public void GetNdfaFromRegularExpressionShouldReturnListOfTransitions()
        {
            // arrange
            string formula = "*(|(.(a,b),a))";
            IRegularExpressionController regularExpressionController = new RegularExpressionController();

            // act
            RegularExpression regularExpression = regularExpressionController.GetNdfaFromRegularExpression(ref formula);

            // assert
            Assert.AreEqual(11, regularExpression.transitions.Count);
            Assert.IsTrue(regularExpression.final.isFinalState);
        }
        public void GetNdfaFromRegularExpressionShouldUseStarRule()
        {
            // arrange
            string formula = "*(a)";
            IRegularExpressionController regularExpressionController = new RegularExpressionController();

            // act
            RegularExpression regularExpression = regularExpressionController.GetNdfaFromRegularExpression(ref formula);

            // assert
            Assert.IsTrue(regularExpression.transitions.Count == 5);
            Assert.IsTrue(regularExpression.transitions.Exists(_ => _.connectingLetter.data == 'a'));
            Assert.IsTrue(regularExpression.final.isFinalState);
            Assert.AreEqual(4, regularExpression.transitions.FindAll(_ => _.connectingLetter.data == '_').Count);
        }
        public void GetNdfaFromRegularExpressionShouldUseOrRule()
        {
            // arrange
            string formula = "|(a,b)";
            IRegularExpressionController regularExpressionController = new RegularExpressionController();

            // act
            RegularExpression regularExpression = regularExpressionController.GetNdfaFromRegularExpression(ref formula);

            // assert
            Assert.IsTrue(regularExpression.transitions.Count == 6);
            Assert.IsTrue(regularExpression.transitions.Exists(_ => _.connectingLetter.data == 'a'));
            Assert.IsTrue(regularExpression.transitions.Exists(_ => _.connectingLetter.data == 'b'));
            Assert.IsTrue(regularExpression.final.isFinalState);
        }
        public void GetNdfaFromRegularExpressionShouldUseLetterRule()
        {
            // arrange
            string formula = "a";
            IRegularExpressionController regularExpressionController = new RegularExpressionController();

            // act
            RegularExpression regularExpression = regularExpressionController.GetNdfaFromRegularExpression(ref formula);

            // assert
            Assert.AreEqual(1, regularExpression.transitions.Count);
            Assert.IsTrue(regularExpression.initial.data == "S0");
            Assert.IsTrue(regularExpression.final.data == "S1");
            Assert.IsTrue(regularExpression.final.isFinalState);
        }
        public void ExtractAlphabetFromTransitionsShouldReturnAlphabetFromTransitions()
        {
            // arrange
            State             stateOneMock    = new State("S0");
            State             stateTwoMock    = new State("S1");
            Letter            letterOneMock   = new Letter('a');
            Letter            letterTwoMock   = new Letter('b');
            List <Transition> transitionsMock = new List <Transition>()
            {
                new Transition(stateOneMock, stateTwoMock, letterOneMock),
                new Transition(stateTwoMock, stateOneMock, letterTwoMock)
            };
            IRegularExpressionController regularExpressionController = new RegularExpressionController();

            // act
            List <Letter> statesResult = regularExpressionController.ExtractAlphabetFromTransitions(transitionsMock);

            // assert
            Assert.AreEqual(2, statesResult.Count);
            Assert.IsTrue(statesResult[0].data == 'a');
            Assert.IsTrue(statesResult[1].data == 'b');
        }