Repository navigation
Add order-independent list equivalence tests (FHIR-59734) - #173
Open
bryantaustin13 wants to merge 1 commit into
Open
bryantaustin13 wants to merge 1 commit into
bryantaustin13 wants to merge 1 commit into
Conversation
FHIR-59734 corrects CQL list equivalence to match FHIRPath: items are paired one to one, in any order. Adds seven Equivalent tests, one NotEquivalent test, and an Equal guard showing equality stays ordered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Test cases for FHIR-59734, which corrects CQL list equivalence (
~) to match FHIRPath. The tests come from the Zulip thread ~ and duplicates. Paul Lynch's two cases are the first two rows of the Equivalent table below. They're meant to check that the corrected wording produces aligned engines before the tracker goes to the WG.The change
CQL currently says list equivalence is ordered (Equivalent, and the list case in the general Equivalent): "for each element in the lists, in order, the elements are equivalent."
FHIRPath (§6.1.2 Equivalent) says: "Each item must be equivalent. Comparison is not order dependent. Note that this implies that if the collections have a different number of items to compare … the result will be false."
The Zulip discussion settled on a pairwise reading. Each item is matched one to one with an equivalent item on the other side, in any order, so duplicates count. Set-style comparison is still available with
includes/included in.Tests
All tests are in
CqlListOperatorsTest.xmland useversion="1.0", matching their groups.Equivalent
Equivalent12And21{ 1, 2 } ~ { 2, 1 }trueEquivalent112And122{ 1, 1, 2 } ~ { 1, 2, 2 }falseEquivalent111And112{ 1, 1, 1 } ~ { 1, 1, 2 }falseEquivalent112And111{ 1, 1, 2 } ~ { 1, 1, 1 }falsea ~ bmust equalb ~ aEquivalent122And212{ 1, 2, 2 } ~ { 2, 1, 2 }trueEquivalentOneNullAndNullOne{ 1, null } ~ { null, 1 }truenull ~ nullis trueEquivalentaBAndbA{ 'a', 'B' } ~ { 'b', 'A' }trueNot Equivalent
NotEquivalent12And21{ 1, 2 } !~ { 2, 1 }falseEqual (guard)
Equal12And21{ 1, 2 } = { 2, 1 }falseList equality stays ordered in both CQL (Equal) and FHIRPath. FHIR-59734 changes only equivalence.
Equivalent112And122,Equivalent111And112,Equivalent112And111andEqual12And21hold under both the current and the corrected wording. They catch an engine fix that makes~order-independent by treating the lists as sets.Current engines
Both reference engines implement the current, ordered wording:
listEquivalentinEquivalentEvaluator.ktwalks both lists in step;compareEveryItemInArrayscompares itemiwith itemi.So
Equivalent12And21,Equivalent122And212,EquivalentOneNullAndNullOne,EquivalentaBAndbAandNotEquivalent12And21are expected to fail on both until they're updated.Run through cql-tests-runner (
main,$cql) against the Java engine on HAPI FHIR 8.12.0, the results match:Equivalent12And21falseEquivalent122And212falseEquivalentOneNullAndNullOnefalseEquivalentaBAndbAfalseNotEquivalent12And21trueEquivalent112And122,Equivalent111And112,Equivalent112And111falseEqual12And21falseI haven't run them against cql-execution; that expectation comes from reading
compareEveryItemInArrays. The engine changes are tracked in cqframework/clinical_quality_language#1897 (Java) and cqframework/cql-execution#398.None of the 13 existing list
~/!~tests reorder items, so none of them change.Not covered
{ {1, 2} } ~ { {2, 1} }. Order-independence would apply recursively if element equivalence uses the same rule, but neither the tracker nor the thread says so.CqlListOperatorsTest.xmlvalidates againsttests/testSchema.xsd.🤖 Generated with Claude Code