示例#1
0
        public void AcceptTestInCorrectFinalState()
        {
            char[]            alphabet = { 'a', 'b' };
            Automaat <string> dfa      = new Automaat <string>(alphabet);

            dfa.AddTransition(new Transition <string>("0", 'a', "1"));
            dfa.AddTransition(new Transition <string>("0", 'b', "4"));

            dfa.AddTransition(new Transition <string>("1", 'b', "2"));
            dfa.AddTransition(new Transition <string>("1", 'a', "4"));

            dfa.AddTransition(new Transition <string>("2", 'a', "3"));
            dfa.AddTransition(new Transition <string>("2", 'b', "4"));

            dfa.AddTransition(new Transition <string>("3", 'a', "1"));
            dfa.AddTransition(new Transition <string>("3", 'b', "2"));

            dfa.AddTransition(new Transition <string>("4", 'a', "4"));
            dfa.AddTransition(new Transition <string>("4", 'b', "4"));

            dfa.DefineAsStartState("0");
            dfa.DefineAsFinalState("0");
            dfa.DefineAsFinalState("2");

            Assert.IsFalse(dfa.Accept("aba"));
        }
示例#2
0
        public void AcceptEpsilonTest()
        {
            char[]            alphabet    = { 'a', 'b' };
            Automaat <string> epsilonNdfa = new Automaat <string>(alphabet);

            epsilonNdfa.AddTransition(new Transition <string>("0", 'a', "1"));
            epsilonNdfa.AddTransition(new Transition <string>("1", '$', "2"));
            epsilonNdfa.AddTransition(new Transition <string>("2", 'b', "3"));
            epsilonNdfa.AddTransition(new Transition <string>("3", '$', "4"));
            epsilonNdfa.AddTransition(new Transition <string>("4", '$', "5"));
            epsilonNdfa.AddTransition(new Transition <string>("5", 'c', "6"));

            epsilonNdfa.DefineAsStartState("0");
            epsilonNdfa.DefineAsFinalState("6");

            Assert.IsTrue(epsilonNdfa.Accept("abc"));
        }