From f06fabeed03ea7f8949ec1d8a7d70a1013b74315 Mon Sep 17 00:00:00 2001 From: Anton Vasetenkov Date: Fri, 2 Aug 2024 10:51:29 +1200 Subject: [PATCH] Remove duplicate tests for aggregate functions, aggregate queries, and arithmetic functions (#1396) * Remove duplicate aggregate function tests * Remove duplicate aggregate query tests * Remove duplicate arithmetic function tests --------- Co-authored-by: JP --- .../cql/CqlAggregateFunctionsTest.xml | 46 + .../org/hl7/fhirpath/cql/CqlAggregateTest.xml | 101 ++- .../cql/CqlArithmeticFunctionsTest.xml | 72 ++ .../execution/CqlAggregateFunctionsTest.java | 167 +--- .../execution/CqlAggregateQueryTest.java | 33 - .../execution/CqlArithmeticFunctionsTest.java | 812 +----------------- .../execution/CqlAggregateFunctionsTest.cql | 78 -- .../execution/CqlAggregateQueryTest.cql | 45 - .../execution/CqlArithmeticFunctionsTest.cql | 253 ------ 9 files changed, 201 insertions(+), 1406 deletions(-) delete mode 100644 Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlAggregateQueryTest.java delete mode 100644 Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlAggregateFunctionsTest.cql delete mode 100644 Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlAggregateQueryTest.cql delete mode 100644 Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlArithmeticFunctionsTest.cql diff --git a/Src/java/engine-fhir/src/test/resources/org/hl7/fhirpath/cql/CqlAggregateFunctionsTest.xml b/Src/java/engine-fhir/src/test/resources/org/hl7/fhirpath/cql/CqlAggregateFunctionsTest.xml index f1489afd8..7298d6b13 100644 --- a/Src/java/engine-fhir/src/test/resources/org/hl7/fhirpath/cql/CqlAggregateFunctionsTest.xml +++ b/Src/java/engine-fhir/src/test/resources/org/hl7/fhirpath/cql/CqlAggregateFunctionsTest.xml @@ -30,6 +30,10 @@ AllTrue({}) true + + AllTrue(null) + true + @@ -68,6 +72,10 @@ AnyTrue({}) false + + AnyTrue(null) + false + @@ -75,6 +83,12 @@ 3.0 + + + Product({5L, 4L, 5L}) + 100L + + Count({ 15, 5, 99, null, 1 }) @@ -98,6 +112,10 @@ Max({ 5, 12, 1, 15, 0, 4, 90, 44 }) 90 + + Max({ 5L, 12L, 1L, 15L, 0L, 4L, 90L, 44L }) + 90L + Max({ 'hi', 'bye', 'zebra' }) 'zebra' @@ -122,6 +140,10 @@ Min({5, 12, 1, 15, 0, 4, 90, 44}) 0 + + Min({5L, 12L, 1L, 15L, 0L, 4L, 90L, 44L}) + 0L + Min({'hi', 'bye', 'zebra'}) 'bye' @@ -144,6 +166,10 @@ Mode({ DateTime(2012, 10, 5), DateTime(2012, 9, 5), DateTime(2012, 10, 6), DateTime(2012, 9, 5) }) DateTime(2012, 9, 5) + + Mode({ DateTime(2012, 10, 5), DateTime(2012, 10, 5), DateTime(2012, 10, 6), DateTime(2012, 9, 5) }) + DateTime(2012, 10, 5) + Mode({ @T15:59:59.999, @T05:59:59.999, @T20:59:59.999, @T05:59:59.999 }) @T05:59:59.999 @@ -155,12 +181,20 @@ 1.41421356 + + PopulationStdDev({ null as Quantity, null as Quantity, null as Quantity }) + null + PopulationVariance({ 1.0, 2.0, 3.0, 4.0, 5.0 }) 2.0 + + PopulationVariance({ null as Quantity, null as Quantity, null as Quantity }) + null + @@ -168,12 +202,24 @@ 1.58113883 + + StdDev({ null as Quantity, null as Quantity, null as Quantity }) + null + Sum({ 6.0, 2.0, 3.0, 4.0, 5.0 }) 20.0 + + Sum({ 6L, 2L, 3L, 4L, 5L }) + 20L + + + Sum({1 'ml',2 'ml',3 'ml',4 'ml',5 'ml'}) + 15 'ml' + Sum({ null, 1, null }) 1 diff --git a/Src/java/engine-fhir/src/test/resources/org/hl7/fhirpath/cql/CqlAggregateTest.xml b/Src/java/engine-fhir/src/test/resources/org/hl7/fhirpath/cql/CqlAggregateTest.xml index 2a6ee6738..ac51c750e 100644 --- a/Src/java/engine-fhir/src/test/resources/org/hl7/fhirpath/cql/CqlAggregateTest.xml +++ b/Src/java/engine-fhir/src/test/resources/org/hl7/fhirpath/cql/CqlAggregateTest.xml @@ -1,29 +1,88 @@ + name="CqlAggregateTest" reference="http://build.fhir.org/ig/HL7/cql/03-developersguide.html#aggregate-queries"> ({ 1, 2, 3, 4, 5 }) Num aggregate Result starting 1: Result * Num 120 - - ({ - Interval[@2012-01-01, @2012-02-28], - Interval[@2012-02-01, @2012-03-31], - Interval[@2012-03-01, @2012-04-30] -}) M - aggregate R starting (null as List<Interval<DateTime>>): R union ({ - M X - let S: Max({ end of Last(R) + 1 day, start of X }), - E: S + duration in days of X - return Interval[S, E] - }) - { - Interval[@2012-01-01, @2012-02-28], - Interval[@2012-02-29, @2012-04-28], - Interval[@2012-04-29, @2012-06-28] -} - - - + + + ({ + Interval[@2012-01-01, @2012-02-28], + Interval[@2012-02-01, @2012-03-31], + Interval[@2012-03-01, @2012-04-30] + }) M + aggregate R starting (null as List<Interval<DateTime>>): R union ({ + M X + let S: Max({ end of Last(R) + 1 day, start of X }), + E: S + duration in days of X + return Interval[S, E] + }) + + + { + Interval[@2012-01-01, @2012-02-28], + Interval[@2012-02-29, @2012-04-28], + Interval[@2012-04-29, @2012-06-28] + } + + + + + + ({ 1, 2, 3, 4, 5 }) Num + aggregate Result starting 1: Result + Num + + 16 + + + + + ({ 1, 2, 3, 4, 5 }) Num + aggregate Result: Coalesce(Result, 0) + Num + + 15 + + + + + ({ 1, 1, 2, 2, 2, 3, 4, 4, 5 }) Num + aggregate all Result: Coalesce(Result, 0) + Num + + 24 + + + + + ({ 1, 1, 2, 2, 2, 3, 4, 4, 5 }) Num + aggregate distinct Result: Coalesce(Result, 0) + Num + + 15 + + + + + from ({1}) X, ({2}) Y, ({3}) Z + aggregate Agg: Coalesce(Agg, 0) + X + Y + Z + + 6 + + + + from ({1, 2}) X, ({1, 2}) Y, ({1, 2}) Z + aggregate Agg starting 0: Agg + X + Y + Z + + 36 + + + + + from ({1, 2, 2, 1}) X, ({1, 2, 1, 2}) Y, ({2, 1, 2, 1}) Z + aggregate distinct Agg starting 1: Agg + X + Y + Z + + 37 + + + diff --git a/Src/java/engine-fhir/src/test/resources/org/hl7/fhirpath/cql/CqlArithmeticFunctionsTest.xml b/Src/java/engine-fhir/src/test/resources/org/hl7/fhirpath/cql/CqlArithmeticFunctionsTest.xml index a667d780e..e609a4d7e 100644 --- a/Src/java/engine-fhir/src/test/resources/org/hl7/fhirpath/cql/CqlArithmeticFunctionsTest.xml +++ b/Src/java/engine-fhir/src/test/resources/org/hl7/fhirpath/cql/CqlArithmeticFunctionsTest.xml @@ -40,6 +40,10 @@ 1 + 1 2 + + 1L + 2L + 3L + 1.0 + 1.0 2.0 @@ -104,6 +108,10 @@ 1 / 1 1.0 + + 1L / 1L + 1.0 + 1.0 / 1.0 1.0 @@ -195,6 +203,10 @@ Round(Exp(1), 8) 2.71828183 + + Round(Exp(1L), 8) + 2.71828183 + Round(Exp(-1), 8) 0.36787944 @@ -225,6 +237,14 @@ HighBoundary(@T10:30, 9) @T10:30:59.999 + + HighBoundary(null as Decimal, 8) + null + + + HighBoundary(1.58888, null) + 1.58888999 + @@ -251,6 +271,10 @@ Log(1, 100) 0.0 + + Log(1L, 100L) + 0.0 + Log(16, 2) 4.0 @@ -277,6 +301,14 @@ LowBoundary(@T10:30, 9) @T10:30:00.000 + + LowBoundary(null as Decimal, 8) + null + + + LowBoundary(1.58888, null) + 1.58888000 + @@ -295,6 +327,10 @@ Ln(1) 0.0 + + Ln(1L) + 0.0 + Ln(-1) null @@ -404,6 +440,14 @@ 3.5 'cm' mod 3 'cm' 0.5 'cm' + + 10.0 'g' mod 3.0 'g' + 1.0 'g' + + + 10.0 'g' mod 0.0 'g' + null + @@ -414,6 +458,10 @@ 1 * 1 1 + + 2L * 3L + 6L + 1.0 * 2.0 2.0 @@ -449,6 +497,14 @@ -1 -1 + + -1L + -1L + + + -9223372036854775807L + -9223372036854775807L + -(-1) 1 @@ -595,6 +651,10 @@ 2^4 16 + + 2L^3L + 8L + 2.0^4.0 16.0 @@ -833,5 +893,17 @@ 10.1 'cm' div -3.1 'cm' -3.0 'cm' + + 10.0 'g' div 5.0 'g' + 2.0 'g' + + + 4.14 'm' div 2.06 'm' + 2.0 'm' + + + 10.0 'g' div 0.0 'g' + null + diff --git a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlAggregateFunctionsTest.java b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlAggregateFunctionsTest.java index 233a60b32..0b8156688 100644 --- a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlAggregateFunctionsTest.java +++ b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlAggregateFunctionsTest.java @@ -1,81 +1,18 @@ package org.opencds.cqf.cql.engine.execution; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; import static org.junit.jupiter.api.Assertions.*; -import java.math.BigDecimal; import java.util.Arrays; import org.junit.jupiter.api.Test; import org.opencds.cqf.cql.engine.elm.executing.AnyTrueEvaluator; import org.opencds.cqf.cql.engine.elm.executing.AvgEvaluator; -import org.opencds.cqf.cql.engine.elm.executing.EquivalentEvaluator; import org.opencds.cqf.cql.engine.exception.InvalidOperatorArgument; -import org.opencds.cqf.cql.engine.runtime.DateTime; -import org.opencds.cqf.cql.engine.runtime.Quantity; -import org.opencds.cqf.cql.engine.runtime.Time; class CqlAggregateFunctionsTest extends CqlTestBase { @Test void all_aggregate_function_tests() { - final BigDecimal bigDecimalZoneOffset = getBigDecimalZoneOffset(); - - var results = engine.evaluate(toElmIdentifier("CqlAggregateFunctionsTest")); - Object value = results.forExpression("AllTrueAllTrue").value(); - assertThat(value, is(true)); - - value = results.forExpression("AllTrueTrueFirst").value(); - assertThat(value, is(false)); - - value = results.forExpression("AllTrueFalseFirst").value(); - assertThat(value, is(false)); - - value = results.forExpression("AllTrueAllTrueFalseTrue").value(); - assertThat(value, is(false)); - - value = results.forExpression("AllTrueAllFalseTrueFalse").value(); - assertThat(value, is(false)); - - value = results.forExpression("AllTrueNullFirst").value(); - assertThat(value, is(true)); - - value = results.forExpression("AllTrueEmptyList").value(); - assertThat(value, is(true)); - - value = results.forExpression("AllTrueIsTrueWhenNull").value(); - assertThat(value, is(true)); - - value = results.forExpression("AnyTrueAllTrue").value(); - assertThat(value, is(true)); - - value = results.forExpression("AnyTrueAllFalse").value(); - assertThat(value, is(false)); - - value = results.forExpression("AnyTrueAllTrueFalseTrue").value(); - assertThat(value, is(true)); - - value = results.forExpression("AnyTrueAllFalseTrueFalse").value(); - assertThat(value, is(true)); - - value = results.forExpression("AnyTrueTrueFirst").value(); - assertThat(value, is(true)); - - value = results.forExpression("AnyTrueFalseFirst").value(); - assertThat(value, is(true)); - - value = results.forExpression("AnyTrueNullFirstThenTrue").value(); - assertThat(value, is(true)); - - value = results.forExpression("AnyTrueNullFirstThenFalse").value(); - assertThat(value, is(false)); - - value = results.forExpression("AnyTrueEmptyList").value(); - assertThat(value, is(false)); - - value = results.forExpression("AnyTrueIsFalseWhenNull").value(); - assertThat(value, is(false)); + Object value; try { value = AnyTrueEvaluator.anyTrue(Arrays.asList("this", "is", "error")); @@ -90,107 +27,5 @@ void all_aggregate_function_tests() { } catch (InvalidOperatorArgument e) { // pass } - - value = results.forExpression("AvgTest1").value(); - assertThat(value, is(new BigDecimal("3.0"))); - - value = results.expressionResults.get("Product_Long").value(); - assertThat(value, is(100L)); - - value = results.forExpression("CountTest1").value(); - assertThat(value, is(4)); - - value = results.forExpression("CountTestDateTime").value(); - assertThat(value, is(3)); - - value = results.forExpression("CountTestTime").value(); - assertThat(value, is(3)); - - value = results.forExpression("CountTestNull").value(); - assertThat(value, is(0)); - - value = results.forExpression("MaxTestInteger").value(); - assertThat(value, is(90)); - - value = results.forExpression("MaxTestLong").value(); - assertThat(value, is(90L)); - - value = results.forExpression("MaxTestString").value(); - assertThat(value, is("zebra")); - - value = results.forExpression("MaxTestDateTime").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new DateTime(bigDecimalZoneOffset, 2012, 10, 6))); - - value = results.forExpression("MaxTestTime").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new Time(20, 59, 59, 999))); - - value = results.forExpression("MedianTestDecimal").value(); - assertThat(value, is(new BigDecimal("3.5"))); - - value = results.forExpression("MinTestInteger").value(); - assertThat(value, is(0)); - - value = results.forExpression("MinTestLong").value(); - assertThat(value, is(0L)); - - value = results.forExpression("MinTestString").value(); - assertThat(value, is("bye")); - - value = results.forExpression("MinTestDateTime").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new DateTime(bigDecimalZoneOffset, 2012, 9, 5))); - - value = results.forExpression("MinTestTime").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new Time(5, 59, 59, 999))); - - value = results.forExpression("ModeTestInteger").value(); - assertThat(value, is(9)); - value = results.forExpression("ModeTestDateTime2").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new DateTime(bigDecimalZoneOffset, 2012, 10, 5))); - - value = results.forExpression("ModeTestTime").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new Time(5, 59, 59, 999))); - - value = results.forExpression("ModeTestDateTime").value(); - assertTrue(((DateTime) value).equal(new DateTime(bigDecimalZoneOffset, 2012, 9, 5))); - - value = results.forExpression("PopStdDevTest1").value(); - assertEquals( - 0, - ((BigDecimal) value) - .compareTo(new BigDecimal("1.41421356"))); // 23730951454746218587388284504413604736328125 - - value = results.forExpression("PopulationStdDevIsNull").value(); - assertThat(value, is(nullValue())); - - value = results.forExpression("PopVarianceTest1").value(); - assertEquals(0, ((BigDecimal) value).compareTo(new BigDecimal("2.0"))); - - value = results.forExpression("PopVarianceIsNull").value(); - assertThat(value, is(nullValue())); - - value = results.forExpression("StdDevTest1").value(); - assertEquals( - 0, - ((BigDecimal) value) - .compareTo(new BigDecimal("1.58113883"))); // 00841897613935316257993690669536590576171875 - - value = results.forExpression("StdDevIsNull").value(); - assertThat(value, is(nullValue())); - - value = results.forExpression("SumTest1").value(); - assertThat(value, is(new BigDecimal("20.0"))); - - value = results.forExpression("SumTestLong").value(); - assertThat(value, is(20L)); - - value = results.forExpression("SumTestQuantity").value(); - assertTrue(((Quantity) value) - .equal(new Quantity().withValue(new BigDecimal("15.0")).withUnit("ml"))); - - value = results.forExpression("SumTestNull").value(); - assertThat(value, is(1)); - - value = results.forExpression("VarianceTest1").value(); - assertEquals(0, ((BigDecimal) value).compareTo(new BigDecimal("2.5"))); } } diff --git a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlAggregateQueryTest.java b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlAggregateQueryTest.java deleted file mode 100644 index f1cc2b6f9..000000000 --- a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlAggregateQueryTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.opencds.cqf.cql.engine.execution; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; - -import org.junit.jupiter.api.Test; - -class CqlAggregateQueryTest extends CqlTestBase { - @Test - void all_aggregate_clause_tests() { - var results = engine.evaluate(toElmIdentifier("CqlAggregateQueryTest")); - var value = results.forExpression("AggregateSumWithStart").value(); - assertThat(value, is(16)); - - value = results.forExpression("AggregateSumWithNull").value(); - assertThat(value, is(15)); - - value = results.forExpression("AggregateSumAll").value(); - assertThat(value, is(24)); - - value = results.forExpression("AggregateSumDistinct").value(); - assertThat(value, is(15)); - - value = results.forExpression("Multi").value(); - assertThat(value, is(6)); - - value = results.forExpression("MegaMulti").value(); - assertThat(value, is(36)); - - value = results.forExpression("MegaMultiDistinct").value(); - assertThat(value, is(37)); - } -} diff --git a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlArithmeticFunctionsTest.java b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlArithmeticFunctionsTest.java index e156bc907..5d16c58c0 100644 --- a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlArithmeticFunctionsTest.java +++ b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlArithmeticFunctionsTest.java @@ -1,53 +1,20 @@ package org.opencds.cqf.cql.engine.execution; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.*; -import java.math.BigDecimal; -import org.hl7.elm.r1.VersionedIdentifier; import org.junit.jupiter.api.Test; import org.opencds.cqf.cql.engine.elm.executing.*; import org.opencds.cqf.cql.engine.exception.CqlException; -import org.opencds.cqf.cql.engine.exception.UndefinedResult; -import org.opencds.cqf.cql.engine.runtime.*; @SuppressWarnings("removal") class CqlArithmeticFunctionsTest extends CqlTestBase { - private static final VersionedIdentifier library = new VersionedIdentifier().withId("CqlArithmeticFunctionsTest"); - @Test void abs() { - var value = engine.expression(library, "AbsNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Abs0").value(); - assertThat(value, is(0)); - - value = engine.expression(library, "AbsNeg1").value(); - assertThat(value, is(1)); - - value = engine.expression(library, "AbsNeg1Long").value(); - assertThat(value, is(1L)); - - value = engine.expression(library, "AbsNeg1Dec").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(1.0))); - - value = engine.expression(library, "Abs0Dec").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(0.0))); - - value = engine.expression(library, "Abs1cm").value(); - assertEquals( - 0, - ((Quantity) value) - .compareTo( - new Quantity().withValue(new BigDecimal("1.0")).withUnit("cm"))); - // error testing try { - value = AbsEvaluator.abs("This is an error"); + var value = AbsEvaluator.abs("This is an error"); fail(); } catch (CqlException e) { // pass @@ -60,787 +27,12 @@ void abs() { @Test void add() { - var value = engine.expression(library, "AddNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Add11").value(); - assertThat(value, is(2)); - - value = engine.expression(library, "Add12Long").value(); - assertThat(value, is(3L)); - - value = engine.expression(library, "Add1D1D").value(); - assertThat(value, is(new BigDecimal("2.0"))); - - value = engine.expression(library, "Add1Q1Q").value(); - assertEquals(((Quantity) value).getValue(), new BigDecimal("2")); - assertEquals("g/cm3", ((Quantity) value).getUnit()); - - value = engine.expression(library, "AddIAndD").value(); - assertThat(value, is(new BigDecimal("3.0"))); - // error testing try { - value = AddEvaluator.add("This is an error", 404); + var value = AddEvaluator.add("This is an error", 404); fail(); } catch (CqlException e) { // pass } } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.CeilingEvaluator#evaluate(Context)} - */ - @Test - void ceiling() { - - var value = engine.expression(library, "CeilingNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Ceiling1D").value(); - assertThat(value, is(1)); - - value = engine.expression(library, "Ceiling1D1").value(); - assertThat(value, is(2)); - - value = engine.expression(library, "CeilingNegD1").value(); - assertThat(value, is(0)); - - value = engine.expression(library, "CeilingNeg1").value(); - assertThat(value, is(-1)); - - value = engine.expression(library, "CeilingNeg1D1").value(); - assertThat(value, is(-1)); - - value = engine.expression(library, "Ceiling1I").value(); - assertThat(value, is(1)); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.DivideEvaluator#evaluate(Context)} - */ - @Test - void divide() { - - var value = engine.expression(library, "DivideNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Divide10").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Divide01").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("0.0"))); - - value = engine.expression(library, "Divide11").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("1.0"))); - - value = engine.expression(library, "Divide11Long").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("1.0"))); - - value = engine.expression(library, "Divide1d1d").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("1.0"))); - - value = engine.expression(library, "Divide103").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("3.33333333"))); - - value = engine.expression(library, "Divide1Q1").value(); - assertEquals(((Quantity) value).getValue(), new BigDecimal("1")); - assertEquals("g/cm3", ((Quantity) value).getUnit()); - - // TODO: The asserted "correct" answer 1.0'g/cm3' is wrong; - // the true correct answer is just 1.0 with no units or empty string unit. - // value = engine.expression(arithmetic, "Divide1Q1Q").value(); - // Assertions.assertEquals(((Quantity) value).getValue(), new BigDecimal("1.0")); - // Assertions.assertEquals("g/cm3", ((Quantity) value).getUnit()); - - value = engine.expression(library, "Divide10I5D").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("2.0"))); - - value = engine.expression(library, "Divide10I5I").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("2.0"))); - - value = engine.expression(library, "Divide10Q5I").value(); - assertEquals(new BigDecimal("2.0"), ((Quantity) value).getValue()); - assertEquals("g", ((Quantity) value).getUnit()); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.FloorEvaluator#evaluate(Context)} - */ - @Test - void floor() { - - var value = engine.expression(library, "FloorNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Floor1").value(); - assertThat(value, is(1)); - - value = engine.expression(library, "Floor1D").value(); - assertThat(value, is(1)); - - value = engine.expression(library, "Floor1D1").value(); - assertThat(value, is(1)); - - value = engine.expression(library, "FloorNegD1").value(); - assertThat(value, is(-1)); - - value = engine.expression(library, "FloorNeg1").value(); - assertThat(value, is(-1)); - - value = engine.expression(library, "FloorNeg1D1").value(); - assertThat(value, is(-2)); - - value = engine.expression(library, "Floor2I").value(); - assertThat(value, is(2)); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.ExpEvaluator#evaluate(Context)} - */ - @Test - void exp() { - - var value = engine.expression(library, "ExpNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Exp0").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(1.0))); - - value = engine.expression(library, "ExpNeg0").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(1.0))); - - value = engine.expression(library, "Exp1").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(Math.exp(1d)))); - - value = engine.expression(library, "Exp1Long").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(Math.exp(1d)))); - - value = engine.expression(library, "ExpNeg1").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(Math.exp((double) -1)))); - - try { - value = engine.expression(library, "Exp1000").value(); - fail(); - } catch (UndefinedResult ae) { - assertThat(ae.getMessage(), is("Results in positive infinity")); - } - - try { - value = engine.expression(library, "Exp1000D").value(); - fail(); - } catch (UndefinedResult ae) { - assertThat(ae.getMessage(), is("Results in positive infinity")); - } - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.HighBoundaryEvaluator#evaluate(Context)} - */ - @Test - void highBoundary() { - - var value = engine.expression(library, "HighBoundaryDec").value(); - assertEquals(0, ((BigDecimal) value).compareTo(new BigDecimal("1.58799999"))); - - value = engine.expression(library, "HighBoundaryDate").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new Date(2014, 12))); - - value = engine.expression(library, "HighBoundaryDateTime").value(); - final DateTime expectedDateTime = new DateTime(getBigDecimalZoneOffset(), 2014, 1, 1, 8, 59, 59, 999); - assertTrue(EquivalentEvaluator.equivalent(value, expectedDateTime)); - - value = engine.expression(library, "HighBoundaryTime").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new Time(10, 30, 59, 999))); - - value = engine.expression(library, "HighBoundaryNull").value(); - assertNull(value); - - value = engine.expression(library, "HighBoundaryNullPrecision").value(); - assertEquals(0, ((BigDecimal) value).compareTo(new BigDecimal("1.58888999"))); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.LogEvaluator#evaluate(Context)} - */ - @Test - void log() { - var value = engine.expression(library, "LogNullNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Log1BaseNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Log1Base1").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Log1Base2").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(0d))); - - value = engine.expression(library, "Log1Base100").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(0d))); - - value = engine.expression(library, "Log1Base100Long").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(0d))); - - value = engine.expression(library, "Log16Base2").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(4d))); - - value = engine.expression(library, "LogD125Base2").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf((double) -3))); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.LnEvaluator#evaluate(Context)} - */ - @Test - void ln() { - var value = engine.expression(library, "LnNull").value(); - assertThat(value, is(nullValue())); - - try { - value = engine.expression(library, "Ln0").value(); - fail(); - } catch (UndefinedResult ae) { - assertThat(ae.getMessage(), is("Results in negative infinity")); - } - - try { - value = engine.expression(library, "LnNeg0").value(); - fail(); - } catch (UndefinedResult ae) { - assertThat(ae.getMessage(), is("Results in negative infinity")); - } - - value = engine.expression(library, "Ln1").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(0))); - - value = engine.expression(library, "Ln1Long").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(0))); - - value = engine.expression(library, "LnNeg1").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Ln1000").value(); - assertThat((BigDecimal) value, comparesEqualTo(Value.verifyPrecision(new BigDecimal("6.90775527"), null))); - - value = engine.expression(library, "Ln1000D").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("6.90775527"))); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.LowBoundaryEvaluator#evaluate(Context)} - */ - @Test - void lowBoundary() { - - var value = engine.expression(library, "LowBoundaryDec").value(); - assertEquals(0, ((BigDecimal) value).compareTo(new BigDecimal("1.58700000"))); - - value = engine.expression(library, "LowBoundaryDate").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new Date(2014, 1))); - - value = engine.expression(library, "LowBoundaryDateTime").value(); - final DateTime expectedDateTime = new DateTime(getBigDecimalZoneOffset(), 2014, 1, 1, 8, 0, 0, 0); - assertTrue(EquivalentEvaluator.equivalent(value, expectedDateTime)); - - value = engine.expression(library, "LowBoundaryTime").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new Time(10, 30, 0, 0))); - - value = engine.expression(library, "LowBoundaryNull").value(); - assertNull(value); - - value = engine.expression(library, "LowBoundaryNullPrecision").value(); - assertEquals(0, ((BigDecimal) value).compareTo(new BigDecimal("1.58888000"))); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.MaxEvaluator#evaluate(Context)} - */ - @Test - void maximum() { - - var value = engine.expression(library, "IntegerMaxValue").value(); - assertThat(value, is(Integer.MAX_VALUE)); - - value = engine.expression(library, "LongMaxValue").value(); - assertThat(value, is(Long.MAX_VALUE)); - - value = engine.expression(library, "DecimalMaxValue").value(); - assertEquals(0, ((BigDecimal) value).compareTo(new BigDecimal("99999999999999999999.99999999"))); - - value = engine.expression(library, "DateTimeMaxValue").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new DateTime(BigDecimal.ZERO, 9999, 12, 31, 23, 59, 59, 999))); - - value = engine.expression(library, "TimeMaxValue").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new Time(23, 59, 59, 999))); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.MinEvaluator#evaluate(Context)} - */ - @Test - void minimum() { - - var value = engine.expression(library, "IntegerMinValue").value(); - assertThat(value, is(Integer.MIN_VALUE)); - - value = engine.expression(library, "LongMinValue").value(); - assertThat(value, is(Long.MIN_VALUE)); - - value = engine.expression(library, "DecimalMinValue").value(); - assertEquals(0, ((BigDecimal) value).compareTo(new BigDecimal("-99999999999999999999.99999999"))); - - value = engine.expression(library, "DateTimeMinValue").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new DateTime(BigDecimal.ZERO, 1, 1, 1, 0, 0, 0, 0))); - - value = engine.expression(library, "TimeMinValue").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new Time(0, 0, 0, 0))); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.ModuloEvaluator#evaluate(Context)} - */ - @Test - void modulo() { - - var value = engine.expression(library, "ModuloNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Modulo0By0").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Modulo4By2").value(); - assertThat(value, is(0)); - - value = engine.expression(library, "Modulo4By2Long").value(); - assertThat(value, is(0L)); - - value = engine.expression(library, "Modulo4DBy2D").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(0d))); - - value = engine.expression(library, "Modulo10By3").value(); - assertThat(value, is((1))); - - value = engine.expression(library, "Modulo10DBy3D").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(1.0))); - - value = engine.expression(library, "Modulo10IBy3D").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(1.0))); - - value = engine.expression(library, "ModuloDResult").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(0.5))); - - value = engine.expression(library, "Modulo10By3Quantity").value(); - assertThat(((Quantity) value).getValue(), comparesEqualTo(BigDecimal.valueOf(1.0))); - assertThat(((Quantity) value).getUnit(), is("g")); - - value = engine.expression(library, "Modulo10By0Quantity").value(); - assertThat(value, is(nullValue())); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.MultiplyEvaluator#evaluate(Context)} - */ - @Test - void multiply() { - - var value = engine.expression(library, "MultiplyNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Multiply1By1").value(); - assertThat(value, is(1)); - - value = engine.expression(library, "Multiply2By3Long").value(); - assertThat(value, is(6L)); - - value = engine.expression(library, "Multiply1DBy2D").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(2.0))); - - value = engine.expression(library, "Multiply1IBy2D").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(2.0))); - - // TODO: should return multiplied units i.e. cm2 - // value = engine.expression(arithmetic, "Multiply1CMBy2CM").value(); - // Assertions.assertTrue(new BigDecimal("2.0").compareTo(((Quantity) value).getValue()) == 0); - // Assertions.assertEquals("cm", ((Quantity) value).getUnit()); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.NegateEvaluator#evaluate(Context)} - */ - @Test - void negate() { - var value = engine.expression(library, "NegateNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Negate0").value(); - assertThat(value, is(0)); - - value = engine.expression(library, "NegateNeg0").value(); - assertThat(value, is(0)); - - value = engine.expression(library, "Negate1").value(); - assertThat(value, is(-1)); - - value = engine.expression(library, "Negate1Long").value(); - assertThat(value, is(-1L)); - - value = engine.expression(library, "NegateMaxLong").value(); - assertThat(value, is(-9223372036854775808L)); - - value = engine.expression(library, "NegateNeg1").value(); - assertThat(value, is(1)); - - value = engine.expression(library, "Negate0D").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(-(0d)))); - - value = engine.expression(library, "NegateNeg0D").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(0d))); - - value = engine.expression(library, "Negate1D").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf((double) -1))); - - value = engine.expression(library, "NegateNeg1D").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("1.0"))); - - value = engine.expression(library, "Negate1CM").value(); - assertEquals(0, new BigDecimal("-1.0").compareTo(((Quantity) value).getValue())); - assertEquals("cm", ((Quantity) value).getUnit()); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.PredecessorEvaluator#evaluate(Context)} - */ - @Test - void predecessor() { - var value = engine.expression(library, "PredecessorNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "PredecessorOf0").value(); - assertThat(value, is(-1)); - - value = engine.expression(library, "PredecessorOf1").value(); - assertThat(value, is(0)); - - value = engine.expression(library, "PredecessorOf1Long").value(); - assertThat(value, is(0L)); - - value = engine.expression(library, "PredecessorOf1D").value(); - assertThat((BigDecimal) value, comparesEqualTo((new BigDecimal("0.99999999")))); - - value = engine.expression(library, "PredecessorOf101D").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("1.00999999"))); - - // value = engine.expression(arithmetic, "PredecessorOf1QCM").value(); - // Assertions.assertTrue(new BigDecimal("0.99999999").compareTo(((Quantity) value).getValue()) == 0); - // Assertions.assertEquals("cm", ((Quantity) value).getUnit()); - - value = engine.expression(library, "PredecessorOfJan12000").value(); - final DateTime expectedDateTime = new DateTime(getBigDecimalZoneOffset(), 1999, 12, 31); - assertTrue(EquivalentEvaluator.equivalent(value, expectedDateTime)); - - value = engine.expression(library, "PredecessorOfNoon").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new Time(11, 59, 59, 999))); - - try { - value = engine.expression(library, "PredecessorUnderflowDt").value(); - fail(); - } catch (RuntimeException re) { - assertThat(re.getMessage(), is("The year: 0 falls below the accepted bounds of 0001-9999.")); - } - - try { - value = engine.expression(library, "PredecessorUnderflowT").value(); - fail(); - } catch (RuntimeException re) { - assertThat( - re.getMessage(), - is("The result of the successor operation precedes the minimum value allowed for the Time type")); - } - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.PrecisionEvaluator#evaluate(Context)} - */ - @Test - void precision() { - var value = engine.expression(library, "PrecisionDecimal5").value(); - assertEquals(5, value); - - value = engine.expression(library, "PrecisionDateYear").value(); - assertEquals(4, value); - - value = engine.expression(library, "PrecisionDateTimeMs").value(); - assertEquals(17, value); - - value = engine.expression(library, "PrecisionTimeMinute").value(); - assertEquals(4, value); - - value = engine.expression(library, "PrecisionTimeMs").value(); - assertEquals(9, value); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.PowerEvaluator#evaluate(Context)} - */ - @Test - void power() { - var value = engine.expression(library, "PowerNullToNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Power0To0").value(); - assertThat(value, is(1)); - - value = engine.expression(library, "Power2To2").value(); - assertThat(value, is(4)); - - value = engine.expression(library, "Power2To2Long").value(); - assertThat(value, is(4L)); - - value = engine.expression(library, "PowerNeg2To2").value(); - assertThat(value, is(4)); - - value = engine.expression(library, "Power2ToNeg2").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("0.25"))); - - value = engine.expression(library, "Power2DTo2D").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(4d))); - - value = engine.expression(library, "PowerNeg2DTo2D").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(4d))); - - value = engine.expression(library, "Power2DToNeg2D").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(0.25))); - - value = engine.expression(library, "Power2DTo2").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(4d))); - - value = engine.expression(library, "Power2To2D").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(4d))); - - value = engine.expression(library, "Power2To4").value(); - assertThat(value, is(16)); - - value = engine.expression(library, "Power2To3Long").value(); - assertThat(value, is(8L)); - - value = engine.expression(library, "Power2DTo4D").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("16.0"))); - - value = engine.expression(library, "Power2DToNeg2DEquivalence").value(); - assertThat(value, is(true)); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.RoundEvaluator#evaluate(Context)} - */ - @Test - void round() { - var value = engine.expression(library, "RoundNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Round1").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(1.0))); - - value = engine.expression(library, "Round0D5").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(1.0))); - - value = engine.expression(library, "Round0D4").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(0.0))); - - value = engine.expression(library, "Round3D14159").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("3.14"))); - - value = engine.expression(library, "RoundNeg0D5").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(0.0))); - - value = engine.expression(library, "RoundNeg0D4").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(0.0))); - - value = engine.expression(library, "RoundNeg0D6").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(-1.0))); - - value = engine.expression(library, "RoundNeg1D1").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(-1.0))); - - value = engine.expression(library, "RoundNeg1D5").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(-1.0))); - - value = engine.expression(library, "RoundNeg1D6").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(-2.0))); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.SubtractEvaluator#evaluate(Context)} - */ - @Test - void subtract() { - var value = engine.expression(library, "SubtractNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Subtract1And1").value(); - assertThat(value, is(0)); - - value = engine.expression(library, "Subtract1And1Long").value(); - assertThat(value, is(0L)); - - value = engine.expression(library, "Subtract1DAnd2D").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(-1.0))); - - value = engine.expression(library, "Subtract1CMAnd2CM").value(); - assertEquals(0, new BigDecimal("-1.0").compareTo(((Quantity) value).getValue())); - assertEquals("cm", ((Quantity) value).getUnit()); - - value = engine.expression(library, "Subtract2And11D").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("0.9"))); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.SuccessorEvaluator#evaluate(Context)} - */ - @Test - void successor() { - var value = engine.expression(library, "SuccessorNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "SuccessorOf0").value(); - assertThat(value, is(1)); - - value = engine.expression(library, "SuccessorOf1").value(); - assertThat(value, is(2)); - - value = engine.expression(library, "SuccessorOf1Long").value(); - assertThat(value, is(2L)); - - value = engine.expression(library, "SuccessorOf1D").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("1.00000001"))); - - value = engine.expression(library, "SuccessorOf101D").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("1.01000001"))); - - value = engine.expression(library, "SuccessorOfJan12000").value(); - final DateTime expectedDateTime = new DateTime(getBigDecimalZoneOffset(), 2000, 1, 2); - assertTrue(EquivalentEvaluator.equivalent(value, expectedDateTime)); - - value = engine.expression(library, "SuccessorOfNoon").value(); - assertTrue(EquivalentEvaluator.equivalent(value, new Time(12, 0, 0, 1))); - - try { - value = engine.expression(library, "SuccessorOverflowDt").value(); - fail(); - } catch (RuntimeException re) { - assertThat(re.getMessage(), is("The year: 10000 falls above the accepted bounds of 0001-9999.")); - } - - try { - value = engine.expression(library, "SuccessorOverflowT").value(); - fail(); - } catch (RuntimeException re) { - assertThat( - re.getMessage(), - is("The result of the successor operation exceeds the maximum value allowed for the Time type")); - } - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.TruncateEvaluator#evaluate(Context)} - */ - @Test - void truncate() { - var value = engine.expression(library, "TruncateNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "Truncate0").value(); - assertThat(value, is(0)); - - value = engine.expression(library, "Truncate0D0").value(); - assertThat(value, is((0))); - - value = engine.expression(library, "Truncate0D1").value(); - assertThat(value, is((0))); - - value = engine.expression(library, "Truncate1").value(); - assertThat(value, is((1))); - - value = engine.expression(library, "Truncate1D0").value(); - assertThat(value, is((1))); - - value = engine.expression(library, "Truncate1D1").value(); - assertThat(value, is((1))); - - value = engine.expression(library, "Truncate1D9").value(); - assertThat(value, is((1))); - - value = engine.expression(library, "TruncateNeg1").value(); - assertThat(value, is((-1))); - - value = engine.expression(library, "TruncateNeg1D0").value(); - assertThat(value, is((-1))); - - value = engine.expression(library, "TruncateNeg1D1").value(); - assertThat(value, is((-1))); - - value = engine.expression(library, "TruncateNeg1D9").value(); - assertThat(value, is((-1))); - } - - /** - * {@link org.opencds.cqf.cql.engine.elm.execution.TruncatedDivideEvaluator#evaluate(Context)} - */ - @Test - void truncatedDivide() { - var value = engine.expression(library, "TruncatedDivideNull").value(); - assertThat(value, is(nullValue())); - - value = engine.expression(library, "TruncatedDivide2By1").value(); - assertThat(value, is(2)); - - value = engine.expression(library, "TruncatedDivide10By3").value(); - assertThat(value, is(3)); - - value = engine.expression(library, "TruncatedDivide10d1By3D1").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(3.0))); - - value = engine.expression(library, "TruncatedDivideNeg2ByNeg1").value(); - assertThat(value, is(2)); - - value = engine.expression(library, "TruncatedDivideNeg10ByNeg3").value(); - assertThat(value, is(3)); - - value = engine.expression(library, "TruncatedDivideNeg10d1ByNeg3D1").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(3.0))); - - value = engine.expression(library, "TruncatedDivideNeg2By1").value(); - assertThat(value, is(-2)); - - value = engine.expression(library, "TruncatedDivideNeg10By3").value(); - assertThat(value, is(-3)); - - value = engine.expression(library, "TruncatedDivideNeg10d1By3D1").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(-3.0))); - - value = engine.expression(library, "TruncatedDivide2ByNeg1").value(); - assertThat(value, is((-2))); - - value = engine.expression(library, "TruncatedDivide10ByNeg3").value(); - assertThat(value, is(-3)); - - value = engine.expression(library, "TruncatedDivide10d1ByNeg3D1").value(); - assertThat((BigDecimal) value, comparesEqualTo(BigDecimal.valueOf(-3.0))); - - value = engine.expression(library, "TruncatedDivide10By5D").value(); - assertThat((BigDecimal) value, comparesEqualTo(new BigDecimal("2.0"))); - - value = engine.expression(library, "TruncatedDivide10By5DQuantity").value(); - assertThat(((Quantity) value).getValue(), comparesEqualTo(new BigDecimal("2.0"))); - assertThat(((Quantity) value).getUnit(), is("g")); - - value = engine.expression(library, "TruncatedDivide414By206DQuantity").value(); - assertThat(((Quantity) value).getValue(), comparesEqualTo(new BigDecimal("2.0"))); - assertThat(((Quantity) value).getUnit(), is("m")); - - value = engine.expression(library, "TruncatedDivide10By0DQuantity").value(); - assertThat(value, nullValue()); - } } diff --git a/Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlAggregateFunctionsTest.cql b/Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlAggregateFunctionsTest.cql deleted file mode 100644 index acbed4f77..000000000 --- a/Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlAggregateFunctionsTest.cql +++ /dev/null @@ -1,78 +0,0 @@ -library CqlAggregateFunctionsTest - -//AllTrue -define AllTrueAllTrue : AllTrue({true,true}) -define AllTrueTrueFirst : AllTrue({true,false}) -define AllTrueFalseFirst : AllTrue({false,true}) -define AllTrueAllTrueFalseTrue : AllTrue({true,false,true}) -define AllTrueAllFalseTrueFalse : AllTrue({false,true,false}) -define AllTrueNullFirst : AllTrue({null,true,true}) -define AllTrueEmptyList : AllTrue({}) -define AllTrueIsTrueWhenNull : AllTrue(null) -//AnyTrue -define AnyTrueAllTrue : AnyTrue({true,true}) -define AnyTrueAllFalse : AnyTrue({false,false}) -define AnyTrueAllTrueFalseTrue : AnyTrue({true,false,true}) -define AnyTrueAllFalseTrueFalse : AnyTrue({false,true,false}) -define AnyTrueTrueFirst : AnyTrue({true,false}) -define AnyTrueFalseFirst : AnyTrue({false,true}) -define AnyTrueNullFirstThenTrue : AnyTrue({null,true}) -define AnyTrueNullFirstThenFalse : AnyTrue({null,false}) -define AnyTrueEmptyList : AnyTrue({}) -define AnyTrueIsFalseWhenNull : AnyTrue(null) - -//Avg -define AvgTest1: Avg({ 1.0, 2.0, 3.0, 6.0 }) - -//Product -define Product_Long: Product({5L, 4L, 5L}) - -//Count -define CountTest1: Count({ 15, 5, 99, null, 1 }) -define CountTestDateTime: Count({ DateTime(2014), DateTime(2001), DateTime(2010) }) -define CountTestTime: Count({ @T15:59:59.999, @T05:59:59.999, @T20:59:59.999 }) -define CountTestNull: Count({}) - -//Max -define MaxTestInteger: Max({ 5, 12, 1, 15, 0, 4, 90, 44 }) -define MaxTestLong: Max({ 5L, 12L, 1L, 15L, 0L, 4L, 90L, 44L }) -define MaxTestString: Max({ 'hi', 'bye', 'zebra' }) -define MaxTestDateTime: Max({ DateTime(2012, 10, 5), DateTime(2012, 9, 5), DateTime(2012, 10, 6) }) -define MaxTestTime: Max({ @T15:59:59.999, @T05:59:59.999, @T20:59:59.999 }) - -//Median -define MedianTestDecimal: Median({6.0, 5.0, 4.0, 3.0, 2.0, 1.0}) - -//Min -define MinTestInteger: Min({5, 12, 1, 15, 0, 4, 90, 44}) -define MinTestLong: Min({5L, 12L, 1L, 15L, 0L, 4L, 90L, 44L}) -define MinTestString: Min({'hi', 'bye', 'zebra'}) -define MinTestDateTime: Min({ DateTime(2012, 10, 5), DateTime(2012, 9, 5), DateTime(2012, 10, 6) }) -define MinTestTime: Min({ @T15:59:59.999, @T05:59:59.999, @T20:59:59.999 }) - -//Mode -define ModeTestInteger: Mode({ 2, 1, 8, 2, 9, 1, 9, 9 }) -define ModeTestDateTime: Mode({ DateTime(2012, 10, 5), DateTime(2012, 9, 5), DateTime(2012, 10, 6), DateTime(2012, 9, 5) }) -define ModeTestDateTime2: Mode({ DateTime(2012, 10, 5), DateTime(2012, 10, 5), DateTime(2012, 10, 6), DateTime(2012, 9, 5) }) -define ModeTestTime: Mode({ @T15:59:59.999, @T05:59:59.999, @T20:59:59.999, @T05:59:59.999 }) - -//PopulationStdDev -define PopStdDevTest1: PopulationStdDev({ 1.0, 2.0, 3.0, 4.0, 5.0 }) -define PopulationStdDevIsNull: PopulationStdDev({ null as Quantity, null as Quantity, null as Quantity }) - -//PopulationVariance -define PopVarianceTest1: PopulationVariance({ 1.0, 2.0, 3.0, 4.0, 5.0 }) -define PopVarianceIsNull: PopulationVariance({ null as Quantity, null as Quantity, null as Quantity }) - -//StdDev -define StdDevTest1: StdDev({ 1.0, 2.0, 3.0, 4.0, 5.0 }) -define StdDevIsNull: StdDev({ null as Quantity, null as Quantity, null as Quantity }) - -//Sum -define SumTest1: Sum({ 6.0, 2.0, 3.0, 4.0, 5.0 }) -define SumTestLong: Sum({ 6L, 2L, 3L, 4L, 5L }) -define SumTestQuantity: Sum({1 'ml',2 'ml',3 'ml',4 'ml',5 'ml'}) -define SumTestNull: Sum({ null, 1, null }) - -//Variance -define VarianceTest1: Variance({ 1.0, 2.0, 3.0, 4.0, 5.0 }) \ No newline at end of file diff --git a/Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlAggregateQueryTest.cql b/Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlAggregateQueryTest.cql deleted file mode 100644 index dd0c3763c..000000000 --- a/Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlAggregateQueryTest.cql +++ /dev/null @@ -1,45 +0,0 @@ -library CqlAggregateQueryTest - -//Aggregate clause -define AggregateSumWithStart: - ({ 1, 2, 3, 4, 5 }) Num - aggregate Result starting 1: Result + Num // 15 + 1 (the initial value) - -define AggregateSumWithNull: - ({ 1, 2, 3, 4, 5 }) Num - aggregate Result: Coalesce(Result, 0) + Num // 15 + 0 (the initial value from null) - -define AggregateSumAll: - ({ 1, 1, 2, 2, 2, 3, 4, 4, 5 }) Num - aggregate all Result: Coalesce(Result, 0) + Num // 24 + 0 - -define AggregateSumDistinct: - ({ 1, 1, 2, 2, 2, 3, 4, 4, 5 }) Num - aggregate distinct Result: Coalesce(Result, 0) + Num // 15 + 0 (the initial value) - - -define First: {1} -define Second: {2} -define Third: {3} - -define Multi: - from First X, Second Y, Third Z - aggregate Agg: Coalesce(Agg, 0) + X + Y + Z // 6 - -define "A": {1, 2} -define "B": {1, 2} -define "C": {1, 2} - -define MegaMulti: - from "A" X, "B" Y, "C" Z - aggregate Agg starting 0: Agg + X + Y + Z // 36 -- (1+1+1)+(1+1+2)+(1+2+1)+(1+2+2)+(2+1+1)+(2+1+2)+(2+2+1)+(2+2+2) - - -define "1": {1, 2, 2, 1} -define "2": {1, 2, 1, 2} -define "3": {2, 1, 2, 1} - -define MegaMultiDistinct: - from "1" X, "2" Y, "3" Z - aggregate distinct Agg starting 1: Agg + X + Y + Z // 37 -- 1 + (1+1+1)+(1+1+2)+(1+2+1)+(1+2+2)+(2+1+1)+(2+1+2)+(2+2+1)+(2+2+2) - diff --git a/Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlArithmeticFunctionsTest.cql b/Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlArithmeticFunctionsTest.cql deleted file mode 100644 index 0da7327ec..000000000 --- a/Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlArithmeticFunctionsTest.cql +++ /dev/null @@ -1,253 +0,0 @@ -library CqlArithmeticFunctionsTest - -//Abs -define AbsNull: Abs(null as Integer) -define Abs0: Abs(0) -define AbsNeg1: Abs(-1) -define AbsNeg1Long: Abs(-1L) -define AbsNeg1Dec: Abs(-1.0) -define Abs0Dec: Abs(0.0) -define Abs1cm: Abs(-1.0'cm') - -//Add -define AddNull: 1 + null -define Add11: 1 + 1 -define Add12Long: 1L + 2L -define Add1D1D: 1.0 + 1.0 -define Add1Q1Q: 1'g/cm3' + 1'g/cm3' -define AddIAndD: 1 + 2.0 - -//Ceiling -define CeilingNull: Ceiling(null as Decimal) -define Ceiling1D: Ceiling(1.0) -define Ceiling1D1: Ceiling(1.1) -define CeilingNegD1: Ceiling(-0.1) -define CeilingNeg1: Ceiling(-1.0) -define CeilingNeg1D1: Ceiling(-1.1) -define Ceiling1I: Ceiling(1) - -//Divide -define DivideNull: 1 / null -define Divide10: 1 / 0 -define Divide01: 0 / 1 -define Divide11: 1 / 1 -define Divide11Long: 1L / 1L -define Divide1d1d: 1.0 / 1.0 -define Divide103: 10 / 3 -define Divide1Q1: 1'g/cm3' / 1.0 -define Divide1Q1Q: 1'g/cm3' / 1'g/cm3' -define Divide10I5D: 10 / 5.0 -define Divide10I5I: 10 / 5 -define Divide10Q5I: 10.0 'g' / 5 - -//Floor -define FloorNull: Floor(null as Decimal) -define Floor1: Floor(1) -define Floor1D: Floor(1.0) -define Floor1D1: Floor(1.1) -define FloorNegD1: Floor(-0.1) -define FloorNeg1: Floor(-1.0) -define FloorNeg1D1: Floor(-1.1) -define Floor2I: Floor(2) - -//Exp -define ExpNull : Exp(null as Decimal) -define Exp0 : Exp(0) -define ExpNeg0 : Exp(-0) -define Exp1 : Exp(1) -define Exp1Long : Exp(1L) -define ExpNeg1 : Exp(-1) -define Exp1000 : Exp(1000) -define Exp1000D : Exp(1000.0) - -//HighBoundary - -define HighBoundaryDec : HighBoundary(1.587, 8) -define HighBoundaryDate :HighBoundary(@2014, 6) -define HighBoundaryDateTime : HighBoundary(@2014-01-01T08, 17) -define HighBoundaryTime : HighBoundary(@T10:30, 9) -define HighBoundaryNull : HighBoundary(null as Decimal, 8) -define HighBoundaryNullPrecision : HighBoundary(1.58888, null) - - -//Log -define LogNullNull : Log(null, null) -define Log1BaseNull : Log(1, null) -define Log1Base1 : Log(1, 1) -define Log1Base2 : Log(1, 2) -define Log1Base100 : Log(1, 100) -define Log1Base100Long : Log(1L, 100L) -define Log16Base2 : Log(16, 2) -define LogD125Base2 : Log(0.125, 2) - -//LowBoundary -define LowBoundaryDec : LowBoundary(1.587, 8) -define LowBoundaryDate :LowBoundary(@2014, 6) -define LowBoundaryDateTime : LowBoundary(@2014-01-01T08, 17) -define LowBoundaryTime : LowBoundary(@T10:30, 9) -define LowBoundaryNull : LowBoundary(null as Decimal, 8) -define LowBoundaryNullPrecision : LowBoundary(1.58888, null) - -//Ln -define LnNull : Ln(null) -define Ln0 : Ln(0) -define LnNeg0 : Ln(-0) -define Ln1 : Ln(1) -define Ln1Long : Ln(1L) -define LnNeg1 : Ln(-1) -define Ln1000 : Ln(1000) -define Ln1000D : Ln(1000.0) - -//MinValue -define IntegerMinValue: minimum Integer -define LongMinValue: minimum Long -define DecimalMinValue: minimum Decimal -define QuantityMinValue: minimum Quantity -define DateTimeMinValue: minimum DateTime -define TimeMinValue: minimum Time - -//MaxValue -define IntegerMaxValue: maximum Integer -define LongMaxValue: maximum Long -define DecimalMaxValue: maximum Decimal -define QuantityMaxValue: maximum Quantity -define DateTimeMaxValue: maximum DateTime -define TimeMaxValue: maximum Time - -//Modulo -define ModuloNull : 1 mod null -define Modulo0By0 : 0 mod 0 -define Modulo4By2 : 4 mod 2 -define Modulo4By2Long : 4L mod 2L -define Modulo4DBy2D : 4.0 mod 2.0 -define Modulo10By3 : 10 mod 3 -define Modulo10DBy3D : 10.0 mod 3.0 -define Modulo10IBy3D: 10 mod 3.0 -define ModuloDResult: 3.5 mod 3 -define Modulo10By3Quantity: 10.0 'g' mod 3.0 'g' -define Modulo10By0Quantity: 10.0 'g' mod 0.0 'g' - -//Multiply -define MultiplyNull: 1 * null -define Multiply1By1 : 1 * 1 -define Multiply2By3Long : 2L * 3L -define Multiply1DBy2D : 1.0 * 2.0 -define Multiply1IBy2D: 1 * 2.0 -define Multiply1CMBy2CM : 1.0 'cm' * 2.0 'cm' - -//Negate -define NegateNull: -(null as Integer) -define Negate0 : -0 -define NegateNeg0 : -(-0) -define Negate1 : -1 -define Negate1Long : -1L -define NegateMaxLong : -9223372036854775807L -define NegateNeg1 : -(-1) -define Negate0D : -(0.0) -define NegateNeg0D : -(-0.0) -define Negate1D : -(1.0) -define NegateNeg1D : -(-1.0) -define Negate1CM : -(1'cm') - -//Precision -define PrecisionDecimal5: Precision(1.58700) //5 -define PrecisionDateYear: Precision(@2014) // 4 -define PrecisionDateTimeMs: Precision(@2014-01-05T10:30:00.000) // 17 -define PrecisionTimeMinute: Precision(@T10:30) // 4 -define PrecisionTimeMs: Precision(@T10:30:00.000) // 9 - -//Predecessor -define PredecessorNull: predecessor of (null as Integer) -define PredecessorOf0: predecessor of 0 -define PredecessorOf1: predecessor of 1 -define PredecessorOf1Long: predecessor of 1L -define PredecessorOf1D: predecessor of 1.0 -define PredecessorOf101D: predecessor of 1.01 -define PredecessorOf1QCM: predecessor of 1.0 'cm' -define PredecessorOfJan12000: predecessor of DateTime(2000,1,1) -define PredecessorOfNoon: predecessor of @T12:00:00.000 -define PredecessorUnderflowDt: predecessor of DateTime(0001, 1, 1, 0, 0, 0, 0) -define PredecessorUnderflowT: predecessor of @T00:00:00.000 - -//Power -define PowerNullToNull: Power(null as Integer, null as Integer) -define Power0To0: Power(0, 0) -define Power2To2: Power(2, 2) -define Power2To2Long: Power(2L, 2L) -define PowerNeg2To2: Power(-2, 2) -define Power2ToNeg2: Power(2, -2) -define Power2DTo2D: Power(2.0, 2.0) -define PowerNeg2DTo2D: Power(-2.0, 2.0) -define Power2DToNeg2D: Power(2.0, -2.0) -define Power2DTo2: Power(2.0, 2) -define Power2To2D: Power(2, 2.0) -define Power2To4: 2^4 -define Power2To3Long: 2L^3L -define Power2DTo4D: 2.0^4.0 -define Power2DToNeg2DEquivalence: Power(2, -2) ~ 0.25 - -//Round -define RoundNull: Round(null as Decimal) -define Round1: Round(1) -define Round0D5: Round(0.5) -define Round0D4: Round(0.4) -define Round3D14159: Round(3.14159, 2) -define RoundNeg0D5: Round(-0.5) -define RoundNeg0D4: Round(-0.4) -define RoundNeg0D6: Round(-0.6) -define RoundNeg1D1: Round(-1.1) -define RoundNeg1D5: Round(-1.5) -define RoundNeg1D6: Round(-1.6) - -//Subtract -define SubtractNull: 1 - null -define Subtract1And1 : 1 - 1 -define Subtract1And1Long : 1L - 1L -define Subtract1DAnd2D : 1.0 - 2.0 -define Subtract1CMAnd2CM : 1.0 'cm' - 2.0 'cm' -define Subtract2And11D: 2 - 1.1 - -//Successor -define SuccessorNull: successor of (null as Integer) -define SuccessorOf0: successor of 0 -define SuccessorOf1: successor of 1 -define SuccessorOf1Long: successor of 1L -define SuccessorOf1D: successor of 1.0 -define SuccessorOf101D: successor of 1.01 -define SuccessorOfJan12000: successor of DateTime(2000,1,1) -define SuccessorOfNoon: successor of @T12:00:00.000 -define SuccessorOverflowDt: successor of DateTime(9999, 12, 31, 23, 59, 59, 999) -define SuccessorOverflowT: successor of @T23:59:59.999 - -//Truncate -define TruncateNull: Truncate(null as Decimal) -define Truncate0: Truncate(0) -define Truncate0D0: Truncate(0.0) -define Truncate0D1: Truncate(0.1) -define Truncate1: Truncate(1) -define Truncate1D0: Truncate(1.0) -define Truncate1D1: Truncate(1.1) -define Truncate1D9: Truncate(1.9) -define TruncateNeg1: Truncate(-1) -define TruncateNeg1D0: Truncate(-1.0) -define TruncateNeg1D1: Truncate(-1.1) -define TruncateNeg1D9: Truncate(-1.9) - -//Truncated Divide -define TruncatedDivideNull: (null as Integer) div (null as Integer) -define TruncatedDivide2By1: 2 div 1 -define TruncatedDivide10By3: 10 div 3 -define TruncatedDivide10d1By3D1: 10.1 div 3.1 -define TruncatedDivideNeg2ByNeg1: -2 div -1 -define TruncatedDivideNeg10ByNeg3: -10 div -3 -define TruncatedDivideNeg10d1ByNeg3D1: -10.1 div -3.1 -define TruncatedDivideNeg2By1: -2 div 1 -define TruncatedDivideNeg10By3: -10 div 3 -define TruncatedDivideNeg10d1By3D1: -10.1 div 3.1 -define TruncatedDivide2ByNeg1: 2 div -1 -define TruncatedDivide10ByNeg3: 10 div -3 -define TruncatedDivide10d1ByNeg3D1: 10.1 div -3.1 -define TruncatedDivide10By5D: 10 div 5.0 -define TruncatedDivide10By5DQuantity: 10.0 'g' div 5.0 'g' -define TruncatedDivide414By206DQuantity: 4.14 'm' div 2.06 'm' -define TruncatedDivide10By0DQuantity: 10.0 'g' div 0.0 'g' \ No newline at end of file