AIMA.Core.Logic.FOL.Parsing.AST.Constant.Equals C# (CSharp) Method

Equals() public method

public Equals ( Object o ) : bool
o Object
return bool
        public override bool Equals(Object o)
        {

            if (this == o)
            {
                return true;
            }
            if (!(o is Constant))
            {
                return false;
            }
            Constant c = (Constant)o;
            return c.getValue().Equals(getValue());

        }

Usage Example

        protected void testDefiniteClauseKBKingsQueryKingXReturnsJohnAndRichardSucceeds(
                InferenceProcedure infp)
        {
            FOLKnowledgeBase kkb = FOLKnowledgeBaseFactory
                    .createKingsKnowledgeBase(infp);
            List<Term> terms = new List<Term>();
            terms.Add(new Variable("x"));
            Predicate query = new Predicate("King", terms);
            InferenceResult answer = kkb.ask(query);

            Assert.IsTrue(null != answer);
            Assert.IsFalse(answer.isPossiblyFalse());
            Assert.IsTrue(answer.isTrue());
            Assert.IsFalse(answer.isUnknownDueToTimeout());
            Assert.IsFalse(answer.isPartialResultDueToTimeout());
            Assert.IsTrue(2 == answer.getProofs().Count);
            Assert.IsTrue(1 == answer.getProofs()[0].getAnswerBindings()
                    .Count);
            Assert.IsTrue(1 == answer.getProofs()[1].getAnswerBindings()
                    .Count);

            bool gotJohn, gotRichard;
            gotJohn = gotRichard = false;
            Constant cJohn = new Constant("John");
            Constant cRichard = new Constant("Richard");
            foreach (Proof p in answer.getProofs())
            {
                Dictionary<Variable, Term> ans = p.getAnswerBindings();
                Assert.AreEqual(1, ans.Count);
                if (cJohn.Equals(ans[new Variable("x")]))
                {
                    gotJohn = true;
                }
                if (cRichard.Equals(ans[new Variable("x")]))
                {
                    gotRichard = true;
                }
            }
            Assert.IsTrue(gotJohn);
            Assert.IsTrue(gotRichard);
        }