public void Check10Returns2() { var finalStates = new List <State> { State.S0, State.S1, State.S2 }; var finiteAutomaton = new FiniteAutomaton(State.S0, finalStates); finiteAutomaton.CreateTransition(State.S0, 0, State.S0); finiteAutomaton.CreateTransition(State.S0, 1, State.S1); finiteAutomaton.CreateTransition(State.S1, 0, State.S2); finiteAutomaton.CreateTransition(State.S1, 1, State.S0); finiteAutomaton.CreateTransition(State.S2, 0, State.S1); finiteAutomaton.CreateTransition(State.S2, 1, State.S2); var input = "10"; bool result = finiteAutomaton.ProcessInput(input); Assert.IsTrue(result, "Resulting state of input " + input + "should be part of the set of final states"); Assert.AreEqual(finiteAutomaton.GetCurrentState(), State.S2, "Remainder of " + input + " should be 2"); finiteAutomaton.ResetState(); Assert.AreEqual(finiteAutomaton.GetCurrentState(), State.S0, "FSA should be reset back to state 0"); }
public void CheckResultStateNotFinal() { var finalStates = new List <State> { State.S0, }; var finiteAutomaton = new FiniteAutomaton(State.S0, finalStates); finiteAutomaton.CreateTransition(State.S0, 1, State.S1); var input = "1"; bool result = finiteAutomaton.ProcessInput(input); Assert.IsFalse(result, "1 is not in the set of final states, therefore result should be false"); finiteAutomaton.ResetState(); Assert.AreEqual(finiteAutomaton.GetCurrentState(), State.S0, "FSA should be reset back to state 0"); }