tkobayas commented on code in PR #6186: URL: https://github.com/apache/incubator-kie-drools/pull/6186#discussion_r1877745223
########## drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/AccumulateTest.java: ########## @@ -3941,4 +3943,156 @@ public void testPeerCollectWithEager(KieBaseTestConfiguration kieBaseTestConfigu kieSession.dispose(); } } + + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + void minWithBigDecimalHighAccuracy(KieBaseTestConfiguration kieBaseTestConfiguration) { + final String drl = + "import " + Primitives.class.getCanonicalName() + ";\n" + + "global java.util.List results;\n" + + "rule R1 when\n" + + " accumulate(Primitives($bd : bigDecimal), $min : min($bd))\n" + + "then\n" + + " results.add($min);\n" + + // to confirm if $min is BigDecimal at build time (Not Comparable) + // The return value isn't important to assert + " System.out.println($min.scale());\n" + + "end"; + + final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("accumulate-test", kieBaseTestConfiguration, drl); + final KieSession kieSession = kieBase.newKieSession(); + try { + List<BigDecimal> results = new ArrayList<>(); + kieSession.setGlobal("results", results); + Primitives p1 = new Primitives(); + p1.setBigDecimal(new BigDecimal("2024043020240501130000")); + Primitives p2_smallest = new Primitives(); + p2_smallest.setBigDecimal(new BigDecimal("2024043020240501120000")); + Primitives p3 = new Primitives(); + p3.setBigDecimal(new BigDecimal("2024043020240501150000")); + + kieSession.insert(p1); + kieSession.insert(p2_smallest); + kieSession.insert(p3); + kieSession.fireAllRules(); + assertThat(results).hasSize(1); + assertThat(results.get(0)).isEqualTo(p2_smallest.getBigDecimal()); + } finally { + kieSession.dispose(); + } + } + + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + void minWithBigIntegerHighAccuracy(KieBaseTestConfiguration kieBaseTestConfiguration) { + final String drl = + "import " + Primitives.class.getCanonicalName() + ";\n" + + "global java.util.List results;\n" + + "rule R1 when\n" + + " accumulate(Primitives($bi : bigInteger), $min : min($bi))\n" + + "then\n" + + " results.add($min);\n" + + // to confirm if $min is BigInteger at build time (Not Comparable) + // The return value isn't important to assert + " System.out.println($min.nextProbablePrime());\n" + Review Comment: `nextProbablePrime()` is specific to `BigInteger` class. So, this line is to check that drl build doesn't raise a compile error, so we can confirm that `$min` is treated as `BigInteger` in the internally generated java code. The return value of `nextProbablePrime()` is not guaranteed, so we cannot assert the value. Having said that, I can avoid `System.out.println` anyway. I'll fix the PR. Thanks. -- 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: commits-unsubscr...@kie.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@kie.apache.org For additional commands, e-mail: commits-h...@kie.apache.org