Esempio n. 1
0
        private static void TestNdfaToDfa()
        {
            Automata <string> testNdfa = TestAutomata.ndfaToDfaTest();

            Console.WriteLine("testNdfa is dfa? " + testNdfa.IsDfa());
            Console.WriteLine("-----------------------------------------");

            testNdfa.PrintTransitions();
            Console.WriteLine("-----------------------------------------");

            Console.WriteLine("StartStatesIn NDFA: ");
            foreach (string startState in testNdfa.StartStates)
            {
                Console.WriteLine(startState);
            }
            Console.WriteLine("-----------------------------------------");

            Console.WriteLine("EndStates NDFA: ");
            foreach (string endState in testNdfa.FinalStates)
            {
                Console.WriteLine(endState);
            }
            Console.WriteLine("-----------------------------------------");

            Console.WriteLine("String {0} is a {1} string for testNdfa.", NDFA_TO_DFA_VALID_1, testNdfa.IsStringAcceptable(NDFA_TO_DFA_VALID_1) ? "valid" : "invalid");
            Console.WriteLine("String {0} is a {1} string for testNdfa.", NDFA_TO_DFA_VALID_2, testNdfa.IsStringAcceptable(NDFA_TO_DFA_VALID_2) ? "valid" : "invalid");
            Console.WriteLine("String {0} is a {1} string for testNdfa.", NDFA_TO_DFA_VALID_3, testNdfa.IsStringAcceptable(NDFA_TO_DFA_VALID_3) ? "valid" : "invalid");
            Console.WriteLine("String {0} is a {1} string for testNdfa.", NDFA_TO_DFA_VALID_4, testNdfa.IsStringAcceptable(NDFA_TO_DFA_VALID_4) ? "valid" : "invalid");
            Console.WriteLine("String {0} is a {1} string for testNdfa.", NDFA_TO_DFA_INVALID_1, testNdfa.IsStringAcceptable(NDFA_TO_DFA_INVALID_1) ? "valid" : "invalid");
            Console.WriteLine("String {0} is a {1} string for testNdfa.", NDFA_TO_DFA_INVALID_2, testNdfa.IsStringAcceptable(NDFA_TO_DFA_INVALID_2) ? "valid" : "invalid");
            Console.WriteLine("String {0} is a {1} string for testNdfa.", NDFA_TO_DFA_INVALID_3, testNdfa.IsStringAcceptable(NDFA_TO_DFA_INVALID_3) ? "valid" : "invalid");
            Console.WriteLine("-----------------------------------------");

            NdfaToDfa <string> converter   = new NdfaToDfa <string>();
            Automata <string>  testNdfaDFA = converter.TransformNdfaIntoDfa(testNdfa);

            Console.WriteLine("testNdfaDFA is dfa? " + testNdfaDFA.IsDfa());
            Console.WriteLine("-----------------------------------------");

            testNdfaDFA.PrintTransitions();
            Console.WriteLine("-----------------------------------------");

            foreach (string state in testNdfaDFA.StartStates)
            {
                Console.WriteLine(state);
            }
            Console.WriteLine("-----------------------------------------");

            foreach (string state in testNdfaDFA.FinalStates)
            {
                Console.WriteLine(state);
            }
            Console.WriteLine("-----------------------------------------");

            Console.WriteLine("And the same strings as befor in the DFA:");
            Console.WriteLine();
            Console.WriteLine("String {0} is a {1} string for testNdfaDFA.", NDFA_TO_DFA_VALID_1, testNdfaDFA.IsStringAcceptable(NDFA_TO_DFA_VALID_1) ? "valid" : "invalid");
            Console.WriteLine("String {0} is a {1} string for testNdfaDFA.", NDFA_TO_DFA_VALID_2, testNdfaDFA.IsStringAcceptable(NDFA_TO_DFA_VALID_2) ? "valid" : "invalid");
            Console.WriteLine("String {0} is a {1} string for testNdfaDFA.", NDFA_TO_DFA_VALID_3, testNdfaDFA.IsStringAcceptable(NDFA_TO_DFA_VALID_3) ? "valid" : "invalid");
            Console.WriteLine("String {0} is a {1} string for testNdfaDFA.", NDFA_TO_DFA_VALID_4, testNdfaDFA.IsStringAcceptable(NDFA_TO_DFA_VALID_4) ? "valid" : "invalid");
            Console.WriteLine("String {0} is a {1} string for testNdfaDFA.", NDFA_TO_DFA_INVALID_1, testNdfaDFA.IsStringAcceptable(NDFA_TO_DFA_INVALID_1) ? "valid" : "invalid");
            Console.WriteLine("String {0} is a {1} string for testNdfaDFA.", NDFA_TO_DFA_INVALID_2, testNdfaDFA.IsStringAcceptable(NDFA_TO_DFA_INVALID_2) ? "valid" : "invalid");
            Console.WriteLine("String {0} is a {1} string for testNdfaDFA.", NDFA_TO_DFA_INVALID_3, testNdfaDFA.IsStringAcceptable(NDFA_TO_DFA_INVALID_3) ? "valid" : "invalid");
            Console.WriteLine("-----------------------------------------");
        }