예제 #1
0
 public void CorrectFinalStateCount()
 {
     const string expression = "ab&";
     var parser = new InputManager ();
     var output = parser.ParseExpression (expression);
     var finalStateCount = output.FindFinalStates (output.StartState);
     finalStateCount.Count.Should ().Be (1);
 }
예제 #2
0
                public void CorrectFinalStates()
                {
                    const string expression = "ab&";
                    var parser = new InputManager ();
                    var output = parser.ParseExpression (expression);
                    var start = output.StartState;
                    var a = start.Out [0].End;
                    var b = a.Out [0].End;
                    var final = b.Out [0].End;

                    final.IsFinal.Should ().BeTrue ();
                }
예제 #3
0
        /// <summary>
        /// Processes the input document and outputs all state tables.
        /// </summary>
        /// <param name="args">The command line arguements</param>
        static void ProcessDocument(string[] args)
        {
            var output = new OutputManager (new ConsoleHelper ());
            //get file contents
            var fileContents = File.ReadAllLines (args.Length != 0 ? args[0] : "test_expressions.txt");
            var inputManager = new InputManager ();

            //foreach line in the file, make a graph then print it.
            foreach (var line in fileContents) {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine ("======= BEGIN GRAPH =======");
                Console.WriteLine ("Input Expression: " + line);
                Console.ResetColor ();
                //make the graph
                var outputGraph = inputManager.ParseExpression (line);
                output.Print (outputGraph);

                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine ("======= END GRAPH =======");
                Console.ResetColor ();

            }
        }
예제 #4
0
 public void CorrectStateCount()
 {
     const string expression = "ab&";
     var parser = new InputManager ();
     var output = parser.ParseExpression (expression);
     output.StateCount.Should ().Be (4);
 }
예제 #5
0
 public void BadInputOffBalanceOperation()
 {
     const string input = "ab+ba";
     var inputManager = new InputManager ();
     inputManager.ParseExpression (input);
 }
예제 #6
0
 public void BadInputNotInLanguage()
 {
     const string input = "1";
     var inputManager = new InputManager ();
     inputManager.ParseExpression (input);
 }
예제 #7
0
 public void HasCorrectStateCount_MultipleOp()
 {
     const string expression = "ab+b+";
     var parser = new InputManager ();
     var output = parser.ParseExpression (expression);
     var finals = output.FindFinalStates (output.StartState);
     finals.Count.Should ().Be (1);
 }
예제 #8
0
 public void BadInputNotEnoughArgsForOp()
 {
     const string input = "a+";
     var inputManager = new InputManager ();
     inputManager.ParseExpression (input);
 }
예제 #9
0
                public void HasCorrectGraph_MultipleOp()
                {
                    const string expression = "ab+b+";

                    var parser = new InputManager ();
                    var output = parser.ParseExpression (expression);

                    var firstPartStart = output.StartState.Out [0];
                    var a = firstPartStart.End.Out [0];
                    var oldAFinal = a.End.Out [0];
                    var aFinal = oldAFinal.End.Out [0];

                    var b = firstPartStart.End.Out [0];
                    var oldBFinal = b.End.Out [0];

                    var topFinal = aFinal.End;
                    var topNewEnd = topFinal.Out [0];
                    topNewEnd.ConnectedBy.Should ().Be (Word.Epsilon);
                    topNewEnd.End.IsFinal.Should ().BeTrue ();

                    //lower half of graph, a.k.a  a 'b' by itself connected to a new final state.
                    var secondPartStart = output.StartState.Out [1];
                    secondPartStart.ConnectedBy.Should ().Be (Word.Epsilon);
                    var secondPartOldFinish = secondPartStart.End.Out [0];
                    secondPartOldFinish.ConnectedBy.Should ().Be (new Word ('b', "b"));
                    var finish = secondPartOldFinish.End.Out [0];
                    finish.ConnectedBy.Should ().Be (Word.Epsilon);
                    finish.End.IsFinal.Should ().BeTrue ();
                    finish.End.Should ().Be (topNewEnd.End);
                }
예제 #10
0
 public void HasCorrectEpsilonFromStart_SingleOp()
 {
     const string expression = "ab+";
     var parser = new InputManager ();
     var output = parser.ParseExpression (expression);
     var start = output.StartState;
     start.Out.Count.Should ().Be (2);
     start.Out [0].ConnectedBy.Should ().Be (Word.Epsilon);
     start.Out [1].ConnectedBy.Should ().Be (Word.Epsilon);
 }
예제 #11
0
                public void CorrectFinalState_SingleOp()
                {
                    const string expression = "ab+";
                    var parser = new InputManager ();
                    var output = parser.ParseExpression (expression);
                    var start = output.StartState;
                    var a = start.Out [0].End;
                    var oldAFinal = a.Out [0].End;
                    var aFinal = oldAFinal.Out [0].End;

                    var b = start.Out [0].End;
                    var oldBFinal = b.Out [0].End;
                    var bFinal = oldBFinal.Out [0].End;

                    aFinal.IsFinal.Should ().BeTrue ();
                    bFinal.IsFinal.Should ().BeTrue ();
                    aFinal.Should ().Be (bFinal);
                }
예제 #12
0
 public void BadInputNoOperation()
 {
     const string input = "ab";
     var inputManager = new InputManager ();
     inputManager.ParseExpression (input);
 }