Пример #1
0
        public void CopyConstructor()
        {
            var morphemeRule = new MorphemeRule(GrammarCharacter.I, RuleMaker.Anything <string>(), MaskRule.Is(EnglishAttributes.I.Lexeme.Interjection));

            morphemeRule.SetSubstitution(SubstitutionRules.Epsilon_U_E);

            var copy = new MorphemeRule(morphemeRule);

            Assert.AreEqual(morphemeRule.GrammarCharacter, copy.GrammarCharacter);
            Assert.IsTrue(morphemeRule.MorphRule.Equals(copy.MorphRule));
            Assert.IsTrue(morphemeRule.AttributesRule.Equals(copy.AttributesRule));
            Assert.IsTrue(morphemeRule.SubstitutionRule.Equals(copy.SubstitutionRule));

            Assert.IsTrue(morphemeRule.Equals(copy));
        }
Пример #2
0
        public void Equals()
        {
            IRule <int> rule1 = RuleMaker.Is(10).Or(20).Or(30);
            IRule <int> rule2 = RuleMaker.Is(10).Or(20).Or(30);

            Assert.IsTrue(rule1.Equals(rule2));
            Assert.IsTrue(rule2.Equals(rule1));

            // Different order means a different rule because the evaluation may stop in different point.
            // E.g. if the second OR is true then it does not continue. So both rules although giving the same result will
            //      be evaluated differently.
            rule2 = RuleMaker.Is(10).Or(30).Or(20);
            Assert.IsFalse(rule1.Equals(rule2));


            rule1 = RuleMaker.Is(10).And(20).And(30);
            rule2 = RuleMaker.Is(10).And(20).And(30);
            Assert.IsTrue(rule1.Equals(rule2));
            Assert.IsTrue(rule2.Equals(rule1));

            rule2 = RuleMaker.Is(10).And(30).And(20);
            Assert.IsFalse(rule1.Equals(rule2));


            rule1 = RuleMaker.Is(10).Not();
            rule2 = RuleMaker.Is(10).Not();
            Assert.IsTrue(rule1.Equals(rule2));

            rule1 = RuleMaker.Is(10).Not();
            rule2 = RuleMaker.Is(20).Not();
            Assert.IsFalse(rule1.Equals(rule2));



            rule1 = RuleMaker.Anything <int>();
            rule2 = RuleMaker.Anything <int>();
            Assert.IsTrue(rule1.Equals(rule2));


            rule1 = RuleMaker.Nothing <int>();
            rule2 = RuleMaker.Nothing <int>();
            Assert.IsTrue(rule1.Equals(rule2));
        }
Пример #3
0
        public void IsMatch()
        {
            IAttributesModel attributesModel = new EnglishAttributesModel();

            // Or
            MorphemeRule morphemeRule = new MorphemeRule(GrammarCharacter.I, RuleMaker.Anything <string>(), MaskRule.Is(EnglishAttributes.I.Lexeme.Interjection).Or(MaskRule.Is(EnglishAttributes.I.Lexeme.Verb)));

            Assert.IsTrue(morphemeRule.Evaluate(new Morpheme(attributesModel, "", EnglishAttributes.I.Lexeme.Verb)));
            Assert.IsTrue(morphemeRule.Evaluate(new Morpheme(attributesModel, "", EnglishAttributes.I.Lexeme.Interjection)));
            Assert.IsTrue(morphemeRule.Evaluate(new Morpheme(attributesModel, "", EnglishAttributes.I.Lexeme.Verb | EnglishAttributes.I.Lexeme.Interjection)));
            Assert.IsFalse(morphemeRule.Evaluate(new Morpheme(attributesModel, "", EnglishAttributes.O)));

            // And
            morphemeRule = new MorphemeRule(GrammarCharacter.I, RuleMaker.Anything <string>(), MaskRule.Is(EnglishAttributes.I.Lexeme.Interjection).And(MaskRule.Is(EnglishAttributes.I.Lexeme.Verb)));
            Assert.IsFalse(morphemeRule.Evaluate(new Morpheme(attributesModel, "", EnglishAttributes.I.Lexeme.Verb)));
            Assert.IsFalse(morphemeRule.Evaluate(new Morpheme(attributesModel, "", EnglishAttributes.I.Lexeme.Interjection)));
            Assert.IsTrue(morphemeRule.Evaluate(new Morpheme(attributesModel, "", EnglishAttributes.I.Lexeme.Verb | EnglishAttributes.I.Lexeme.Interjection)));
            Assert.IsFalse(morphemeRule.Evaluate(new Morpheme(attributesModel, "", EnglishAttributes.O)));
        }
Пример #4
0
        public void IsSubruleOf()
        {
            IRule <int> rule1 = RuleMaker.Is(1) | RuleMaker.Is(2);
            IRule <int> rule2 = RuleMaker.Is(1) | RuleMaker.Is(2) | RuleMaker.Is(3);

            Assert.IsTrue(rule1.IsSubruleOf(rule2));
            Assert.IsFalse(rule2.IsSubruleOf(rule1));

            // Two same rules.
            Assert.IsTrue(rule1.IsSubruleOf(rule1));

            Assert.IsTrue(rule1.IsSubruleOf(RuleMaker.Anything <int>()));
            Assert.IsFalse(rule1.IsSubruleOf(RuleMaker.Nothing <int>()));

            Assert.IsTrue(RuleMaker.Anything <int>().IsSubruleOf(RuleMaker.Anything <int>()));

            Assert.IsFalse(RuleMaker.Anything <int>().IsSubruleOf(RuleMaker.Nothing <int>()));

            Assert.IsFalse(RuleMaker.Nothing <int>().IsSubruleOf(RuleMaker.Anything <int>()));
        }