public static void FreezeTests() { Console.WriteLine("BEGIN: FreezeTests"); int[,] transitions = { {} }; bool[] finalStates = { true }; int[] word = {}; var fsmDefinition = new FiniteStateMachineDefinition <int, int>(null, null, 0, transitions, finalStates); Console.WriteLine("1 Does it accept the empty word (it should) ? " + (fsmDefinition.Accepts(word) ? "yes" : "no") + "."); finalStates[0] = false; Console.WriteLine("2 Does it still accept the empty word (it should) ? " + (fsmDefinition.Accepts(word) ? "yes" : "no") + "."); var v = new FrozenVector <bool>(finalStates); var fsmDefinition2 = new FiniteStateMachineDefinition <int, int>(null, null, 0, new FrozenMatrix <int>(transitions), v); Console.WriteLine("3 Does this other one accept the empty word (it should not) ? " + (fsmDefinition2.Accepts(word) ? "yes" : "no") + "."); Console.WriteLine("END: FreezeTests"); }
public static void SimplestFSM() { Console.WriteLine("BEGIN: SimplestFSM"); int[,] transitions = { {} }; bool[] finalStates = { true }; int[] word = {}; var fsmDefinition = new FiniteStateMachineDefinition <int, int>(null, null, 0, transitions, finalStates); Console.WriteLine("Does it accept the empty word? " + (fsmDefinition.Accepts(word) ? "yes" : "no") + "."); Console.WriteLine("END: SimplestFSM"); }
public static void TrivialAcceptAllFSM() { Console.WriteLine("BEGIN: TrivialAcceptAllFSM"); bool[] finalStates = { true }; int[,] transitions = { { 0, 0 } }; var fsmDefinition = new FiniteStateMachineDefinition <char, char>("01".ToCharArray(), "F".ToCharArray(), 0, transitions, finalStates); string word = "0100010001110"; Console.WriteLine("Does it accept " + word + "? " + (fsmDefinition.Accepts(word) ? "yes" : "no") + "."); Console.WriteLine("END: TrivialAcceptAllFSM"); }
public static void CloneTests() { Console.WriteLine("BEGIN: CloneTests"); Console.WriteLine("Let Σ=ab, we consider the machine that accepts a*b*."); char[] alphabet = "ab".ToCharArray(); int[,] transitions = { //a b { 0, 1 }, // class of "", subset of L { 2, 1 }, // class of "b", subset of L { 2, 2 }, // class of "ab" = Σ* - L }; bool[] finalStates = { true, true, false }; var fsmDefinition = new FiniteStateMachineDefinition <char, int>(alphabet, null, 0, transitions, finalStates); Console.WriteLine("Try some words, are they accepted?"); string[] words = { "", "a", "aaaaa", "aaabbbbbb", "abaa", "bbbb", "bbbba", "abababa" }; foreach (string word in words) { Console.WriteLine("\"" + word + "\" -> " + (fsmDefinition.Accepts(word.ToCharArray()) ? "yes" : "no")); } var afterReadingB = fsmDefinition.NewExecution(); afterReadingB.Read("b".ToCharArray()); Console.WriteLine("We now build a machine and we make it read a \"b\"."); var copy1 = afterReadingB.Clone(); copy1.Read("aaaaa".ToCharArray()); Console.WriteLine("We make a first copy of it and make the copy read \"aaaaa\". Is it in final state? " + (copy1.InFinalState ? "yes" : "no") + "."); var copy2 = afterReadingB.Clone(); copy2.Read("bbb".ToCharArray()); Console.WriteLine("We make a second copy and make the copy read \"bbb\". Is it in final state? " + (copy2.InFinalState ? "yes" : "no") + "."); Console.WriteLine("END: CloneTests"); }