예제 #1
0
        public void WordWithStackExistsShouldReturnFalse()
        {
            // arrange
            string[] lines = new string[] { "alphabet: ab",
                                            "states: N0,N1,N2",
                                            "stack: x",
                                            "final: N2",
                                            "transitions:",
                                            "N0,_[_,x] --> N1",
                                            "N1,_[x,_]--> N0",
                                            "N1,a-- > N2",
                                            "end.", };

            List <Transition> transitions = new List <Transition>();
            List <State>      states      = new List <State>();
            List <Letter>     alphabet    = new List <Letter>();
            List <Word>       words       = new List <Word>();
            Stack             stack       = new Stack();

            IParserController parserController = new ParserController(alphabet, states, transitions, stack, words);
            IStackController  stackController  = new StackController(transitions, stack);

            // act
            parserController.Parse(lines);

            // assert
            Assert.IsFalse(stackController.WordWithStackExists("aa", states[0], stack));
        }
예제 #2
0
        public void WordWithStackExistsShouldCheckWithMultipleWords()
        {
            // arrange
            string[] lines = new string[] { "alphabet: abc",
                                            "stack: x",
                                            "states: S,B,C",
                                            "final: C",
                                            "transitions:",
                                            "S,a[_,x]-- > S",
                                            "S,_-- > B",
                                            "B,b[_,x]-- > B",
                                            "B,_-- > C",
                                            "C,c[x,_]-- > C",
                                            "end." };

            List <Transition> transitions = new List <Transition>();
            List <State>      states      = new List <State>();
            List <Letter>     alphabet    = new List <Letter>();
            List <Word>       words       = new List <Word>();
            Stack             stack       = new Stack();

            IParserController parserController = new ParserController(alphabet, states, transitions, stack, words);
            IStackController  stackController  = new StackController(transitions, stack);

            // act
            parserController.Parse(lines);

            // assert
            Assert.IsTrue(stackController.WordWithStackExists("abcc", states[0], new Stack()));
            Assert.IsTrue(stackController.WordWithStackExists("aacc", states[0], new Stack()));
            Assert.IsTrue(stackController.WordWithStackExists("bbbccc", states[0], new Stack()));
            Assert.IsFalse(stackController.WordWithStackExists("aaabbcccc", states[0], new Stack()));
            Assert.IsFalse(stackController.WordWithStackExists("aabbccccc", states[0], new Stack()));
            Assert.IsFalse(stackController.WordWithStackExists("bbaccc", states[0], new Stack()));
        }
예제 #3
0
        public void ParseShouldParseGivenString()
        {
            // arrange
            Mock <Stack>      stackMock        = new Mock <Stack>();
            List <Letter>     alphabet         = new List <Letter>();
            List <State>      states           = new List <State>();
            List <Transition> transitions      = new List <Transition>();
            List <Word>       words            = new List <Word>();
            IParserController parserController = new ParserController(alphabet, states, transitions, stackMock.Object, words);

            string[] lines = new string[] { "alphabet: ab", "states: S0,S1", "final: S1", "transitions:", "S0,a --> S1", "S1,b --> S0", "end.", "words:", "ab, n", "a, y", "end." };

            // act
            parserController.Parse(lines);

            // assert
            Assert.AreEqual(2, states.Count);
            Assert.AreEqual(2, alphabet.Count);
            Assert.AreEqual(2, transitions.Count);
            Assert.IsTrue(states[1].isFinalState);

            Assert.IsFalse(words[0].existsInAutomata);
            Assert.IsFalse(words[0].expectedWordExistance);
            Assert.AreEqual("ab", words[0].word);

            Assert.IsTrue(words[1].expectedWordExistance);
            Assert.IsTrue(words[1].existsInAutomata);
            Assert.AreEqual("a", words[1].word);
        }