public void GrammarDerivationParseTest() { var der1 = DerivationParser <char> .Parse(f1, "S \n S S S \n S a b S \n x a b S \n x a b S S S \n x a b x S S \n x a b x x S \n x a b x x x"); Assert.IsTrue(der1.Count == 8); var der1L = new int[] { 1, 3, 4, 4, 6, 6, 6, 6 }; for (int i = 0; i < der1L.Length; i++) { Assert.IsTrue(der1[i].Length == der1L[i]); } }
public void GrammarDerivationTest() //tests derivation computation in combination with parsing (grammar and derivation) { String sg = "S->S S S | x | A | ab | A -> A A | S | a | "; ContextFreeGrammar g = GrammarParser <char> .Parse(f1, sg); var der1 = DerivationParser <char> .Parse(f1, "S \n A \n A A \n A \n A A \n A S \n A \n S \n S S S \n S a b S \n x a b S \n x a b S S S \n x a b x S S \n x a b x x S \n x a b x x x"); Assert.IsTrue(Derivation.comparator.Equals(der1[0], new GrammarSymbol[] { g.StartSymbol })); //check start for (int i = 1; i < der1.Count; i++) { Assert.IsTrue(Derivation.isValidDerivationStep(g.GetProductions(), der1[i - 1], der1[i])); //check step } }
public void GrammarFindDerivationTest() //tests problem type "find derivation" { String sg = "S->S S S | x | A | ab | A -> A A | S | a | "; ContextFreeGrammar g = GrammarParser <char> .Parse(f1, sg); var wrong_start = DerivationParser <char> .Parse(f1, "S S S \n S a b S \n x a b S \n x a b S S S \n x a b x S S \n x a b x x S \n x a b x x x"); var wrong_end = DerivationParser <char> .Parse(f1, "S \n S S S \n S a b S \n x a b S"); var wrong_step = DerivationParser <char> .Parse(f1, "S \n S S S \n S a b S \n x a b S \n x a b S S S \n x a b x x x"); var correct = DerivationParser <char> .Parse(f1, "S \n S S S \n S a b S \n x a b S \n x a b S S S \n x a b x S S \n x a b x x S \n x a b x x x"); var correct_long = DerivationParser <char> .Parse(f1, "S \n A \n A A \n A \n A A \n A S \n A \n S \n S S S \n S a b S \n x a b S \n x a b S S S \n x a b x S S \n x a b x x S \n x a b x x x"); Assert.IsFalse(GrammarGrading.gradeFindDerivation(g, "xabxxx", wrong_start, 10).Item1 == 10); Assert.IsFalse(GrammarGrading.gradeFindDerivation(g, "xabxxx", wrong_end, 10).Item1 == 10); Assert.IsFalse(GrammarGrading.gradeFindDerivation(g, "xabxxx", wrong_step, 10).Item1 == 10); Assert.IsTrue(GrammarGrading.gradeFindDerivation(g, "xabxxx", correct, 10).Item1 == 10); Assert.IsTrue(GrammarGrading.gradeFindDerivation(g, "xabxxx", correct_long, 10).Item1 == 10); }