private static void TWDFAFunction(string inputString) { Timer.Start(); FiniteAutomata automata1 = TWDFABuilder3(); ConsoleOperations.WriteBMarkReset("2DFA Creation"); ConsoleOperations.WriteTitle("2DFA Info"); ConsoleOperations.WriteAutomataInfo(automata1); Timer.Restart(); FiniteAutomataConverter dfaConverter1 = new FiniteAutomataConverter(); FiniteAutomata resultX = dfaConverter1.Convert2DFAToDFA(automata1); ConsoleOperations.WriteBMarkReset("Automata Conversion"); Console.WriteLine("\n>>>2DFA is converted to DFA<<<\n"); ConsoleOperations.WriteTitle("DFA Info"); ConsoleOperations.WriteAutomataInfo(resultX); ConsoleOperations.WriteTitle("DFA Trace"); Timer.Restart(); bool result = resultX.Run(inputString); ConsoleOperations.WriteBMarkReset("DFA Run"); Timer.Stop(); ConsoleOperations.WriteTitle("Automata Results"); Console.WriteLine("DFA Response: Input is " + (result ? "Accepted" : "Rejected")); ConsoleOperations.WriteTitle("Benchmark Results"); BenchmarkResults.ForEach(x => Console.WriteLine(x)); }
private void runDFAButton_Click(object sender, EventArgs e) { if (DFA is null) { Convertor automataConverter = new Convertor(); FiniteAutomata dfa = automataConverter.NFAToDFA(NFA); var(result, text) = dfa.Run(inputString); dfaResult = result; if (result == false) { Console.WriteLine("Not Valid"); } automataOutputRichTextBox.Text = text; } else { var(result, text) = DFA.Run(inputString); dfaResult = result; if (result == false) { Console.WriteLine("Not Valid"); } automataOutputRichTextBox.Text = text; } }
public void Should_ReturnFalse_When_Run_DFAWithABCABCABC() { List <char> alphabet = new List <char>() { 'a', 'b', 'c' }; FiniteAutomata automata = new FiniteAutomata(FiniteAutomataType.DFA, alphabet); _ = automata.AddState("q0", isInitialState: true, isFinalState: true); _ = automata.AddState("q1"); _ = automata.AddState("q2"); _ = automata.AddState("q3"); _ = automata.AddTransition('a', "q0", "q1"); _ = automata.AddTransition('b', "q0", "q1"); _ = automata.AddTransition('c', "q0", "q1"); _ = automata.AddTransition('a', "q1", "q2"); _ = automata.AddTransition('b', "q1", "q2"); _ = automata.AddTransition('c', "q1", "q2"); _ = automata.AddTransition('a', "q2", "q3"); _ = automata.AddTransition('b', "q2", "q3"); _ = automata.AddTransition('c', "q2", "q3"); _ = automata.AddTransition('a', "q3", "q0"); _ = automata.AddTransition('b', "q3", "q0"); _ = automata.AddTransition('c', "q3", "q0"); Assert.False(automata.Run("abcabcabc")); }
public void Test_NFA_RUN_Should_Return_False_Invalid_Input() { var inputString = "10001"; List <char> alphabet = new List <char> { '0', '1' }; FiniteAutomata nfaTest = new FiniteAutomata(AutomataType.NFA, alphabet); _ = nfaTest.AddState("A", isInitialState: true, false); //A _ = nfaTest.AddState("B", false, false); //B _ = nfaTest.AddState("C", false, isFinalState: true); //C _ = nfaTest.AddTransition('0', "A", "A"); // TR: A '0' _ = nfaTest.AddTransition('1', "A", "B,C"); // TR: A '1' _ = nfaTest.AddTransition('0', "B", "A"); // TR: B '0' _ = nfaTest.AddTransition('1', "B", "A,C"); // TR: B '1' _ = nfaTest.AddTransition('0', "C", "A,B"); // TR: C '0' _ = nfaTest.AddTransition('1', "C", "C"); // TR: C '1' var result = nfaTest.Run(inputString); Assert.AreEqual(false, result); }
private static void NFAFunction(string inputString) { Timer.Start(); FiniteAutomata automata = NFABuilder(); ConsoleOperations.WriteBMarkReset("NFA Creation"); ConsoleOperations.WriteTitle("NFA Info"); ConsoleOperations.WriteAutomataInfo(automata); ConsoleOperations.WriteTitle("NFA Trace"); Timer.Restart(); bool result = automata.Run(inputString); ConsoleOperations.WriteBMarkReset("NFA Run"); Timer.Restart(); FiniteAutomataConverter dfaConverter = new FiniteAutomataConverter(); FiniteAutomata DFAVersion = dfaConverter.ConvertNFAToDFA(automata); ConsoleOperations.WriteBMarkReset("Automata Conversion"); Console.WriteLine("\n>>>NFA is converted to DFA<<<\n"); ConsoleOperations.WriteTitle("DFA Info"); ConsoleOperations.WriteAutomataInfo(DFAVersion); ConsoleOperations.WriteTitle("DFA Trace"); Timer.Restart(); bool resultDFA = DFAVersion.Run(inputString); ConsoleOperations.WriteBMarkReset("DFA Run"); Timer.Stop(); ConsoleOperations.WriteTitle("Automata Results"); Console.WriteLine("NFA Response: Input is " + (result ? "Accepted" : "Rejected")); Console.WriteLine("DFA Response: Input is " + (resultDFA ? "Accepted" : "Rejected")); ConsoleOperations.WriteTitle("Benchmark Results"); BenchmarkResults.ForEach(x => Console.WriteLine(x)); }