Пример #1
0
  @Test
  public void testFalse() throws Exception {
    assertTrue(!(new UnaryOr<Object>()).test("xyzzy"));
    assertTrue(!(new UnaryOr<Object>(Constant.FALSE)).test("xyzzy"));
    assertTrue(!(new UnaryOr<Object>(Constant.FALSE, Constant.FALSE)).test("xyzzy"));
    assertTrue(
        !(new UnaryOr<Object>(Constant.FALSE, Constant.FALSE, Constant.FALSE)).test("xyzzy"));

    UnaryOr<Object> p = new UnaryOr<Object>(Constant.FALSE);
    assertTrue(!p.test("xyzzy"));
    for (int i = 0; i < 10; i++) {
      p.or(Constant.FALSE);
      assertTrue(!p.test("xyzzy"));
    }

    UnaryOr<Object> q = new UnaryOr<Object>(Constant.FALSE);
    assertTrue(!q.test("xyzzy"));
    for (int i = 0; i < 10; i++) {
      q.or(Constant.FALSE);
      assertTrue(!q.test("xyzzy"));
    }

    UnaryOr<Object> r = new UnaryOr<Object>(p, q);
    assertTrue(!r.test("xyzzy"));
  }
Пример #2
0
  @Test
  public void testEquals() throws Exception {
    UnaryOr<Object> p = new UnaryOr<Object>();
    assertEquals(p, p);

    UnaryOr<Object> q = new UnaryOr<Object>();
    assertObjectsAreEqual(p, q);

    UnaryAnd<Object> r = new UnaryAnd<Object>();
    assertObjectsAreNotEqual(p, r);

    for (int i = 0; i < 3; i++) {
      p.or(Constant.truePredicate());
      assertObjectsAreNotEqual(p, q);
      q.or(Constant.truePredicate());
      assertObjectsAreEqual(p, q);
      r.and(Constant.truePredicate());
      assertObjectsAreNotEqual(p, r);

      p.or(new UnaryOr<Object>(Constant.truePredicate(), Constant.falsePredicate()));
      assertObjectsAreNotEqual(p, q);
      q.or(new UnaryOr<Object>(Constant.truePredicate(), Constant.falsePredicate()));
      assertObjectsAreEqual(p, q);
      r.and(new UnaryOr<Object>(Constant.truePredicate(), Constant.falsePredicate()));
      assertObjectsAreNotEqual(p, r);
    }

    assertObjectsAreNotEqual(p, Constant.truePredicate());
    UnaryOr<Object> s = new UnaryOr<Object>();
    s.or(Constant.truePredicate());
    s.or(new UnaryOr<Object>(Constant.truePredicate(), Constant.falsePredicate()));
    assertObjectsAreEqual(s, new UnaryOr<Object>(s.getUnaryPredicateList()));
  }
Пример #3
0
 @Test
 public void testDuplicateAdd() throws Exception {
   UnaryPredicate<Object> p = Constant.TRUE;
   UnaryOr<Object> q = new UnaryOr<Object>(p, p);
   assertTrue(q.test("xyzzy"));
   for (int i = 0; i < 10; i++) {
     q.or(p);
     assertTrue(q.test("xyzzy"));
   }
 }
Пример #4
0
  @Test
  public void testTrue() throws Exception {
    assertTrue((new UnaryOr<Object>(Constant.TRUE)).test("xyzzy"));
    assertTrue((new UnaryOr<Object>(Constant.FALSE, Constant.TRUE)).test("xyzzy"));
    assertTrue((new UnaryOr<Object>(Constant.FALSE, Constant.FALSE, Constant.TRUE)).test("xyzzy"));

    UnaryOr<Object> p = new UnaryOr<Object>(Constant.TRUE);
    assertTrue(p.test("xyzzy"));
    for (int i = 0; i < 10; i++) {
      p.or(Constant.of(i % 2 == 0));
      assertTrue(p.test("xyzzy"));
    }

    UnaryOr<Object> q = new UnaryOr<Object>(Constant.TRUE);
    assertTrue(q.test("xyzzy"));
    for (int i = 0; i < 10; i++) {
      q.or(Constant.of(i % 2 == 0));
      assertTrue(q.test("xyzzy"));
    }

    UnaryOr<Object> r = new UnaryOr<Object>(p, q);
    assertTrue(r.test("xyzzy"));
  }