tangled
alpha
login
or
join now
zenfyr.dev
/
EvalEx
0
fork
atom
a fork of EvalEx by ezylang with a handful of breaking changes
0
fork
atom
overview
issues
pulls
pipelines
More inlining tests.
zenfyr.dev
2 years ago
fadd439c
78d9d8a5
+37
-9
1 changed file
expand all
collapse all
unified
split
src
test
java
com
ezylang
evalex
ExpressionInlineTest.java
+37
-9
src/test/java/com/ezylang/evalex/ExpressionInlineTest.java
reviewed
···
26
26
public class ExpressionInlineTest extends BaseExpressionEvaluatorTest {
27
27
28
28
@Test
29
29
-
public void testSimpleInlinedExpression() throws ParseException, EvaluationException {
29
29
+
public void testInlinedExpression() throws ParseException, EvaluationException {
30
30
Expression expression = parser.inlineExpression(createExpression("2 + 2"));
31
31
32
32
-
assertThat(expression.evaluate(UnaryOperator.identity()).getNumberValue())
33
33
-
.isEqualTo(BigDecimal.valueOf(4));
32
32
+
assertThat(expression.evaluate(UnaryOperator.identity()).getStringValue())
33
33
+
.isEqualTo(BigDecimal.valueOf(4).toPlainString());
34
34
assertThat(expression.getAbstractSyntaxTree()).isInstanceOf(InlinedASTNode.class);
35
35
}
36
36
37
37
@Test
38
38
-
public void testConstantInlinedExpression() throws ParseException, EvaluationException {
38
38
+
public void testInlinedConstant() throws ParseException, EvaluationException {
39
39
Expression expression = parser.inlineExpression(createExpression("2 + PI"));
40
40
41
41
-
assertThat(expression.evaluate(UnaryOperator.identity()).getNumberValue())
41
41
+
assertThat(expression.evaluate(UnaryOperator.identity()).getStringValue())
42
42
.isEqualTo(
43
43
BigDecimal.valueOf(2)
44
44
.add(
45
45
new BigDecimal(
46
46
-
"3.1415926535897932384626433832795028841971693993751058209749445923078")));
46
46
+
"3.1415926535897932384626433832795028841971693993751058209749445923078"))
47
47
+
.toPlainString());
47
48
assertThat(expression.getAbstractSyntaxTree()).isInstanceOf(InlinedASTNode.class);
48
49
}
49
50
50
51
@Test
51
51
-
public void testParameterNotInlinedExpression() throws ParseException, EvaluationException {
52
52
+
public void testNotInlinedParameter() throws ParseException, EvaluationException {
52
53
Expression expression = parser.inlineExpression(createExpression("cheese / 2"));
53
54
54
54
-
assertThat(expression.evaluate(builder -> builder.parameter("cheese", 22)).getNumberValue())
55
55
+
assertThat(expression.evaluate(builder -> builder.parameter("cheese", 22)).getStringValue())
55
56
.isEqualTo(
56
56
-
BigDecimal.valueOf(22).divide(BigDecimal.valueOf(2), configuration.getMathContext()));
57
57
+
BigDecimal.valueOf(22)
58
58
+
.divide(BigDecimal.valueOf(2), configuration.getMathContext())
59
59
+
.toPlainString());
60
60
+
assertThat(expression.getAbstractSyntaxTree()).isNotInstanceOf(InlinedASTNode.class);
61
61
+
}
62
62
+
63
63
+
@Test
64
64
+
public void testFunctionInlined() throws ParseException, EvaluationException {
65
65
+
Expression expression = parser.inlineExpression(createExpression("SUM(2, 4, 6, 7)"));
66
66
+
67
67
+
assertThat(expression.evaluate(UnaryOperator.identity()).getStringValue())
68
68
+
.isEqualTo(BigDecimal.valueOf(2 + 4 + 6 + 7).toPlainString());
69
69
+
assertThat(expression.getAbstractSyntaxTree()).isInstanceOf(InlinedASTNode.class);
70
70
+
}
71
71
+
72
72
+
@Test
73
73
+
public void testFunctionNotInlined() throws ParseException, EvaluationException {
74
74
+
Expression expression = parser.inlineExpression(createExpression("SUM(2, a, 6, 7)"));
75
75
+
76
76
+
assertThat(expression.evaluate(builder -> builder.parameter("a", 5)).getStringValue())
77
77
+
.isEqualTo(BigDecimal.valueOf(2 + 5 + 6 + 7).toPlainString());
78
78
+
assertThat(expression.getAbstractSyntaxTree()).isNotInstanceOf(InlinedASTNode.class);
79
79
+
}
80
80
+
81
81
+
@Test
82
82
+
public void testRandomNotInlined() throws ParseException, EvaluationException {
83
83
+
Expression expression = parser.inlineExpression(createExpression("RANDOM()"));
84
84
+
57
85
assertThat(expression.getAbstractSyntaxTree()).isNotInstanceOf(InlinedASTNode.class);
58
86
}
59
87
}