Re: [PR] [incubator-kie-issues#2174] Unit test cases for Dialect Handler classes [incubator-kie-drools]
yesamer merged PR #6632: URL: https://github.com/apache/incubator-kie-drools/pull/6632 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] [incubator-kie-issues#2174] Unit test cases for Dialect Handler classes [incubator-kie-drools]
Copilot commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3147439827
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,294 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
Review Comment:
BFEELDialectHandler behavior depends on ctx.getFEELDialect() (e.g.,
DefaultDialectHandler/InfixExecutorUtils apply BFEEL-specific coercions and
defaults based on the dialect). This test sets up an EvaluationContext that
defaults to FEEL, so the assertions may not reflect real BFEEL execution via
DialectHandlerFactory. Please initialize the context with FEELDialect.BFEEL
(e.g., EvaluationContextImpl(..., FEELDialect.BFEEL) or a mock returning BFEEL).
##
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandler.java:
##
@@ -60,20 +80,64 @@ public Map> getAddOperation
return leftNum + rightNum;
});
-// date + number → return the number
+// Row 2: NUMBER - date + number → convert date to 0, then add: 0 +
number = number
+// Since 0 + number = number, we return the number operand directly
map.put(
new CheckedPredicate((left, right) -> left instanceof
LocalDate && right instanceof Number, false),
(left, right) -> right);
+
+// Row 2: NUMBER - number + date → convert date to 0, then add: number
+ 0 = number
+// Since number + 0 = number, we return the number operand directly
map.put(
new CheckedPredicate((left, right) -> left instanceof Number
&& right instanceof LocalDate, false),
(left, right) -> left);
-// Number + null → number
+// Row 2: NUMBER - duration + number → convert duration to seconds,
then add
+map.put(
+new CheckedPredicate((left, right) -> left instanceof Duration
&& right instanceof Number, false),
+(left, right) -> {
+BigDecimal seconds = getBigDecimalOrNull(((Duration)
left).getSeconds());
+BigDecimal rightNum = getBigDecimalOrNull(right);
+if (seconds == null || rightNum == null) return rightNum
!= null ? rightNum : BigDecimal.ZERO;
+return seconds.add(rightNum, MathContext.DECIMAL128);
+});
+
+// Row 2: NUMBER - number + duration → convert duration to seconds,
then add
+map.put(
+new CheckedPredicate((left, right) -> left instanceof Number
&& right instanceof Duration, false),
+(left, right) -> {
+BigDecimal leftNum = getBigDecimalOrNull(left);
+BigDecimal seconds = getBigDecimalOrNull(((Duration)
right).getSeconds());
+if (leftNum == null || seconds == null) return leftNum !=
null ? leftNum : BigDecimal.ZERO;
+return leftNum.add(seconds, MathContext.DECIMAL128);
+});
+
+// Row 2: NUMBER - period + number → convert period to months, then add
+map.put(
+new CheckedPredicate((left, right) -> left instanceof
ChronoPeriod && right instanceof Number, false),
+(left, right) -
Re: [PR] [incubator-kie-issues#2174] Unit test cases for Dialect Handler classes [incubator-kie-drools]
yesamer commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3115990755
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -44,192 +44,240 @@ void setUp() {
handler = new BFEELDialectHandler();
ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
}
-
+
@Test
-void testAddOperations() {
-// String concatenation with type coercion
-assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
-assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
-assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
-
-// Numbers
+void testAdditionWithPrecedenceOrder() {
+//Basic addition operation
assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+// Case 1 : STRING - If either operand is a string, convert non-string
to string
+// Left: string + other
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Date:", LocalDate.of(2024, 1, 1),
ctx)).isEqualTo("Date:2024-01-01");
+assertThat(handler.executeAdd("Duration:", Duration.ofDays(5),
ctx)).isEqualTo("Duration:PT120H");
+assertThat(handler.executeAdd("Period:", Period.ofMonths(3),
ctx)).isEqualTo("Period:P3M");
-// Date operations - returns number instead of null
+// Right: other + string
+assertThat(handler.executeAdd(123, "World",
ctx)).isEqualTo("123World");
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), " is the
date", ctx)).isEqualTo("2024-01-01 is the date");
+assertThat(handler.executeAdd(Duration.ofDays(5), " duration",
ctx)).isEqualTo("PT120H duration");
+assertThat(handler.executeAdd(Period.ofMonths(3), " period",
ctx)).isEqualTo("P3M period");
+
+// Case 2 : NUMBER - If either operand is a number (and neither is
string), convert non-number to number
+// Per BFEEL Section 11.3: number(date) = 0, number(duration) =
seconds, number(period) = months
+
+// Left: date + number → 0 + number = number
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), new
BigDecimal("10.5"), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Right: number + date → number + 0 = number
+assertThat(handler.executeAdd(5, LocalDate.of(2024, 1, 1),
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(new BigDecimal("10.5"),
LocalDate.of(2024, 1, 1), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Case 3: DATE - If either operand is a date, convert non-date to
duration
+// Left: date + duration
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
.isEqualTo(LocalDate.of(2024, 1, 6));
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Period.ofMonths(2), ctx))
+.isEqualTo(LocalDate.of(2024, 3, 1));
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
}
@Test
-void testLogicalOperations() {
-// AND with boolean coercion
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
-
-// OR operations
-assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-}
-
-@Test
-void testEqualityOperations() {
-// Equal - returns false for different types (not null)
-assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
-assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+void testSubtractionWithPrecedenceOrder() {
+// Basic subtraction operation
+assertThat(handler.executeSub(20, 10, ctx)).isEqualTo(new
BigDecimal("10"));
+// Case 1: STRING - If either operand is a string, subtraction returns
empty string ""
+// Left: string - other
+assertThat(handler.executeSub("Hello"
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
ChinchuAjith commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3111831375
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAdditionWithPrecedenceOrder() {
+//Basic addition operation
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+// Case 1 : STRING - If either operand is a string, convert non-string
to string
+// Left: string + other
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Date:", LocalDate.of(2024, 1, 1),
ctx)).isEqualTo("Date:2024-01-01");
+assertThat(handler.executeAdd("Duration:", Duration.ofDays(5),
ctx)).isEqualTo("Duration:PT120H");
+assertThat(handler.executeAdd("Period:", Period.ofMonths(3),
ctx)).isEqualTo("Period:P3M");
+
+// Right: other + string
+assertThat(handler.executeAdd(123, "World",
ctx)).isEqualTo("123World");
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), " is the
date", ctx)).isEqualTo("2024-01-01 is the date");
+assertThat(handler.executeAdd(Duration.ofDays(5), " duration",
ctx)).isEqualTo("PT120H duration");
+assertThat(handler.executeAdd(Period.ofMonths(3), " period",
ctx)).isEqualTo("P3M period");
+
+// Case 2 : NUMBER - If either operand is a number (and neither is
string), convert non-number to number
+// Per BFEEL Section 11.3: number(date) = 0, number(duration) =
seconds, number(period) = months
+
+// Left: date + number → 0 + number = number
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), new
BigDecimal("10.5"), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Right: number + date → number + 0 = number
+assertThat(handler.executeAdd(5, LocalDate.of(2024, 1, 1),
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(new BigDecimal("10.5"),
LocalDate.of(2024, 1, 1), ctx))
+.isEqualTo(new BigDecimal("10.5"));
Review Comment:
You were absolutely correct! Added the missing cases : Number + Duration and
Number + Period.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
ChinchuAjith commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3111828924
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAdditionWithPrecedenceOrder() {
+//Basic addition operation
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+// Case 1 : STRING - If either operand is a string, convert non-string
to string
+// Left: string + other
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Date:", LocalDate.of(2024, 1, 1),
ctx)).isEqualTo("Date:2024-01-01");
+assertThat(handler.executeAdd("Duration:", Duration.ofDays(5),
ctx)).isEqualTo("Duration:PT120H");
+assertThat(handler.executeAdd("Period:", Period.ofMonths(3),
ctx)).isEqualTo("Period:P3M");
+
+// Right: other + string
+assertThat(handler.executeAdd(123, "World",
ctx)).isEqualTo("123World");
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), " is the
date", ctx)).isEqualTo("2024-01-01 is the date");
+assertThat(handler.executeAdd(Duration.ofDays(5), " duration",
ctx)).isEqualTo("PT120H duration");
+assertThat(handler.executeAdd(Period.ofMonths(3), " period",
ctx)).isEqualTo("P3M period");
+
+// Case 2 : NUMBER - If either operand is a number (and neither is
string), convert non-number to number
+// Per BFEEL Section 11.3: number(date) = 0, number(duration) =
seconds, number(period) = months
Review Comment:
@gitgabrio The DMN specification does not define a signature for the
number() function that accepts a date type. Standard FEEL treats it as a
semantic error and returns null (find the points below),
while B-FEEL modifies this result to 0.
In standard FEEL, the number() function has a restricted domain for its
parameters.
According to Table 73 (Semantics of conversion functions), the valid
signatures for number() are:
* number(from, grouping separator, decimal separator) where from must be a
string.
* number(from) where from must be a string.
* number(from) where from must be a number.
There is no signature provided in the specification that allows a date type
as the from parameter.
Section 10.3.4 (Built-in functions) defines ”Whenever a parameter is outside
its domain, the result of the built-in is null".
This is reiterated in Section 10.3.2.13.1, which states that actual
parameters must conform to the parameter domains or the result is null.
According to Section 11.3 (Built-in functions returning a number): "Several
FEEL built-in functions return a numeric result. In B-FEEL, those functions’
semantics are modified to return 0 everywhere FEEL would return null for them".
This is the maximum we will get from spec :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For querie
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
gitgabrio commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3110791285
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -44,192 +44,240 @@ void setUp() {
handler = new BFEELDialectHandler();
ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
}
-
+
@Test
-void testAddOperations() {
-// String concatenation with type coercion
-assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
-assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
-assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
-
-// Numbers
+void testAdditionWithPrecedenceOrder() {
+//Basic addition operation
assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+// Case 1 : STRING - If either operand is a string, convert non-string
to string
+// Left: string + other
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Date:", LocalDate.of(2024, 1, 1),
ctx)).isEqualTo("Date:2024-01-01");
+assertThat(handler.executeAdd("Duration:", Duration.ofDays(5),
ctx)).isEqualTo("Duration:PT120H");
+assertThat(handler.executeAdd("Period:", Period.ofMonths(3),
ctx)).isEqualTo("Period:P3M");
-// Date operations - returns number instead of null
+// Right: other + string
+assertThat(handler.executeAdd(123, "World",
ctx)).isEqualTo("123World");
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), " is the
date", ctx)).isEqualTo("2024-01-01 is the date");
+assertThat(handler.executeAdd(Duration.ofDays(5), " duration",
ctx)).isEqualTo("PT120H duration");
+assertThat(handler.executeAdd(Period.ofMonths(3), " period",
ctx)).isEqualTo("P3M period");
+
+// Case 2 : NUMBER - If either operand is a number (and neither is
string), convert non-number to number
+// Per BFEEL Section 11.3: number(date) = 0, number(duration) =
seconds, number(period) = months
+
+// Left: date + number → 0 + number = number
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), new
BigDecimal("10.5"), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Right: number + date → number + 0 = number
+assertThat(handler.executeAdd(5, LocalDate.of(2024, 1, 1),
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(new BigDecimal("10.5"),
LocalDate.of(2024, 1, 1), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Case 3: DATE - If either operand is a date, convert non-date to
duration
+// Left: date + duration
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
.isEqualTo(LocalDate.of(2024, 1, 6));
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Period.ofMonths(2), ctx))
+.isEqualTo(LocalDate.of(2024, 3, 1));
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
}
@Test
-void testLogicalOperations() {
-// AND with boolean coercion
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
-
-// OR operations
-assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-}
-
-@Test
-void testEqualityOperations() {
-// Equal - returns false for different types (not null)
-assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
-assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+void testSubtractionWithPrecedenceOrder() {
+// Basic subtraction operation
+assertThat(handler.executeSub(20, 10, ctx)).isEqualTo(new
BigDecimal("10"));
+// Case 1: STRING - If either operand is a string, subtraction returns
empty string ""
+// Left: string - other
+assertThat(handler.executeSub("Hell
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
gitgabrio commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3110774992
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAdditionWithPrecedenceOrder() {
+//Basic addition operation
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+// Case 1 : STRING - If either operand is a string, convert non-string
to string
+// Left: string + other
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Date:", LocalDate.of(2024, 1, 1),
ctx)).isEqualTo("Date:2024-01-01");
+assertThat(handler.executeAdd("Duration:", Duration.ofDays(5),
ctx)).isEqualTo("Duration:PT120H");
+assertThat(handler.executeAdd("Period:", Period.ofMonths(3),
ctx)).isEqualTo("Period:P3M");
+
+// Right: other + string
+assertThat(handler.executeAdd(123, "World",
ctx)).isEqualTo("123World");
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), " is the
date", ctx)).isEqualTo("2024-01-01 is the date");
+assertThat(handler.executeAdd(Duration.ofDays(5), " duration",
ctx)).isEqualTo("PT120H duration");
+assertThat(handler.executeAdd(Period.ofMonths(3), " period",
ctx)).isEqualTo("P3M period");
+
+// Case 2 : NUMBER - If either operand is a number (and neither is
string), convert non-number to number
+// Per BFEEL Section 11.3: number(date) = 0, number(duration) =
seconds, number(period) = months
+
+// Left: date + number → 0 + number = number
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), new
BigDecimal("10.5"), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Right: number + date → number + 0 = number
+assertThat(handler.executeAdd(5, LocalDate.of(2024, 1, 1),
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(new BigDecimal("10.5"),
LocalDate.of(2024, 1, 1), ctx))
+.isEqualTo(new BigDecimal("10.5"));
Review Comment:
IINW there is a missing case of Number + Duration (Maybe I do not see it 😊 )
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
gitgabrio commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3110768178
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAdditionWithPrecedenceOrder() {
+//Basic addition operation
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+// Case 1 : STRING - If either operand is a string, convert non-string
to string
+// Left: string + other
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Date:", LocalDate.of(2024, 1, 1),
ctx)).isEqualTo("Date:2024-01-01");
+assertThat(handler.executeAdd("Duration:", Duration.ofDays(5),
ctx)).isEqualTo("Duration:PT120H");
+assertThat(handler.executeAdd("Period:", Period.ofMonths(3),
ctx)).isEqualTo("Period:P3M");
+
+// Right: other + string
+assertThat(handler.executeAdd(123, "World",
ctx)).isEqualTo("123World");
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), " is the
date", ctx)).isEqualTo("2024-01-01 is the date");
+assertThat(handler.executeAdd(Duration.ofDays(5), " duration",
ctx)).isEqualTo("PT120H duration");
+assertThat(handler.executeAdd(Period.ofMonths(3), " period",
ctx)).isEqualTo("P3M period");
+
+// Case 2 : NUMBER - If either operand is a number (and neither is
string), convert non-number to number
+// Per BFEEL Section 11.3: number(date) = 0, number(duration) =
seconds, number(period) = months
Review Comment:
@ChinchuAjith
Are you sure this comes from section 11.3 ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
ChinchuAjith commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3109836435
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -44,192 +44,240 @@ void setUp() {
handler = new BFEELDialectHandler();
ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
}
-
+
@Test
-void testAddOperations() {
-// String concatenation with type coercion
-assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
-assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
-assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
-
-// Numbers
+void testAdditionWithPrecedenceOrder() {
+//Basic addition operation
assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+// Case 1 : STRING - If either operand is a string, convert non-string
to string
+// Left: string + other
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Date:", LocalDate.of(2024, 1, 1),
ctx)).isEqualTo("Date:2024-01-01");
+assertThat(handler.executeAdd("Duration:", Duration.ofDays(5),
ctx)).isEqualTo("Duration:PT120H");
+assertThat(handler.executeAdd("Period:", Period.ofMonths(3),
ctx)).isEqualTo("Period:P3M");
-// Date operations - returns number instead of null
+// Right: other + string
+assertThat(handler.executeAdd(123, "World",
ctx)).isEqualTo("123World");
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), " is the
date", ctx)).isEqualTo("2024-01-01 is the date");
+assertThat(handler.executeAdd(Duration.ofDays(5), " duration",
ctx)).isEqualTo("PT120H duration");
+assertThat(handler.executeAdd(Period.ofMonths(3), " period",
ctx)).isEqualTo("P3M period");
+
+// Case 2 : NUMBER - If either operand is a number (and neither is
string), convert non-number to number
+// Per BFEEL Section 11.3: number(date) = 0, number(duration) =
seconds, number(period) = months
+
+// Left: date + number → 0 + number = number
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), new
BigDecimal("10.5"), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Right: number + date → number + 0 = number
+assertThat(handler.executeAdd(5, LocalDate.of(2024, 1, 1),
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(new BigDecimal("10.5"),
LocalDate.of(2024, 1, 1), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Case 3: DATE - If either operand is a date, convert non-date to
duration
+// Left: date + duration
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
.isEqualTo(LocalDate.of(2024, 1, 6));
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Period.ofMonths(2), ctx))
+.isEqualTo(LocalDate.of(2024, 3, 1));
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
}
@Test
-void testLogicalOperations() {
-// AND with boolean coercion
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
-
-// OR operations
-assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-}
-
-@Test
-void testEqualityOperations() {
-// Equal - returns false for different types (not null)
-assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
-assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+void testSubtractionWithPrecedenceOrder() {
+// Basic subtraction operation
+assertThat(handler.executeSub(20, 10, ctx)).isEqualTo(new
BigDecimal("10"));
+// Case 1: STRING - If either operand is a string, subtraction returns
empty string ""
+// Left: string - other
+assertThat(handler.executeSub("H
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
ChinchuAjith commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3109745110
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -44,192 +44,240 @@ void setUp() {
handler = new BFEELDialectHandler();
ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
}
-
+
@Test
-void testAddOperations() {
-// String concatenation with type coercion
-assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
-assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
-assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
-
-// Numbers
+void testAdditionWithPrecedenceOrder() {
+//Basic addition operation
assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+// Case 1 : STRING - If either operand is a string, convert non-string
to string
+// Left: string + other
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Date:", LocalDate.of(2024, 1, 1),
ctx)).isEqualTo("Date:2024-01-01");
+assertThat(handler.executeAdd("Duration:", Duration.ofDays(5),
ctx)).isEqualTo("Duration:PT120H");
+assertThat(handler.executeAdd("Period:", Period.ofMonths(3),
ctx)).isEqualTo("Period:P3M");
-// Date operations - returns number instead of null
+// Right: other + string
+assertThat(handler.executeAdd(123, "World",
ctx)).isEqualTo("123World");
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), " is the
date", ctx)).isEqualTo("2024-01-01 is the date");
+assertThat(handler.executeAdd(Duration.ofDays(5), " duration",
ctx)).isEqualTo("PT120H duration");
+assertThat(handler.executeAdd(Period.ofMonths(3), " period",
ctx)).isEqualTo("P3M period");
+
+// Case 2 : NUMBER - If either operand is a number (and neither is
string), convert non-number to number
+// Per BFEEL Section 11.3: number(date) = 0, number(duration) =
seconds, number(period) = months
+
+// Left: date + number → 0 + number = number
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), new
BigDecimal("10.5"), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Right: number + date → number + 0 = number
+assertThat(handler.executeAdd(5, LocalDate.of(2024, 1, 1),
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(new BigDecimal("10.5"),
LocalDate.of(2024, 1, 1), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Case 3: DATE - If either operand is a date, convert non-date to
duration
+// Left: date + duration
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
.isEqualTo(LocalDate.of(2024, 1, 6));
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Period.ofMonths(2), ctx))
+.isEqualTo(LocalDate.of(2024, 3, 1));
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
}
@Test
-void testLogicalOperations() {
-// AND with boolean coercion
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
-
-// OR operations
-assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-}
-
-@Test
-void testEqualityOperations() {
-// Equal - returns false for different types (not null)
-assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
-assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+void testSubtractionWithPrecedenceOrder() {
+// Basic subtraction operation
+assertThat(handler.executeSub(20, 10, ctx)).isEqualTo(new
BigDecimal("10"));
+// Case 1: STRING - If either operand is a string, subtraction returns
empty string ""
+// Left: string - other
+assertThat(handler.executeSub("H
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
gitgabrio commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3109102356
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -44,192 +44,240 @@ void setUp() {
handler = new BFEELDialectHandler();
ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
}
-
+
@Test
-void testAddOperations() {
-// String concatenation with type coercion
-assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
-assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
-assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
-
-// Numbers
+void testAdditionWithPrecedenceOrder() {
+//Basic addition operation
assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+// Case 1 : STRING - If either operand is a string, convert non-string
to string
+// Left: string + other
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Date:", LocalDate.of(2024, 1, 1),
ctx)).isEqualTo("Date:2024-01-01");
+assertThat(handler.executeAdd("Duration:", Duration.ofDays(5),
ctx)).isEqualTo("Duration:PT120H");
+assertThat(handler.executeAdd("Period:", Period.ofMonths(3),
ctx)).isEqualTo("Period:P3M");
-// Date operations - returns number instead of null
+// Right: other + string
+assertThat(handler.executeAdd(123, "World",
ctx)).isEqualTo("123World");
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), " is the
date", ctx)).isEqualTo("2024-01-01 is the date");
+assertThat(handler.executeAdd(Duration.ofDays(5), " duration",
ctx)).isEqualTo("PT120H duration");
+assertThat(handler.executeAdd(Period.ofMonths(3), " period",
ctx)).isEqualTo("P3M period");
+
+// Case 2 : NUMBER - If either operand is a number (and neither is
string), convert non-number to number
+// Per BFEEL Section 11.3: number(date) = 0, number(duration) =
seconds, number(period) = months
+
+// Left: date + number → 0 + number = number
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), new
BigDecimal("10.5"), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Right: number + date → number + 0 = number
+assertThat(handler.executeAdd(5, LocalDate.of(2024, 1, 1),
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(new BigDecimal("10.5"),
LocalDate.of(2024, 1, 1), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Case 3: DATE - If either operand is a date, convert non-date to
duration
+// Left: date + duration
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
.isEqualTo(LocalDate.of(2024, 1, 6));
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Period.ofMonths(2), ctx))
+.isEqualTo(LocalDate.of(2024, 3, 1));
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
}
@Test
-void testLogicalOperations() {
-// AND with boolean coercion
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
-
-// OR operations
-assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-}
-
-@Test
-void testEqualityOperations() {
-// Equal - returns false for different types (not null)
-assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
-assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+void testSubtractionWithPrecedenceOrder() {
+// Basic subtraction operation
+assertThat(handler.executeSub(20, 10, ctx)).isEqualTo(new
BigDecimal("10"));
+// Case 1: STRING - If either operand is a string, subtraction returns
empty string ""
+// Left: string - other
+assertThat(handler.executeSub("Hell
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
gitgabrio commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3109102356
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -44,192 +44,240 @@ void setUp() {
handler = new BFEELDialectHandler();
ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
}
-
+
@Test
-void testAddOperations() {
-// String concatenation with type coercion
-assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
-assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
-assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
-
-// Numbers
+void testAdditionWithPrecedenceOrder() {
+//Basic addition operation
assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+// Case 1 : STRING - If either operand is a string, convert non-string
to string
+// Left: string + other
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Date:", LocalDate.of(2024, 1, 1),
ctx)).isEqualTo("Date:2024-01-01");
+assertThat(handler.executeAdd("Duration:", Duration.ofDays(5),
ctx)).isEqualTo("Duration:PT120H");
+assertThat(handler.executeAdd("Period:", Period.ofMonths(3),
ctx)).isEqualTo("Period:P3M");
-// Date operations - returns number instead of null
+// Right: other + string
+assertThat(handler.executeAdd(123, "World",
ctx)).isEqualTo("123World");
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), " is the
date", ctx)).isEqualTo("2024-01-01 is the date");
+assertThat(handler.executeAdd(Duration.ofDays(5), " duration",
ctx)).isEqualTo("PT120H duration");
+assertThat(handler.executeAdd(Period.ofMonths(3), " period",
ctx)).isEqualTo("P3M period");
+
+// Case 2 : NUMBER - If either operand is a number (and neither is
string), convert non-number to number
+// Per BFEEL Section 11.3: number(date) = 0, number(duration) =
seconds, number(period) = months
+
+// Left: date + number → 0 + number = number
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), new
BigDecimal("10.5"), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Right: number + date → number + 0 = number
+assertThat(handler.executeAdd(5, LocalDate.of(2024, 1, 1),
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(new BigDecimal("10.5"),
LocalDate.of(2024, 1, 1), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Case 3: DATE - If either operand is a date, convert non-date to
duration
+// Left: date + duration
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
.isEqualTo(LocalDate.of(2024, 1, 6));
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Period.ofMonths(2), ctx))
+.isEqualTo(LocalDate.of(2024, 3, 1));
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
}
@Test
-void testLogicalOperations() {
-// AND with boolean coercion
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
-
-// OR operations
-assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-}
-
-@Test
-void testEqualityOperations() {
-// Equal - returns false for different types (not null)
-assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
-assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+void testSubtractionWithPrecedenceOrder() {
+// Basic subtraction operation
+assertThat(handler.executeSub(20, 10, ctx)).isEqualTo(new
BigDecimal("10"));
+// Case 1: STRING - If either operand is a string, subtraction returns
empty string ""
+// Left: string - other
+assertThat(handler.executeSub("Hell
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
gitgabrio commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3109087451
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -44,192 +44,240 @@ void setUp() {
handler = new BFEELDialectHandler();
ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
}
-
+
@Test
-void testAddOperations() {
-// String concatenation with type coercion
-assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
-assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
-assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
-
-// Numbers
+void testAdditionWithPrecedenceOrder() {
+//Basic addition operation
assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+// Case 1 : STRING - If either operand is a string, convert non-string
to string
+// Left: string + other
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Date:", LocalDate.of(2024, 1, 1),
ctx)).isEqualTo("Date:2024-01-01");
+assertThat(handler.executeAdd("Duration:", Duration.ofDays(5),
ctx)).isEqualTo("Duration:PT120H");
+assertThat(handler.executeAdd("Period:", Period.ofMonths(3),
ctx)).isEqualTo("Period:P3M");
-// Date operations - returns number instead of null
+// Right: other + string
+assertThat(handler.executeAdd(123, "World",
ctx)).isEqualTo("123World");
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), " is the
date", ctx)).isEqualTo("2024-01-01 is the date");
+assertThat(handler.executeAdd(Duration.ofDays(5), " duration",
ctx)).isEqualTo("PT120H duration");
+assertThat(handler.executeAdd(Period.ofMonths(3), " period",
ctx)).isEqualTo("P3M period");
+
+// Case 2 : NUMBER - If either operand is a number (and neither is
string), convert non-number to number
+// Per BFEEL Section 11.3: number(date) = 0, number(duration) =
seconds, number(period) = months
+
+// Left: date + number → 0 + number = number
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), new
BigDecimal("10.5"), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Right: number + date → number + 0 = number
+assertThat(handler.executeAdd(5, LocalDate.of(2024, 1, 1),
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(new BigDecimal("10.5"),
LocalDate.of(2024, 1, 1), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Case 3: DATE - If either operand is a date, convert non-date to
duration
+// Left: date + duration
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
.isEqualTo(LocalDate.of(2024, 1, 6));
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Period.ofMonths(2), ctx))
+.isEqualTo(LocalDate.of(2024, 3, 1));
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
}
@Test
-void testLogicalOperations() {
-// AND with boolean coercion
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
-
-// OR operations
-assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-}
-
-@Test
-void testEqualityOperations() {
-// Equal - returns false for different types (not null)
-assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
-assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+void testSubtractionWithPrecedenceOrder() {
+// Basic subtraction operation
+assertThat(handler.executeSub(20, 10, ctx)).isEqualTo(new
BigDecimal("10"));
+// Case 1: STRING - If either operand is a string, subtraction returns
empty string ""
+// Left: string - other
+assertThat(handler.executeSub("Hell
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
gitgabrio commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3109076312
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -44,192 +44,240 @@ void setUp() {
handler = new BFEELDialectHandler();
ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
}
-
+
@Test
-void testAddOperations() {
-// String concatenation with type coercion
-assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
-assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
-assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
-
-// Numbers
+void testAdditionWithPrecedenceOrder() {
+//Basic addition operation
assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+// Case 1 : STRING - If either operand is a string, convert non-string
to string
+// Left: string + other
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Date:", LocalDate.of(2024, 1, 1),
ctx)).isEqualTo("Date:2024-01-01");
+assertThat(handler.executeAdd("Duration:", Duration.ofDays(5),
ctx)).isEqualTo("Duration:PT120H");
+assertThat(handler.executeAdd("Period:", Period.ofMonths(3),
ctx)).isEqualTo("Period:P3M");
-// Date operations - returns number instead of null
+// Right: other + string
+assertThat(handler.executeAdd(123, "World",
ctx)).isEqualTo("123World");
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), " is the
date", ctx)).isEqualTo("2024-01-01 is the date");
+assertThat(handler.executeAdd(Duration.ofDays(5), " duration",
ctx)).isEqualTo("PT120H duration");
+assertThat(handler.executeAdd(Period.ofMonths(3), " period",
ctx)).isEqualTo("P3M period");
+
+// Case 2 : NUMBER - If either operand is a number (and neither is
string), convert non-number to number
+// Per BFEEL Section 11.3: number(date) = 0, number(duration) =
seconds, number(period) = months
+
+// Left: date + number → 0 + number = number
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), new
BigDecimal("10.5"), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Right: number + date → number + 0 = number
+assertThat(handler.executeAdd(5, LocalDate.of(2024, 1, 1),
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(new BigDecimal("10.5"),
LocalDate.of(2024, 1, 1), ctx))
+.isEqualTo(new BigDecimal("10.5"));
+
+// Case 3: DATE - If either operand is a date, convert non-date to
duration
+// Left: date + duration
assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
.isEqualTo(LocalDate.of(2024, 1, 6));
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Period.ofMonths(2), ctx))
+.isEqualTo(LocalDate.of(2024, 3, 1));
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
}
@Test
-void testLogicalOperations() {
-// AND with boolean coercion
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
-
-// OR operations
-assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
-}
-
-@Test
-void testEqualityOperations() {
-// Equal - returns false for different types (not null)
-assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
-assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
-assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
-assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+void testSubtractionWithPrecedenceOrder() {
+// Basic subtraction operation
+assertThat(handler.executeSub(20, 10, ctx)).isEqualTo(new
BigDecimal("10"));
+// Case 1: STRING - If either operand is a string, subtraction returns
empty string ""
+// Left: string - other
+assertThat(handler.executeSub("Hell
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
ChinchuAjith commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3108562016
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAddOperations() {
+// String concatenation with type coercion
+assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
+
+// Numbers
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+
+// Date operations - returns number instead of null
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
Review Comment:
i have arranged the tests in the order of the rows specified in the table.
Please check
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
ChinchuAjith commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3108558440
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAddOperations() {
+// String concatenation with type coercion
+assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
+
+// Numbers
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+
+// Date operations - returns number instead of null
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
+.isEqualTo(LocalDate.of(2024, 1, 6));
+}
+
+@Test
+void testLogicalOperations() {
+// AND with boolean coercion
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
+
+// OR operations
+assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testEqualityOperations() {
+// Equal - returns false for different types (not null)
+assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
+assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+
+// Not Equal
+assertThat(handler.executeNotEqual(null, null,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeNotEqual(10, 20,
ctx)).isEqualTo(Boolean.TRUE);
+}
+
+@Test
+void testComparisonOperations() {
+// BFEEL returns false for invalid comparisons (not null)
+assertThat(handler.executeGte(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeGte(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", 10,
ctx)).isEqualTo(Boolean.FALSE); // Incomparable
+
+assertThat(handler.executeGt(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLte(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLt(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testAr
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
ChinchuAjith commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3108557027
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAddOperations() {
+// String concatenation with type coercion
+assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
+
+// Numbers
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+
+// Date operations - returns number instead of null
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
+.isEqualTo(LocalDate.of(2024, 1, 6));
+}
+
+@Test
+void testLogicalOperations() {
+// AND with boolean coercion
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
+
+// OR operations
+assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testEqualityOperations() {
+// Equal - returns false for different types (not null)
+assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
+assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+
+// Not Equal
+assertThat(handler.executeNotEqual(null, null,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeNotEqual(10, 20,
ctx)).isEqualTo(Boolean.TRUE);
+}
+
+@Test
+void testComparisonOperations() {
+// BFEEL returns false for invalid comparisons (not null)
+assertThat(handler.executeGte(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeGte(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", 10,
ctx)).isEqualTo(Boolean.FALSE); // Incomparable
+
+assertThat(handler.executeGt(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLte(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLt(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testAr
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
ChinchuAjith commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3108333512
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAddOperations() {
+// String concatenation with type coercion
+assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
+
+// Numbers
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+
+// Date operations - returns number instead of null
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
Review Comment:
I understand the concern @gitgabrio Based on the further analysis, this is
the implementation we are doing currently
Reordered and corrected the addition operations in getAddOperations() method
to comply with BFEEL Section 11.9 specification:
**Key Fix: Number operations now take precedence over string concatenation,
following the BFEEL Table 11.9 precedence rules.**
**Precedence:**
1. Date + Number operations → Returns the number
* BFEEL Section 11.9, when one operand is a number, the non-number value
(date) is converted to a number using the number() function
* In BFEEL, number(date) returns 0 (per Section 11.3)
* Therefore: 0 + 5 = 5, so we return the number operand
2. Number + Date operations → Returns the number
* Same logic: 5 + 0 = 5, so we return the number operand
3. Number + null operations → Returns the number
4. null + Number operations → Returns the number
5. String concatenation → Only applies when no number operands are present
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
gitgabrio commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3098871510
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAddOperations() {
+// String concatenation with type coercion
+assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
+
+// Numbers
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+
+// Date operations - returns number instead of null
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
+.isEqualTo(LocalDate.of(2024, 1, 6));
+}
+
+@Test
+void testLogicalOperations() {
+// AND with boolean coercion
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
+
+// OR operations
+assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testEqualityOperations() {
+// Equal - returns false for different types (not null)
+assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
+assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+
+// Not Equal
+assertThat(handler.executeNotEqual(null, null,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeNotEqual(10, 20,
ctx)).isEqualTo(Boolean.TRUE);
+}
+
+@Test
+void testComparisonOperations() {
+// BFEEL returns false for invalid comparisons (not null)
+assertThat(handler.executeGte(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeGte(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", 10,
ctx)).isEqualTo(Boolean.FALSE); // Incomparable
+
+assertThat(handler.executeGt(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLte(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLt(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testArith
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
gitgabrio commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3098884687
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAddOperations() {
+// String concatenation with type coercion
+assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
+
+// Numbers
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+
+// Date operations - returns number instead of null
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
+.isEqualTo(LocalDate.of(2024, 1, 6));
+}
+
+@Test
+void testLogicalOperations() {
+// AND with boolean coercion
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
+
+// OR operations
+assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testEqualityOperations() {
+// Equal - returns false for different types (not null)
+assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
+assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+
+// Not Equal
+assertThat(handler.executeNotEqual(null, null,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeNotEqual(10, 20,
ctx)).isEqualTo(Boolean.TRUE);
+}
+
+@Test
+void testComparisonOperations() {
+// BFEEL returns false for invalid comparisons (not null)
+assertThat(handler.executeGte(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeGte(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", 10,
ctx)).isEqualTo(Boolean.FALSE); // Incomparable
+
+assertThat(handler.executeGt(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLte(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLt(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testArith
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
gitgabrio commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3098871510
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAddOperations() {
+// String concatenation with type coercion
+assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
+
+// Numbers
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+
+// Date operations - returns number instead of null
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
+.isEqualTo(LocalDate.of(2024, 1, 6));
+}
+
+@Test
+void testLogicalOperations() {
+// AND with boolean coercion
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
+
+// OR operations
+assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testEqualityOperations() {
+// Equal - returns false for different types (not null)
+assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
+assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+
+// Not Equal
+assertThat(handler.executeNotEqual(null, null,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeNotEqual(10, 20,
ctx)).isEqualTo(Boolean.TRUE);
+}
+
+@Test
+void testComparisonOperations() {
+// BFEEL returns false for invalid comparisons (not null)
+assertThat(handler.executeGte(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeGte(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", 10,
ctx)).isEqualTo(Boolean.FALSE); // Incomparable
+
+assertThat(handler.executeGt(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLte(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLt(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testArith
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
gitgabrio commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3098869386
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAddOperations() {
+// String concatenation with type coercion
+assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
+
+// Numbers
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+
+// Date operations - returns number instead of null
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
Review Comment:
@yesamer @ChinchuAjith
This is very tricky. I think you are right with that, but we need to double
check everyone.
My interpretation is:
1. normal FEEL defines valid addiction/subtraction with Table 58
2. for BFEEL, we have to "extend" this table for invalid cases, with the
Table at 11.9
3. the order of the rows in that latter take precedence, so if there is a
number, everything has to be considered a number.
But, please, double check yourself.
@ChinchuAjith would it be possible to create a test for each row in that
latter table , with parameters at both left and right side ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
ChinchuAjith commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3098297314
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAddOperations() {
+// String concatenation with type coercion
+assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
+
+// Numbers
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+
+// Date operations - returns number instead of null
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
+.isEqualTo(LocalDate.of(2024, 1, 6));
+}
+
+@Test
+void testLogicalOperations() {
+// AND with boolean coercion
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
+
+// OR operations
+assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testEqualityOperations() {
+// Equal - returns false for different types (not null)
+assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
+assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+
+// Not Equal
+assertThat(handler.executeNotEqual(null, null,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeNotEqual(10, 20,
ctx)).isEqualTo(Boolean.TRUE);
+}
+
+@Test
+void testComparisonOperations() {
+// BFEEL returns false for invalid comparisons (not null)
+assertThat(handler.executeGte(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeGte(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", 10,
ctx)).isEqualTo(Boolean.FALSE); // Incomparable
+
+assertThat(handler.executeGt(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLte(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLt(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testAr
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
gitgabrio commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3092327923
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAddOperations() {
+// String concatenation with type coercion
+assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
+
+// Numbers
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+
+// Date operations - returns number instead of null
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
+.isEqualTo(LocalDate.of(2024, 1, 6));
+}
+
+@Test
+void testLogicalOperations() {
+// AND with boolean coercion
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
+
+// OR operations
+assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testEqualityOperations() {
+// Equal - returns false for different types (not null)
+assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
+assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+
+// Not Equal
+assertThat(handler.executeNotEqual(null, null,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeNotEqual(10, 20,
ctx)).isEqualTo(Boolean.TRUE);
+}
+
+@Test
+void testComparisonOperations() {
+// BFEEL returns false for invalid comparisons (not null)
+assertThat(handler.executeGte(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeGte(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", 10,
ctx)).isEqualTo(Boolean.FALSE); // Incomparable
+
+assertThat(handler.executeGt(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLte(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLt(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testArith
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
ChinchuAjith commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3092262265
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAddOperations() {
+// String concatenation with type coercion
+assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
+
+// Numbers
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+
+// Date operations - returns number instead of null
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
+.isEqualTo(LocalDate.of(2024, 1, 6));
+}
+
+@Test
+void testLogicalOperations() {
+// AND with boolean coercion
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
+
+// OR operations
+assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testEqualityOperations() {
+// Equal - returns false for different types (not null)
+assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
+assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+
+// Not Equal
+assertThat(handler.executeNotEqual(null, null,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeNotEqual(10, 20,
ctx)).isEqualTo(Boolean.TRUE);
+}
+
+@Test
+void testComparisonOperations() {
+// BFEEL returns false for invalid comparisons (not null)
+assertThat(handler.executeGte(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeGte(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", 10,
ctx)).isEqualTo(Boolean.FALSE); // Incomparable
+
+assertThat(handler.executeGt(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLte(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLt(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testAr
Re: [PR] [incubator-kie-issues#2174]Unit test cases for Dialect Handler classes [incubator-kie-drools]
gitgabrio commented on code in PR #6632:
URL:
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3021312814
##
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns
default values
+ */
+class BFEELDialectHandlerTest {
+
+private BFEELDialectHandler handler;
+private EvaluationContext ctx;
+
+@BeforeEach
+void setUp() {
+handler = new BFEELDialectHandler();
+ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+}
+
+@Test
+void testAddOperations() {
+// String concatenation with type coercion
+assertThat(handler.executeAdd("Hello", "World",
ctx)).isEqualTo("HelloWorld");
+assertThat(handler.executeAdd("Hello", 123,
ctx)).isEqualTo("Hello123");
+assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello");
+
+// Numbers
+assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new
BigDecimal("30"));
+assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10);
+
+// Date operations - returns number instead of null
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5,
ctx)).isEqualTo(5);
+assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1),
Duration.ofDays(5), ctx))
+.isEqualTo(LocalDate.of(2024, 1, 6));
+}
+
+@Test
+void testLogicalOperations() {
+// AND with boolean coercion
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeAnd(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeAnd("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.FALSE); // Non-boolean coerced to false
+
+// OR operations
+assertThat(handler.executeOr(Boolean.TRUE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeOr(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testEqualityOperations() {
+// Equal - returns false for different types (not null)
+assertThat(handler.executeEqual(null, null,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 10, ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeEqual(10, 20, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeEqual("10", 10,
ctx)).isEqualTo(Boolean.FALSE); // Different types
+assertThat(handler.executeEqual(null, 10,
ctx)).isEqualTo(Boolean.FALSE);
+
+// Not Equal
+assertThat(handler.executeNotEqual(null, null,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeNotEqual(10, 20,
ctx)).isEqualTo(Boolean.TRUE);
+}
+
+@Test
+void testComparisonOperations() {
+// BFEEL returns false for invalid comparisons (not null)
+assertThat(handler.executeGte(Boolean.FALSE, Boolean.FALSE,
ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", Boolean.TRUE,
ctx)).isEqualTo(Boolean.TRUE);
+assertThat(handler.executeGte(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeGte("test", 10,
ctx)).isEqualTo(Boolean.FALSE); // Incomparable
+
+assertThat(handler.executeGt(20, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLte(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+assertThat(handler.executeLt(5, 10, ctx)).isEqualTo(Boolean.FALSE);
+}
+
+@Test
+void testArith
