Beispiel #1
0
 @Test
 public void testChooseLiteral() {
   Clause c = cpqr;
   while (!(c.isEmpty())) {
     Literal l = c.chooseLiteral();
     assertTrue(c.contains(l));
     c = c.reduce(l.getNegation());
   }
 }
Beispiel #2
0
public class ClauseTest {
  // helpful values for test cases
  Clause empty = make();
  Literal p = PosLiteral.make("P");
  Literal q = PosLiteral.make("Q");
  Literal r = PosLiteral.make("R");
  Literal np = p.getNegation();
  Literal nq = q.getNegation();
  Literal nr = r.getNegation();
  Clause cp = make(p);
  Clause cq = make(q);
  Clause cr = make(r);
  Clause cnp = make(np);
  Clause cnq = make(nq);
  Clause cpq = make(p, q);
  Clause cpqr = make(p, q, r);
  Clause cpnq = make(p, nq);

  // make sure assertions are turned on!
  // we don't want to run test cases without assertions too.
  // see the handout to find out how to turn them on.
  @Test(expected = AssertionError.class)
  public void testAssertionsEnabled() {
    assert false;
  }

  @Test
  public void testChooseLiteral() {
    Clause c = cpqr;
    while (!(c.isEmpty())) {
      Literal l = c.chooseLiteral();
      assertTrue(c.contains(l));
      c = c.reduce(l.getNegation());
    }
  }

  private Clause make(Literal... e) {
    Clause c = new Clause();
    for (int i = 0; i < e.length; ++i) {
      c = c.add(e[i]);
    }
    return c;
  }
}
Beispiel #3
0
  /**
   * Test if this Body is included in a rule. It is the literals of this Body are contained in the
   * body of the other rule, or if their negation is included in the head of the other rule.
   */
  public boolean isIncludedIn(Rule otherRule) {

    Iterator iter = this.enumerateLiterals();
    while (iter.hasNext()) {
      Literal current = (Literal) iter.next();
      if (!otherRule.bodyContains(current) && !otherRule.headContains(current.getNegation())) {
        return false;
      }
    }
    return true;
  }