示例#1
0
        public void GrammarGradingTest1() //   balanced parenthesis (wordsInGrammar)        !!!could change if grading scale is changed!!!
        {
            String             sg1 = "S -> S S|(S)|";
            ContextFreeGrammar g   = GrammarParser <char> .Parse(f1, sg1);

            var res = GrammarGrading.gradeWordsInGrammar(g, new[] { "()", "())()()(", "()((" }, new[] { "()(", "())()(", "xyz" }, 10);

            Assert.IsTrue(res.Item1 == 5);
        }
示例#2
0
        public void GrammarGradingTest2() //  a^n b^n (grammar equality)        !!!could change if grading scale is changed!!!
        {
            String             sg1 = "S->absjjfhghs|X X->aXb|";
            String             sg2 = "S->aSb|aaSbb|";
            ContextFreeGrammar g1  = GrammarParser <char> .Parse(f1, sg1);

            ContextFreeGrammar g2 = GrammarParser <char> .Parse(f1, sg2);

            var res  = GrammarGrading.gradeGrammarEquality(g1, g2, 10, 50);
            var res2 = GrammarGrading.gradeGrammarEquality(g2, g1, 10, 50);

            Assert.IsTrue(res.Item1 == 9);
            Assert.IsTrue(res2.Item1 == 9); //mirrored
        }
示例#3
0
        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);
        }