@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")); }
@Test public void testEquals() throws Exception { CompositeUnaryPredicate<Object> f = new CompositeUnaryPredicate<Object>(Constant.TRUE); assertEquals(f, f); CompositeUnaryPredicate<Object> g = new CompositeUnaryPredicate<Object>(Constant.TRUE); assertObjectsAreEqual(f, g); for (int i = 0; i < 3; i++) { f = f.of(Constant.of("x")); assertObjectsAreNotEqual(f, g); g = g.of(Constant.of("x")); assertObjectsAreEqual(f, g); f = f.of(Constant.of("y")).of(Constant.of("z")); assertObjectsAreNotEqual(f, g); g = g.of(Constant.of("y")).of(Constant.of("z")); assertObjectsAreEqual(f, g); } assertObjectsAreNotEqual(f, Constant.FALSE); assertTrue(!f.equals(null)); }
@Test public void testTest() throws Exception { assertTrue(Composite.predicate(Constant.TRUE).test(null)); assertTrue(Composite.predicate(Constant.TRUE, Constant.of(3)).test("xyzzy")); assertFalse(Composite.predicate(Constant.FALSE, Constant.of(4)).test("xyzzy")); }
@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())); }