a fork of EvalEx by ezylang with a handful of breaking changes

More inlining tests.

Changed files
+37 -9
src
test
java
com
ezylang
+37 -9
src/test/java/com/ezylang/evalex/ExpressionInlineTest.java
··· 26 26 public class ExpressionInlineTest extends BaseExpressionEvaluatorTest { 27 27 28 28 @Test 29 - public void testSimpleInlinedExpression() throws ParseException, EvaluationException { 29 + public void testInlinedExpression() throws ParseException, EvaluationException { 30 30 Expression expression = parser.inlineExpression(createExpression("2 + 2")); 31 31 32 - assertThat(expression.evaluate(UnaryOperator.identity()).getNumberValue()) 33 - .isEqualTo(BigDecimal.valueOf(4)); 32 + assertThat(expression.evaluate(UnaryOperator.identity()).getStringValue()) 33 + .isEqualTo(BigDecimal.valueOf(4).toPlainString()); 34 34 assertThat(expression.getAbstractSyntaxTree()).isInstanceOf(InlinedASTNode.class); 35 35 } 36 36 37 37 @Test 38 - public void testConstantInlinedExpression() throws ParseException, EvaluationException { 38 + public void testInlinedConstant() throws ParseException, EvaluationException { 39 39 Expression expression = parser.inlineExpression(createExpression("2 + PI")); 40 40 41 - assertThat(expression.evaluate(UnaryOperator.identity()).getNumberValue()) 41 + assertThat(expression.evaluate(UnaryOperator.identity()).getStringValue()) 42 42 .isEqualTo( 43 43 BigDecimal.valueOf(2) 44 44 .add( 45 45 new BigDecimal( 46 - "3.1415926535897932384626433832795028841971693993751058209749445923078"))); 46 + "3.1415926535897932384626433832795028841971693993751058209749445923078")) 47 + .toPlainString()); 47 48 assertThat(expression.getAbstractSyntaxTree()).isInstanceOf(InlinedASTNode.class); 48 49 } 49 50 50 51 @Test 51 - public void testParameterNotInlinedExpression() throws ParseException, EvaluationException { 52 + public void testNotInlinedParameter() throws ParseException, EvaluationException { 52 53 Expression expression = parser.inlineExpression(createExpression("cheese / 2")); 53 54 54 - assertThat(expression.evaluate(builder -> builder.parameter("cheese", 22)).getNumberValue()) 55 + assertThat(expression.evaluate(builder -> builder.parameter("cheese", 22)).getStringValue()) 55 56 .isEqualTo( 56 - BigDecimal.valueOf(22).divide(BigDecimal.valueOf(2), configuration.getMathContext())); 57 + BigDecimal.valueOf(22) 58 + .divide(BigDecimal.valueOf(2), configuration.getMathContext()) 59 + .toPlainString()); 60 + assertThat(expression.getAbstractSyntaxTree()).isNotInstanceOf(InlinedASTNode.class); 61 + } 62 + 63 + @Test 64 + public void testFunctionInlined() throws ParseException, EvaluationException { 65 + Expression expression = parser.inlineExpression(createExpression("SUM(2, 4, 6, 7)")); 66 + 67 + assertThat(expression.evaluate(UnaryOperator.identity()).getStringValue()) 68 + .isEqualTo(BigDecimal.valueOf(2 + 4 + 6 + 7).toPlainString()); 69 + assertThat(expression.getAbstractSyntaxTree()).isInstanceOf(InlinedASTNode.class); 70 + } 71 + 72 + @Test 73 + public void testFunctionNotInlined() throws ParseException, EvaluationException { 74 + Expression expression = parser.inlineExpression(createExpression("SUM(2, a, 6, 7)")); 75 + 76 + assertThat(expression.evaluate(builder -> builder.parameter("a", 5)).getStringValue()) 77 + .isEqualTo(BigDecimal.valueOf(2 + 5 + 6 + 7).toPlainString()); 78 + assertThat(expression.getAbstractSyntaxTree()).isNotInstanceOf(InlinedASTNode.class); 79 + } 80 + 81 + @Test 82 + public void testRandomNotInlined() throws ParseException, EvaluationException { 83 + Expression expression = parser.inlineExpression(createExpression("RANDOM()")); 84 + 57 85 assertThat(expression.getAbstractSyntaxTree()).isNotInstanceOf(InlinedASTNode.class); 58 86 } 59 87 }