Skip to content

Commit

Permalink
Merge pull request #43 from sidhant92/array_math_functions
Browse files Browse the repository at this point in the history
Fix Negative Comparison
  • Loading branch information
sidhant92 authored Aug 24, 2024
2 parents 17dfb51 + 5cf9ac5 commit 86fb416
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void exitArithmeticExpression(BooleanExpressionParser.ArithmeticExpressio

@Override
public void exitUnaryArithmeticExpression(BooleanExpressionParser.UnaryArithmeticExpressionContext ctx) {
final Node leafNode = !currentNodes.isEmpty() ? currentNodes.pop() : mapTypesExpressionContext(
final Node leafNode = !currentNodes.isEmpty() && currentNodes.peek() instanceof ArithmeticNode ? currentNodes.pop() : mapTypesExpressionContext(
(BooleanExpressionParser.TypesExpressionContext) ctx.exp);
currentNodes.add(ArithmeticNode.builder().left(leafNode).operator(Operator.UNARY).build());
super.enterUnaryArithmeticExpression(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,15 @@ public void testComparisonWithArithmeticFalseCondition1() {
assertFalse(booleanOptional.get());
}

@Test
public void testNegativeComparison() {
final Map<String, Object> data = new HashMap<>();
data.put("a", -6);
final Try<Boolean> resultOptional = booleanExpressionEvaluator.evaluate("a > -10 AND a < -2", data);
assertTrue(resultOptional.isSuccess());
assertEquals(resultOptional.get(), true);
}

@Test
public void testNullCheck() {
final Map<String, Object> data = new HashMap<>();
Expand Down

0 comments on commit 86fb416

Please sign in to comment.