/// <summary> /// Converte um afnde para uma imagem representando o gráfico /// </summary> public static bool AFNDEtoPNG(string path) { GrammarNonDeterministicAutomata afnde = new GrammarNonDeterministicAutomata(); Graph graph = new Graph(""); for (int i = 0; i < afnde.StateList.Count; i++) { GrammarState state = GrammarState.ConvertFrom(afnde.StateList[i]); graph.AddNode(state.StateValue); for (int j = 0; j < state.Transictions.Count; j++) { graph.AddEdge(state.StateValue, state.Transictions[j].Transiction.Value, state.Transictions[j].NextState.StateValue); } } return(GenerateGraphImage(graph, path)); }
public void TestAutomataAFND() { Automata <int, char> testAutomata = GenerateTestAutomataAFN(); #region Trivial Tests State <int, char> state0 = testAutomata.InitialState; Assert.AreEqual(0, state0.StateValue, "Valor do estado 0 diferente de 0, valor = " + state0.StateValue); List <State <int, char> > list = state0.ReachableStatesBy('e'); Assert.AreEqual(list.Count, 1, "Estados alcançáveis pelo inicial diferente de 1, valor = " + list.Count); //State 1 State <int, char> stateAux = list[0]; Assert.AreEqual(1, stateAux.StateValue, "Valor do estado 1 diferente de 1, valor = " + stateAux.StateValue); list = stateAux.ReachableStatesBy('e'); Assert.IsNull(list, "Lista não nula para os estados alcançáveis a partir do vazio do estado 1"); //State 2 stateAux = stateAux.TransictionIn('a'); Assert.AreEqual(2, stateAux.StateValue, "Valor do estado 2 diferente de 2, valor = " + stateAux.StateValue); list = stateAux.ReachableStatesBy('e'); Assert.AreEqual(list.Count, 1, "Estados alcançáveis pelo estado 2 diferente de 1, valor = " + list.Count); //State 3 stateAux = list[0]; Assert.AreEqual(3, stateAux.StateValue, "Valor do estado 3 diferente de 3, valor = " + stateAux.StateValue); //State 4 stateAux = stateAux.TransictionIn('b'); Assert.AreEqual(4, stateAux.StateValue, "Valor do estado 4 diferente de 4, valor = " + stateAux.StateValue); Assert.IsTrue(stateAux.IsFinal, "Estado 4 não final!"); #endregion GrammarNonDeterministicAutomata automata = new GrammarNonDeterministicAutomata(); Assert.IsNotNull(automata, "Automato não determinístico com transição em vazio retornou nulo"); //TODO mais testes }