Skip to content

Commit

Permalink
[#688] Unary tests: Add tests for ? in the right operand of In expres…
Browse files Browse the repository at this point in the history
…sions
  • Loading branch information
opatrascoiu committed Jul 22, 2024
1 parent 689671d commit f1b702f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -665,16 +665,26 @@ public Object visit(InExpression<Type> element, DMNContext context) {
DMNContext testContext = context.isTestContext() ? context : this.dmnTransformer.makeUnaryTestContext(valueExp, context);
testContext.bind(INPUT_ENTRY_PLACE_HOLDER, value);

List<Object> result = new ArrayList<>();
List<PositiveUnaryTest<Type>> positiveUnaryTests = element.getTests();
for (PositiveUnaryTest<Type> positiveUnaryTest : positiveUnaryTests) {
Object test = positiveUnaryTest.accept(this, testContext);
result.add(test);
}
if (result.size() == 1) {
return result.get(0);
} else {
return this.lib.booleanOr(result);
try {
List<Object> result = new ArrayList<>();
List<PositiveUnaryTest<Type>> positiveUnaryTests = element.getTests();
for (PositiveUnaryTest<Type> positiveUnaryTest : positiveUnaryTests) {
Object condition;
if (positiveUnaryTest instanceof ExpressionTest) {
condition = evaluateOperatorRange(element, "=", value, ((ExpressionTest<Type>) positiveUnaryTest).getExpression(), context);
} else {
condition = positiveUnaryTest.accept(this, testContext);
}
result.add(condition);
}
if (result.size() == 1) {
return result.get(0);
} else {
return this.lib.booleanOr(result);
}
} catch (Exception e) {
this.errorHandler.reportError(String.format("Cannot evaluate '%s'", element), e);
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,13 @@ public Triple visit(InExpression<Type> element, DMNContext context) {
DMNContext testContext = context.isTestContext() ? context : this.dmnTransformer.makeUnaryTestContext(valueExp, context);
List<Triple> result = new ArrayList<>();
for (PositiveUnaryTest<Type> positiveUnaryTest : positiveUnaryTests) {
Triple test = (Triple) positiveUnaryTest.accept(this, testContext);
result.add(test);
Triple condition;
if (positiveUnaryTest instanceof ExpressionTest) {
condition = makeRangeCondition("=", valueExp, ((ExpressionTest<Type>) positiveUnaryTest).getExpression(), context);
} else {
condition = (Triple) positiveUnaryTest.accept(this, testContext);
}
result.add(condition);
}
if (result.size() == 1) {
return result.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void testExpressionTest() {
);

//
// ExpressionTest
// Simple expressions
//
doUnaryTestsTest(entries, "number", "? < 2 + 3",
"PositiveUnaryTests(ExpressionTest(Relational(<,Name(?),Addition(+,NumericLiteral(2),NumericLiteral(3)))))",
Expand Down Expand Up @@ -355,6 +355,28 @@ public void testExpressionTest() {
"booleanOr(numericLessThan(input, number(\"1\")), booleanAnd(numericGreaterEqualThan(input, number(\"1\")), numericLessEqualThan(input, number(\"2\"))), numericEqual(input, number(\"3\")))",
this.lib.booleanOr(this.lib.numericLessThan(input, this.lib.number("1")), this.lib.booleanAnd(this.lib.numericGreaterEqualThan(input, this.lib.number("1")), this.lib.numericLessEqualThan(input, this.lib.number("2"))), this.lib.numericEqual(input, this.lib.number("3"))),
true);

// null test
doUnaryTestsTest(entries, "input", "? in null",
"PositiveUnaryTests(ExpressionTest(InExpression(Name(?), NullTest())))",
"TupleType(boolean)",
"input == null",
input == null,
false);

// ? is in the right end side
doUnaryTestsTest(entries, "input", "1 in (?, ?)",
"PositiveUnaryTests(ExpressionTest(InExpression(NumericLiteral(1), ExpressionTest(Name(?)), ExpressionTest(Name(?)))))",
"TupleType(boolean)",
"booleanOr(numericEqual(number(\"1\"), input), numericEqual(number(\"1\"), input))",
this.lib.booleanOr(this.lib.numericEqual(this.lib.number("1"), input), this.lib.numericEqual(this.lib.number("1"), input)),
true);
doUnaryTestsTest(entries, "input", "1 in ?",
"PositiveUnaryTests(ExpressionTest(InExpression(NumericLiteral(1), ExpressionTest(Name(?)))))",
"TupleType(boolean)",
"numericEqual(number(\"1\"), input)",
this.lib.numericEqual(this.lib.number("1"), input),
true);
}

@Test
Expand Down

0 comments on commit f1b702f

Please sign in to comment.