public void Should_Generate_Instructions_Successfully() { IFiniteAutomataStructure str = new FiniteAutomataStructure(); ILetter letter = new Letter('s'); str.StructureAlphabet.Letters.Add(letter); IState initial = new State(1, "1", true); IState final = new State(2, "2", false, true); initial.Directions.Add(final, new HashSet <DirectionValue>() { new DirectionValue { Letter = letter } }); str.States.Add(initial); str.States.Add(final); str.GenerateOriginalInstructions(new Mock <IConfiguration>().Object); IFiniteAutomataStructure newStr = new FiniteAutomataStructure( new InstructionsInput { instructions = str.OriginalInstructions }); Assert.AreEqual(newStr.States, str.States); }
public void Should_Return_That_Structure_Is_DFA_If_There_Are_Directions_That_Include_All_Letters() { IFiniteAutomataStructure str = new FiniteAutomataStructure(); ILetter letter = new Letter('s'); IState state1 = new State(1, "1", true, true); IState state2 = new State(2, "2", false, true); state1.Directions.Add(state2, new HashSet <DirectionValue>() { new DirectionValue { Letter = letter } }); state2.Directions.Add(state1, new HashSet <DirectionValue>() { new DirectionValue { Letter = letter } }); str.States.Add(state1); str.States.Add(state2); str.StructureAlphabet.Letters.Add(letter); Assert.IsTrue(str.IsDFA); }
public void Should_Process_Repetition_Rule_Successfully() { IFiniteAutomataStructure str = new FiniteAutomataStructure(); int statesId = 1; IState initial = new State(statesId++, "1", true); IState state2 = new State(statesId, "2"); Stack <TompsonInitialFinalStatesHelperPair> stack = new Stack <TompsonInitialFinalStatesHelperPair>(); str.States.Add(initial); str.States.Add(state2); initial.Directions.Add(state2, new HashSet <DirectionValue>() { new DirectionValue { Letter = new Letter('a') } }); stack.Push(new TompsonInitialFinalStatesHelperPair() { CurrentFinal = state2, CurrentInitial = initial }); var result = TompsonProcessor.ProcessRule(TompsonRules.REPETITION, stack, str, ref statesId); Assert.IsTrue(initial.Directions.ContainsKey(result.CurrentFinal)); Assert.IsTrue(result.CurrentFinal.Directions.ContainsKey(initial)); Assert.IsTrue(state2.Directions.ContainsKey(result.CurrentFinal)); }
public void Should_Return_That_Structure_Is_Not_DFA_If_Contains_Epsilon() { IFiniteAutomataStructure str = new FiniteAutomataStructure(); str.StructureAlphabet.Letters.Add(Alphabet.EPSILON_LETTER); Assert.IsFalse(str.IsDFA); }
public void Should_Return_The_First_Initial_State_Successfully() { IFiniteAutomataStructure str = new FiniteAutomataStructure(); IState initial = new State(1, "1", true); str.States.Add(initial); str.States.Add(new State(2, "2", true)); Assert.AreEqual(str.GetInitialState(), initial); }
public void Should_Build_Structure_From_Regex_And_Build_DFA(string regex) { IFiniteAutomataStructure str = new FiniteAutomataStructure( new InstructionsInput { instructions = "regex: " + regex + "\n" }); str.BuildDFA(); Assert.IsTrue(str.CheckDFA(str.DFA)); }
public void Should_Build_Structure_From_Regex_AnD_Verify_Alphabet_DFA_And_Finite(string regex, int letters, bool dfa, bool finite) { IFiniteAutomataStructure str = new FiniteAutomataStructure( new InstructionsInput { instructions = "regex: " + regex + "\n" }); Assert.AreEqual(str.StructureAlphabet.Letters.Count, letters); Assert.AreEqual(str.IsDFA, dfa); Assert.AreEqual(str.IsFinite, finite); }
public void WordExists_Should_Call_Initial_State_Method_For_Checking_Word_Successfully() { string wordToCheck = "s"; IFiniteAutomataStructure str = new FiniteAutomataStructure(); Mock <IState> initial = new Mock <IState>(); initial.Setup(s => s.Initial).Returns(true); str.States.Add(initial.Object); str.WordExists(wordToCheck); initial.Verify(s => s.CheckWord(wordToCheck)); }
public void Should_Return_All_Final_States_Successfully() { IFiniteAutomataStructure str = new FiniteAutomataStructure(); IState final1 = new State(1, "1", true, true); IState final2 = new State(2, "2", false, true); str.States.Add(final1); str.States.Add(final2); Assert.AreEqual(str.GetFinalStates(), new HashSet <IState>() { final1, final2 }); }
public void Should_Return_That_Structure_Is_Not_Finite_If_There_Are_Self_Referenced_States_That_Reach_Final_State() { IFiniteAutomataStructure str = new FiniteAutomataStructure(); IState state1 = new State(1, "1", true, true); state1.Directions.Add(state1, new HashSet <DirectionValue>() { new DirectionValue { Letter = new Letter('s') } }); str.States.Add(state1); Assert.IsFalse(str.IsFinite); }
public void Should_Generate_DFA_Instructions_For_Non_DFA_Structure_And_Verfiy_That_It_Is_DFA_After_Evaluation() { IFiniteAutomataStructure str = new FiniteAutomataStructure(); ILetter letter = new Letter('s'); str.StructureAlphabet.Letters.Add(letter); IState initial = new State(1, "1", true); IState state2 = new State(2, "2", true); IState state3 = new State(3, "3", true); IState final = new State(4, "4", true, true); initial.Directions.Add(state2, new HashSet <DirectionValue>() { new DirectionValue { Letter = letter } }); state2.Directions.Add(state3, new HashSet <DirectionValue>() { new DirectionValue { Letter = Alphabet.EPSILON_LETTER } }); state3.Directions.Add(initial, new HashSet <DirectionValue>() { new DirectionValue { Letter = Alphabet.EPSILON_LETTER } }); state3.Directions.Add(final, new HashSet <DirectionValue>() { new DirectionValue { Letter = Alphabet.EPSILON_LETTER } }); str.States.Add(initial); str.States.Add(final); str.GenerateDFAInstructions(new Mock <IConfiguration>().Object); IFiniteAutomataStructure DFA = new FiniteAutomataStructure( new InstructionsInput { instructions = str.DFAInstructions }); Assert.IsTrue(DFA.IsDFA); }
public void Should_Return_That_Structure_Is_Finite_If_There_Are_States_In_A_Loop_With_Epsilon_Letters() { IFiniteAutomataStructure str = new FiniteAutomataStructure(); IState initial = new State(1, "1", true); IState state2 = new State(2, "2", true); IState state3 = new State(3, "3", true); IState final = new State(4, "4", true, true); initial.Directions.Add(state2, new HashSet <DirectionValue>() { new DirectionValue { Letter = Alphabet.EPSILON_LETTER } }); state2.Directions.Add(state3, new HashSet <DirectionValue>() { new DirectionValue { Letter = Alphabet.EPSILON_LETTER } }); state3.Directions.Add(initial, new HashSet <DirectionValue>() { new DirectionValue { Letter = Alphabet.EPSILON_LETTER } }); state3.Directions.Add(final, new HashSet <DirectionValue>() { new DirectionValue { Letter = Alphabet.EPSILON_LETTER } }); str.States.Add(initial); str.States.Add(final); Assert.IsTrue(str.IsFinite); }