private static void AssertAutomaton(Automaton automaton)
{
var cra = new CharacterRunAutomaton(automaton);
var bra = new ByteRunAutomaton(automaton);
var ras = new AutomatonTestUtil.RandomAcceptedStrings(automaton);
int num = AtLeast(1000);
for (int i = 0; i < num; i++)
{
string s;
if (Random().NextBoolean())
{
// likely not accepted
s = TestUtil.RandomUnicodeString(Random());
}
else
{
// will be accepted
int[] codepoints = ras.GetRandomAcceptedString(Random());
try
{
s = UnicodeUtil.NewString(codepoints, 0, codepoints.Length);
}
catch (Exception e)
{
Console.WriteLine(codepoints.Length + " codepoints:");
for (int j = 0; j < codepoints.Length; j++)
{
Console.WriteLine(" " + codepoints[j].ToString("x"));
}
throw e;
}
}
var bytes = s.GetBytes(Encoding.UTF8);
Assert.AreEqual(cra.Run(s), bra.Run(bytes, 0, bytes.Length));
}
}