domain.addPredicate("Pred1");
domain.addPredicate("Pred2");
domain.addPredicate("Pred3");
domain.addPredicate("Pred4");
Clause c1 = new Clause();
// Ensure that resolving to self when empty returns an empty clause
Assert.assertNotNull(c1.binaryResolvents(c1));
Assert.assertEquals(1, c1.binaryResolvents(c1).size());
Assert.assertTrue(c1.binaryResolvents(c1).iterator().next().isEmpty());
// Check if resolve with self to an empty clause
c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
c1.addNegativeLiteral(new Predicate("Pred1", new ArrayList<Term>()));
Assert.assertNotNull(c1.binaryResolvents(c1));
Assert.assertEquals(1, c1.binaryResolvents(c1).size());
// i.e. resolving a tautology with a tautology gives you
// back a tautology.
Assert.assertEquals("[~Pred1(), Pred1()]", c1.binaryResolvents(c1)
.iterator().next().toString());
// Check if try to resolve with self and no resolvents
c1 = new Clause();
c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
Assert.assertEquals(0, c1.binaryResolvents(c1).size());
c1 = new Clause();
Clause c2 = new Clause();
// Ensure that two empty clauses resolve to an empty clause
Assert.assertNotNull(c1.binaryResolvents(c2));
Assert.assertEquals(1, c1.binaryResolvents(c2).size());
Assert.assertTrue(c1.binaryResolvents(c2).iterator().next().isEmpty());
Assert.assertNotNull(c2.binaryResolvents(c1));
Assert.assertEquals(1, c2.binaryResolvents(c1).size());
Assert.assertTrue(c2.binaryResolvents(c1).iterator().next().isEmpty());
// Enusre the two complementary clauses resolve
// to the empty clause
c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
c2.addNegativeLiteral(new Predicate("Pred1", new ArrayList<Term>()));
Assert.assertNotNull(c1.binaryResolvents(c2));
Assert.assertEquals(1, c1.binaryResolvents(c2).size());
Assert.assertTrue(c1.binaryResolvents(c2).iterator().next().isEmpty());
Assert.assertNotNull(c2.binaryResolvents(c1));
Assert.assertEquals(1, c2.binaryResolvents(c1).size());
Assert.assertTrue(c2.binaryResolvents(c1).iterator().next().isEmpty());
// Ensure that two clauses that have two complementaries
// resolve with two resolvents
c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
c2.addNegativeLiteral(new Predicate("Pred1", new ArrayList<Term>()));
c1.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));
c2.addNegativeLiteral(new Predicate("Pred2", new ArrayList<Term>()));
Assert.assertNotNull(c1.binaryResolvents(c2));
Assert.assertEquals(2, c1.binaryResolvents(c2).size());
Assert.assertNotNull(c2.binaryResolvents(c1));
Assert.assertEquals(2, c2.binaryResolvents(c1).size());
// Ensure two clauses that factor are not
// considered resolved
c1 = new Clause();
c2 = new Clause();
c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
c1.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));
c1.addNegativeLiteral(new Predicate("Pred3", new ArrayList<Term>()));
c1.addNegativeLiteral(new Predicate("Pred4", new ArrayList<Term>()));
c2.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));
c2.addNegativeLiteral(new Predicate("Pred4", new ArrayList<Term>()));
Assert.assertNotNull(c1.binaryResolvents(c2));
Assert.assertEquals(0, c1.binaryResolvents(c2).size());
Assert.assertNotNull(c2.binaryResolvents(c1));
Assert.assertEquals(0, c2.binaryResolvents(c1).size());
// Ensure the resolvent is a subset of the originals
c1 = new Clause();
c2 = new Clause();
c1.addPositiveLiteral(new Predicate("Pred1", new ArrayList<Term>()));
c1.addNegativeLiteral(new Predicate("Pred2", new ArrayList<Term>()));
c1.addNegativeLiteral(new Predicate("Pred3", new ArrayList<Term>()));
c2.addPositiveLiteral(new Predicate("Pred2", new ArrayList<Term>()));
Assert.assertNotNull(c1.binaryResolvents(c2));
Assert.assertNotNull(c2.binaryResolvents(c1));
Assert.assertEquals(1, c1.binaryResolvents(c2).iterator().next()
.getNumberPositiveLiterals());
Assert.assertEquals(1, c1.binaryResolvents(c2).iterator().next()
.getNumberNegativeLiterals());
Assert.assertEquals(1, c2.binaryResolvents(c1).iterator().next()
.getNumberPositiveLiterals());
Assert.assertEquals(1, c2.binaryResolvents(c1).iterator().next()
.getNumberNegativeLiterals());
}