ExpressionEvaluator { public final Atom evaluate(final String expression) { return evaluate(Expression.parse(expression)); } ExpressionEvaluator(); final Atom evaluate(final String expression); final Atom evaluate(final Expression expression); final Atom evaluate(final Expression expression, final EvaluationContext context); Variable getVariable(final String identifier); final void putVariable(final Variable variable); final boolean hasVariable(final String identifier); final void removeVariable(final String identifier); final void clearVariables(); final Variable[] getVariables(); Function getFunction(final String identifier); final void putFunction(final Function function); final boolean hasFunction(final String identifier); final void removeFunction(final String identifier); final void clearFunctions(); final Function[] getFunctions(); final void addDefaultVariables(); final void addDefaultFunctions();  }
@Test void contextTest() { assertEquals(evaluator.evaluate(Expression.parse("pi"), context).getValue(), BigDecimalMath.pi(context.getMathContext())); }
@Test void additiveExpressionTest() { assertEquals(new BigDecimal(18), evaluator.evaluate("8 + 10").getValue()); assertEquals(new BigDecimal(-2), evaluator.evaluate("8 - 10").getValue()); assertNotEquals(new BigDecimal(21), evaluator.evaluate("7 * 2 + 1").getValue()); }
@Test void multiplicationExpressionTest() { assertEquals(new BigDecimal(600), evaluator.evaluate("6 * 100").getValue()); assertEquals(new BigDecimal("0.2"), evaluator.evaluate("1 / 5").getValue()); assertEquals(BigDecimal.ONE, evaluator.evaluate("10 % 3").getValue()); }
@Test void parenthesisExpressionTest() { assertEquals(new BigDecimal(20), evaluator.evaluate("5 * (2 + 2)").getValue()); assertNotEquals(new BigDecimal(20), evaluator.evaluate("5 * 2 + 2").getValue()); assertEquals(new BigDecimal(10), evaluator.evaluate("|-15 + 5|").getValue()); assertEquals(new BigDecimal(25), evaluator.evaluate("|5^2|").getValue()); }
@Test void powerExpressionTest() { assertEquals(evaluator.evaluate("EXP(1)").getValue(), evaluator.evaluate("e^1").getValue()); assertEquals(new BigDecimal(17), evaluator.evaluate("1 + 2^4").getValue()); }
@Test void booleanExpressionTest() { assertEquals(BigDecimal.ONE, evaluator.evaluate("2 + 2 == 2^2").getValue()); assertEquals(BigDecimal.ONE, evaluator.evaluate("(2 + 2 != 4 OR 2 + 3 == 5) && (4^2 == 16 OR 4 % 2 == 1)").getValue()); assertEquals(BigDecimal.ONE, evaluator.evaluate("|-2 + 2| == 1 || |-2 + 2| == 0").getValue()); assertEquals(BigDecimal.ONE, evaluator.evaluate("NOT (true AND false)").getValue()); assertEquals(BigDecimal.ONE, evaluator.evaluate("!false").getValue()); assertEquals(BigDecimal.ZERO, evaluator.evaluate("!true").getValue()); }