public void CreatesCorrectConnection() { var m1Start = new GraphState () { StateNumber = 0, IsFinal = true }; var m2Start = new GraphState () { StateNumber = 1, IsFinal = true }; var m1 = new Graph () { StartState = m1Start }; var m2 = new Graph () { StartState = m2Start }; var ndfa = m1.Concat (m2); ndfa.StartState.Out[0].Start.Should ().Be (m2Start); ndfa.StartState.Out[0].End.Should ().Be (m1Start); ndfa.StartState.Out[0].ConnectedBy.Letter.Should ().Be (Word.Epsilon.Letter); ndfa.StartState.Out[0].ConnectedBy.Mapping.Should ().Be (Word.Epsilon.Mapping); }
public void CreatesOneConnection() { var m1Start = new GraphState () { StateNumber = 0, IsFinal = true }; var m2Start = new GraphState () { StateNumber = 1, IsFinal = true }; var m1 = new Graph () { StartState = m1Start }; var m2 = new Graph () { StartState = m2Start }; var ndfa = m1.Concat (m2); ndfa.StartState.Out.Count.Should ().Be (1); }
Graph ProcessOperation(Graph initGraph, Operation op, Stack<Word> opStack) { // create base graph if not done already. if(initGraph == null){ //start of our graph initGraph = Graph.CreateNewGraph(opStack.Pop()); } //if kleene operation, do it here. if (op.Mapping == OperationType.Kleene) { initGraph = initGraph.Kleene (); } //now process each operation while(opStack.Count != 0){ //get next letter to work with. var wordToAdd = opStack.Pop(); //depending on the mapped type, do operation on graph //with the new letter. if(op.Mapping == OperationType.Concat) initGraph = initGraph.Concat(wordToAdd); else if(op.Mapping == OperationType.Union) initGraph = initGraph.Union(wordToAdd); } //return the created graph. return initGraph; }
public void HasCorrectFinalStates() { var m1Start = new GraphState () { StateNumber = 0, IsFinal = true }; var m2Start = new GraphState () { StateNumber = 1, IsFinal = true }; var m1 = new Graph () { StartState = m1Start }; var m2 = new Graph () { StartState = m2Start }; var ndfa = m1.Concat (m2); var finals = ndfa.FindFinalStates (ndfa.StartState); finals.Count.Should ().Be (1); finals [0].Should ().Be (m1Start); }
public void StateNumbersCorrect() { var m1Start = new GraphState () { StateNumber = 0, IsFinal = true }; var m2Start = new GraphState () { StateNumber = 0, IsFinal = true }; var m1 = new Graph () { StartState = m1Start }; var m2 = new Graph () { StartState = m2Start }; var ndfa = m1.Concat (m2); ndfa.StartState.StateNumber.Should ().Be (0); ndfa.StartState.Out [0].End.StateNumber.Should ().Be (1); }
public void HasCorrectTwoStateCount() { var m1Start = new GraphState () { StateNumber = 0, IsFinal = true }; var m2Start = new GraphState () { StateNumber = 1, IsFinal = true }; var m1 = new Graph () { StartState = m1Start }; var m2 = new Graph () { StartState = m2Start }; var ndfa = m1.Concat (m2); ndfa.StateCount.Should ().Be (2); }