Repository navigation
Add mixed-unit Quantity tests for div and mod - #167
Open
bryantaustin13 wants to merge 2 commits into
Open
bryantaustin13 wants to merge 2 commits into
bryantaustin13 wants to merge 2 commits into
Conversation
Every Quantity test for div and mod used the same unit on both sides, so the suite could not tell whether an engine converts units at all. Four Truncated Divide tests divide operands of the same dimension in different units: "The div operator performs truncated division of its arguments", so 250.0 'cm' div 1.0 'm' is 2.5 truncated to 2.0 '1' (the dimensionless unit, as in the existing tests since cqframework#148), and likewise for a negative, a zero and a kg/g case. Two Modulo tests do the same for mod: 100 cm mod 30 cm = 10 cm. The spec does not say which unit a mixed-unit result is in (10 'cm' or 0.1 'm'), so they compare with =, which only requires the same dimension. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FHIR-59659 specifies that mod keeps the operands' unit after converting them to common units as division does, so the two mixed-unit Modulo tests now expect 10.0 'cm' and 100.0 'g' instead of comparing with =. Adds Modulo10GBy3Quantity (10.0 'g' mod 3 is 1.0 'g') and cites the ticket's div rule on the mixed-unit Truncated Divide tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every Quantity test for
divandmoduses the same unit on both sides ('g' div 'g','cm' mod 'cm', …). So the suite can't tell whether an engine converts units at all. On the Java engine, for example,250.0 'cm' div 1.0 'm'returns250 'cm'and1.0 'm' mod 30.0 'cm'returns1 'm'(cqframework/clinical_quality_language#1860), but every existing Quantitydiv/modtest only checks the unit label.The expected units follow FHIR-59659 ("Specify result unit determination for div and mod operators"), which asks for examples based on these tests:
"In the same way as for division" refers to the FHIR-58137 rule (#161): convert to the most granular unit, which for a positive exponent is the smaller one.
Change
Seven tests in
CqlArithmeticFunctionsTest.xml. They are markedversion="1.5", since the Quantity overloads were introduced in 1.5, and they carry the same capabilities as their sibling Quantity tests. Each set has a comment quoting FHIR-59659 and linking the spec entry.Truncated Divide (end of the group):
TruncatedDivide250CMBy1MQuantity250.0 'cm' div 1.0 'm'2.0 '1'TruncatedDivideNeg250CMBy1MQuantity-250.0 'cm' div 1.0 'm'-2.0 '1'TruncatedDivide10CMBy1MQuantity10.0 'cm' div 1.0 'm'0.0 '1'TruncatedDivide7KGBy2GQuantity7.0 'kg' div 2.0 'g'3500.0 '1'"The div operator performs truncated division of its arguments", so 250 cm ÷ 1 m = 2.5 truncates to 2, and −2.5 truncates to −2. The result is unitless (
'1'), per FHIR-59659.Modulo (end of the group):
Modulo1MBy30CMQuantity1.0 'm' mod 30.0 'cm'10.0 'cm'Modulo1KGBy300GQuantity1.0 'kg' mod 300.0 'g'100.0 'g'Modulo10GBy3Quantity10.0 'g' mod 31.0 'g'3converts implicitly to3 '1'. As in division (10.0 'g' / 3is3.33 'g'),'1'has no dimension to convert, so the remainder keeps the left operand's unit. FHIR-59659 doesn't spell this case out; Bryn confirmed the tests should be built on that ticket.An earlier version of this PR compared the mixed-unit Modulo results with
=, because the result unit wasn't specified. FHIR-59659 settles it, so they now expect exact units.Verification
CqlArithmeticFunctionsTest.xmlvalidates againsttests/testSchema.xsd.TruncatedDivide250CMBy1MQuantity250 'cm')TruncatedDivideNeg250CMBy1MQuantity-250 'cm')TruncatedDivide10CMBy1MQuantity10 'cm')TruncatedDivide7KGBy2GQuantity3 'kg')Modulo1MBy30CMQuantitynull)1 'm')Modulo1KGBy300GQuantitynull)1 'kg')Modulo10GBy3Quantitynullexpected (see below)1 'g')TruncatedDivide10By5DQuantityand others) fail there too, returning the operand's unit instead of'1'.nullfor every Quantitymod, including the existing same-unitModuloQuantityandModulo10By3Quantity, because itsModulohas no Quantity branch. That's tracked as Modulo is not implemented for Quantity arguments (always returns null) cql-execution#386, with a fix in Implement Modulo for Quantity arguments cql-execution#393. That fix returnsnullwhen the units differ after conversion, which includes10.0 'g' mod 3, soModulo10GBy3Quantityneeds a change there; I've suggested one in a review on #393.No other test changes.
🤖 Generated with Claude Code