domain.addPredicate("Q");
FOLParser parser = new FOLParser(domain);
// p(x,y), q(a,b), p(b,a), q(y,x)
Clause c = new Clause();
c.addPositiveLiteral((Predicate) parser.parse("P(x,y)"));
c.addPositiveLiteral((Predicate) parser.parse("Q(A,B)"));
c.addNegativeLiteral((Predicate) parser.parse("P(B,A)"));
c.addPositiveLiteral((Predicate) parser.parse("Q(y,x)"));
Assert.assertEquals("[[~P(B,A), P(B,A), Q(A,B)]]", c
.getNonTrivialFactors().toString());
// p(x,y), q(a,b), p(b,a), q(y,x)
c = new Clause();
c.addPositiveLiteral((Predicate) parser.parse("P(x,y)"));
c.addPositiveLiteral((Predicate) parser.parse("Q(A,B)"));
c.addNegativeLiteral((Predicate) parser.parse("P(B,A)"));
c.addNegativeLiteral((Predicate) parser.parse("Q(y,x)"));
Assert.assertEquals("[]", c.getNonTrivialFactors().toString());
// p(x,f(y)), p(g(u),x), p(f(y),u)
c = new Clause();
c.addPositiveLiteral((Predicate) parser.parse("P(x,F(y))"));
c.addPositiveLiteral((Predicate) parser.parse("P(G(u),x)"));
c.addPositiveLiteral((Predicate) parser.parse("P(F(y),u)"));
// Should be: [{P(F(c#),F(c#)),P(G(F(c#)),F(c#))}]
c = c.getNonTrivialFactors().iterator().next();
Literal p = c.getPositiveLiterals().get(0);
Assert.assertEquals("P", p.getAtomicSentence().getSymbolicName());
Function f = (Function) p.getAtomicSentence().getArgs().get(0);
Assert.assertEquals("F", f.getFunctionName());
Variable v = (Variable) f.getTerms().get(0);
f = (Function) p.getAtomicSentence().getArgs().get(1);
Assert.assertEquals("F", f.getFunctionName());
Assert.assertEquals(v, f.getTerms().get(0));
//
p = c.getPositiveLiterals().get(1);
f = (Function) p.getAtomicSentence().getArgs().get(0);
Assert.assertEquals("G", f.getFunctionName());
f = (Function) f.getTerms().get(0);
Assert.assertEquals("F", f.getFunctionName());
Assert.assertEquals(v, f.getTerms().get(0));
f = (Function) p.getAtomicSentence().getArgs().get(1);
Assert.assertEquals("F", f.getFunctionName());
Assert.assertEquals(v, f.getTerms().get(0));
// p(g(x)), q(x), p(f(a)), p(x), p(g(f(x))), q(f(a))
c = new Clause();
c.addPositiveLiteral((Predicate) parser.parse("P(G(x))"));
c.addPositiveLiteral((Predicate) parser.parse("Q(x)"));
c.addPositiveLiteral((Predicate) parser.parse("P(F(A))"));
c.addPositiveLiteral((Predicate) parser.parse("P(x)"));
c.addPositiveLiteral((Predicate) parser.parse("P(G(F(x)))"));
c.addPositiveLiteral((Predicate) parser.parse("Q(F(A))"));
Assert.assertEquals("[[P(F(A)), P(G(F(F(A)))), P(G(F(A))), Q(F(A))]]",
c.getNonTrivialFactors().toString());
}