public void AutoTest(string regex, string str, bool shouldReturn, bool displayNFA = false) //Method for doing one auto test { NFA autoTest = NFA.Create(regex); //Create NFA for given regex testCount++; //Increase test count if (autoTest != null) { if (displayNFA || displayNFAOverride) //Show NFA if needed { Console.WriteLine(autoTest.ToString()); } string status = "FAILED"; //Default status bool testStatus = autoTest.CheckString(str); //Check given string if (shouldReturn == testStatus) //Compare responses { status = "OK"; } Console.WriteLine(regex + " : " + str + " : " + testStatus + " : " + status); //Test output StatusFilter(status); //Add to summary } }
static void Main(string[] args) { //Auto testing AutoTester at = new AutoTester(); Console.WriteLine("****** AUTO TEST START ******"); Console.WriteLine("regex : string : match : STATUS"); Console.WriteLine(); at.AutoTest("ab", "a", false); at.AutoTest("ab", "", false); at.AutoTest("ab", "aa", false); at.AutoTest("ab", "aaa", false); at.AutoTest("ab", "ab", true); at.AutoTest("ab", "b", false); at.AutoTest("ab", "bb", false); Console.WriteLine(); at.AutoTest("a", "a", true); at.AutoTest("a", "", false); at.AutoTest("a", "aa", false); at.AutoTest("a", "aaa", false); at.AutoTest("a", "ab", false); at.AutoTest("a", "b", false); at.AutoTest("a", "bb", false); Console.WriteLine(); at.AutoTest("a*", "", true); at.AutoTest("a*", "a", true); at.AutoTest("a*", "aa", true); at.AutoTest("a*", "aaa", true); at.AutoTest("a*", "ab", false); at.AutoTest("a*", "b", false); at.AutoTest("a*", "bb", false); Console.WriteLine(); at.AutoTest("a*b", "", false); at.AutoTest("a*b", "a", false); at.AutoTest("a*b", "aa", false); at.AutoTest("a*b", "aaa", false); at.AutoTest("a*b", "ab", true); at.AutoTest("a*b", "b", true); at.AutoTest("a*b", "bb", false); at.AutoTest("a*b", "aaaaab", true); Console.WriteLine(); at.AutoTest("a|b", "", false); at.AutoTest("a|b", "a", true); at.AutoTest("a|b", "aa", false); at.AutoTest("a|b", "aaa", false); at.AutoTest("a|b", "ab", false); at.AutoTest("a|b", "b", true); Console.WriteLine(); at.AutoTest("a*|b", "", true); at.AutoTest("a*|b", "a", true); at.AutoTest("a*|b", "aaa", true); at.AutoTest("a*|b", "b", true); at.AutoTest("a*|b", "ba", false); at.AutoTest("a*|b", "ab", false); Console.WriteLine(); at.AutoTest("a(ab)*c", "aababababc", true); at.AutoTest("a(ab)*c", "aababababcc", false); at.AutoTest("a(ab)*c", "ac", true); at.AutoTest("a(ab)*c", "", false); at.AutoTest("a(ab)*c", "c", false); Console.WriteLine(); at.AutoTest("(a*)|b", "", true); at.AutoTest("(a*)|b", "a", true); at.AutoTest("(a*)|b", "aa", true); at.AutoTest("(a*)|b", "aaa", true); at.AutoTest("(a*)|b", "ab", false); at.AutoTest("(a*)|b", "b", true); at.AutoTest("(a*)|b", "bb", false); Console.WriteLine(); at.AutoTest("((a*b)*c)|b", "aaaaabaabc", true); at.AutoTest("((a*b)*c)|b", "c", true); at.AutoTest("((a*b)*c)|b", "ca", false); at.AutoTest("((a*b)*c)|b", "cb", false); at.AutoTest("((a*b)*c)|b", "cc", false); at.AutoTest("((a*b)*c)|b", "", false); Console.WriteLine(); at.AutoTest("a*b*c*", "abb", true); at.AutoTest("a*b*c*", "aaaaabb", true); at.AutoTest("a*b*c*", "aaaaac", true); at.AutoTest("a*b*c*", "aaaaabbccccc", true); at.AutoTest("a*b*c*", "ccc", true); Console.WriteLine(); at.AutoTest("(a*)", "a", true); at.AutoTest("(a*)", "aaa", true); at.AutoTest("(a*)b", "aaab", true); at.AutoTest("b(a*)", "b", true); at.AutoTest("b(a*)", "ba", true); Console.WriteLine(); at.AutoTest("()", "", true); at.AutoTest("()", "a", false); Console.WriteLine(); at.AutoTest("(c|b(a*))*", "cccbbaaaaabab", true); at.AutoTest("(c|b(a*))*", "cccbbaaaaababc", true); at.AutoTest("(c|(a))*", "caaaaaccc", true); Console.WriteLine(); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "0", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "00", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "11", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "000", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "011", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "110", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "0000", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "0011", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "0110", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "1001", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "1100", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "1111", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "00000", true); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "00001", false); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "0011101", false); at.AutoTest("(0|(1(01*(00)*0)*1)*)*", "1011100000011100000110111000000111000001", true); Console.WriteLine("Invalid regex tests: "); at.AutoTest("((a*)", "", true); at.AutoTest("(a*))", "", true); at.AutoTest("|a", "", true); at.AutoTest("|(a)", "", true); at.AutoTest("a**", "aaaa", true); at.AutoTest("a**", "", true); at.AutoTest("a**", "b", true); at.AutoTest("a||b", "a", true); at.AutoTest("a||b", "b", true); Console.WriteLine(); at.StatusFilterDisplay(); Console.WriteLine("****** AUTO TEST END ******"); Console.WriteLine(); //Manual testing loop Console.WriteLine("Input regex"); var input = Console.ReadLine(); NFA inputNFA = NFA.Create(input); if (inputNFA != null) { Console.WriteLine(inputNFA.ToString()); while (true) { Console.WriteLine("====================="); Console.WriteLine("Input string to check"); input = Console.ReadLine(); Console.WriteLine(inputNFA.CheckString(input)); } } }