Search in sources :

Example 1 with PostfixMathCommandI

use of org.nfunk.jep.function.PostfixMathCommandI in project pcgen by PCGen.

the class IfCommandTest method testIf04.

/* Test the case where the condition is a true boolean */
public void testIf04() {
    final PostfixMathCommandI c = new IfCommand();
    final Stack<Boolean> s = new Stack<>();
    s.push(true);
    s.push(false);
    s.push(true);
    runIf(s, c);
    final Boolean result = s.pop();
    is(result, eq(false), "if (true,false,true) returns false");
}
Also used : PostfixMathCommandI(org.nfunk.jep.function.PostfixMathCommandI) Stack(java.util.Stack)

Example 2 with PostfixMathCommandI

use of org.nfunk.jep.function.PostfixMathCommandI in project pcgen by PCGen.

the class IfCommandTest method testIf02.

/* Test the case where the condition is a non zero double */
public void testIf02() {
    final PostfixMathCommandI c = new IfCommand();
    final Stack<Double> s = new Stack<>();
    s.push(1.0);
    s.push(1.0);
    s.push(2.0);
    runIf(s, c);
    final Double result = s.pop();
    is(result, eq(1.0, 0.1), "if (1.0,1.0,2.0) returns 1.0");
}
Also used : PostfixMathCommandI(org.nfunk.jep.function.PostfixMathCommandI) Stack(java.util.Stack)

Example 3 with PostfixMathCommandI

use of org.nfunk.jep.function.PostfixMathCommandI in project pcgen by PCGen.

the class OrCommandTest method testOr02.

/* Test the case where the first operand is false, but the second is true */
public void testOr02() {
    final PostfixMathCommandI c = new OrCommand();
    final Stack<Double> s = new Stack<>();
    s.push(0.0);
    s.push(2.0);
    c.setCurNumberOfParameters(2);
    runOr(s, c);
    final Double result = s.pop();
    is(result, eq(2.0, 0.1), "if (0.0,2.0) returns 2.0");
}
Also used : PostfixMathCommandI(org.nfunk.jep.function.PostfixMathCommandI) CompareEqualDouble(pcgen.util.testchecker.CompareEqualDouble) Stack(java.util.Stack)

Example 4 with PostfixMathCommandI

use of org.nfunk.jep.function.PostfixMathCommandI in project pcgen by PCGen.

the class OrCommandTest method testOr01.

/* Test the case where the first operand is true */
public void testOr01() {
    final PostfixMathCommandI c = new OrCommand();
    final Stack<Object> s = new Stack<>();
    s.push(1.0);
    s.push(2.0);
    c.setCurNumberOfParameters(2);
    runOr(s, c);
    final Double result = (Double) s.pop();
    is(result, eq(1.0, 0.1), "if (1.0,2.0) returns 1.0");
}
Also used : PostfixMathCommandI(org.nfunk.jep.function.PostfixMathCommandI) CompareEqualDouble(pcgen.util.testchecker.CompareEqualDouble) Stack(java.util.Stack)

Example 5 with PostfixMathCommandI

use of org.nfunk.jep.function.PostfixMathCommandI in project pcgen by PCGen.

the class OrCommandTest method testOr05.

/* Test the case where false and zero are skipped */
public void testOr05() {
    final PostfixMathCommandI c = new OrCommand();
    final Stack s = new Stack();
    s.push(false);
    s.push(false);
    s.push(false);
    s.push(false);
    c.setCurNumberOfParameters(4);
    runOr(s, c);
    final Object result = s.pop();
    is(result, new CompareEqualDouble(0.0), "if (false,false,false,false) returns 0.0");
}
Also used : PostfixMathCommandI(org.nfunk.jep.function.PostfixMathCommandI) CompareEqualDouble(pcgen.util.testchecker.CompareEqualDouble) Stack(java.util.Stack)

Aggregations

PostfixMathCommandI (org.nfunk.jep.function.PostfixMathCommandI)11 Stack (java.util.Stack)9 CompareEqualDouble (pcgen.util.testchecker.CompareEqualDouble)3 ParseException (org.nfunk.jep.ParseException)1