public void HasCorrectSingleFinalState() { var m1Start = new GraphState () { IsFinal = true }; var m1 = new Graph () { StartState = m1Start }; var finals = m1.FindFinalStates (m1.StartState); finals [0].Should ().Be (m1Start); }
public void CountsOnlyOneFinal() { var m1Start = new GraphState () { IsFinal = true }; var secondFinal = new GraphState () { IsFinal = true }; var thirdFinal = new GraphState () { IsFinal = true }; var m1 = new Graph () { StartState = m1Start }; var epsilonConnection1 = new GraphStateConnection { Start = m1Start, End = secondFinal, ConnectedBy = Word.Epsilon }; var epsilonConnection2 = new GraphStateConnection { Start = secondFinal, End = thirdFinal, ConnectedBy = Word.Epsilon }; m1.StartState.Out.Add (epsilonConnection1); secondFinal.Out.Add (epsilonConnection2); var finals = m1.FindFinalStates (m1.StartState); finals.Count.Should ().Be (3); }
public void HasCorrectCount() { var m1Start = new GraphState () { IsFinal = true }; var m1 = new Graph () { StartState = m1Start }; var finals = m1.FindFinalStates (m1.StartState); finals.Count.Should ().Be (1); }
/// <summary> /// Concatinates two NDFA's. /// </summary> /// <param name="m1">The second NDFA to concatinate with.</param> /// <returns>The new graph that is this and m1 concatinated.</returns> public Graph Concat(Graph m1) { var m = new Graph (); var m2 = this; var m1FinalStates = m1.FindFinalStates (m1.StartState); foreach (var finalState in m1FinalStates) { //create a new connection to m2 initial state var m1FinalTom2Initial = new GraphStateConnection () { Start = finalState, End = m2.StartState, ConnectedBy = Word.Epsilon }; //make the connection finalState.Out.Add (m1FinalTom2Initial); //kill m1 final states and leave m2 as finals for m finalState.IsFinal = false; } //update state count for new graph m.StartState = m1.StartState; m.StateCount = m1.StateCount + m2.StateCount; if (updateStateNumber) { RenumberStates (m.StartState); } return m; }