Пример #1
0
 @Test(expected = IllegalArgumentException.class)
 public void testNOfFunctionInderterminate() throws EvaluationException {
   IntegerExp n = IntegerExp.of(4);
   replay(context);
   assertEquals(
       BooleanExp.valueOf(false), LogicalFunctions.nof(context, n, BooleanExp.valueOf(false)));
   verify(context);
 }
Пример #2
0
  @Test
  public void testLazyAndFunctionParamEvaluation() throws EvaluationException {
    Expression p1 = control.createMock(Expression.class);
    Expression p2 = control.createMock(Expression.class);
    Expression p3 = control.createMock(Expression.class);

    expect(p1.evaluate(context)).andReturn(BooleanExp.valueOf(false));
    control.replay();

    assertEquals(BooleanExp.valueOf(false), LogicalFunctions.and(context, p1, p2, p3));
    control.verify();

    control.reset();
    expect(p1.evaluate(context)).andReturn(BooleanExp.valueOf(true));
    expect(p2.evaluate(context)).andReturn(BooleanExp.valueOf(false));
    control.replay();

    assertEquals(BooleanExp.valueOf(false), LogicalFunctions.and(context, p1, p2, p3));
    control.verify();

    control.reset();
    expect(p1.evaluate(context)).andReturn(BooleanExp.valueOf(true));
    expect(p2.evaluate(context)).andReturn(BooleanExp.valueOf(true));
    expect(p3.evaluate(context)).andReturn(BooleanExp.valueOf(false));
    control.replay();

    assertEquals(BooleanExp.valueOf(false), LogicalFunctions.and(context, p1, p2, p3));
    control.verify();
  }
Пример #3
0
  @Test
  public void testAndFunction() throws EvaluationException {
    control.replay();
    assertEquals(
        BooleanExp.valueOf(false),
        LogicalFunctions.and(context, BooleanExp.valueOf(false), BooleanExp.valueOf(false)));
    control.verify();

    control.reset();
    control.replay();
    assertEquals(
        BooleanExp.valueOf(false),
        LogicalFunctions.and(context, BooleanExp.valueOf(true), BooleanExp.valueOf(false)));
    control.verify();

    control.reset();
    control.replay();
    assertEquals(
        BooleanExp.valueOf(true),
        LogicalFunctions.and(context, BooleanExp.valueOf(true), BooleanExp.valueOf(true)));
    control.verify();

    control.reset();
    control.replay();
    assertEquals(
        BooleanExp.valueOf(false),
        LogicalFunctions.and(context, BooleanExp.valueOf(false), BooleanExp.valueOf(true)));
    control.verify();
  }
Пример #4
0
 @Test
 public void testNOfFunction() throws EvaluationException {
   IntegerExp n = IntegerExp.of(0);
   replay(context);
   assertEquals(BooleanExp.valueOf(true), LogicalFunctions.nof(context, n));
   verify(context);
   reset(context);
   replay(context);
   n = IntegerExp.of(1);
   assertEquals(
       BooleanExp.valueOf(true), LogicalFunctions.nof(context, n, BooleanExp.valueOf(true)));
   verify(context);
   reset(context);
   replay(context);
   assertEquals(
       BooleanExp.valueOf(false), LogicalFunctions.nof(context, n, BooleanExp.valueOf(false)));
   verify(context);
   reset(context);
   replay(context);
   n = IntegerExp.of(2);
   assertEquals(
       BooleanExp.valueOf(true),
       LogicalFunctions.nof(context, n, BooleanExp.valueOf(true), BooleanExp.valueOf(true)));
   verify(context);
   reset(context);
   replay(context);
   assertEquals(
       BooleanExp.valueOf(false),
       LogicalFunctions.nof(context, n, BooleanExp.valueOf(true), BooleanExp.valueOf(false)));
   verify(context);
   reset(context);
   replay(context);
   n = IntegerExp.of(2);
   assertEquals(
       BooleanExp.valueOf(true),
       LogicalFunctions.nof(
           context,
           n,
           BooleanExp.valueOf(true),
           BooleanExp.valueOf(false),
           BooleanExp.valueOf(true)));
   verify(context);
 }