From a6a75c264545289ea1982e9b0f612ac258897879 Mon Sep 17 00:00:00 2001 From: Selena Zhou Date: Wed, 18 Jun 2025 16:15:26 -0400 Subject: [PATCH 1/4] lte test allows for doubles --- internal/integration/unified/matches.go | 8 ++++---- internal/spectest/skip.go | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/internal/integration/unified/matches.go b/internal/integration/unified/matches.go index 52afdc283c..98f14e7fc1 100644 --- a/internal/integration/unified/matches.go +++ b/internal/integration/unified/matches.go @@ -242,11 +242,11 @@ func evaluateSpecialComparison(ctx context.Context, assertionDoc bson.Raw, actua return fmt.Errorf("expected lsid %v, got %v", expectedID, actualID) } case "$$lte": - if assertionVal.Type != bson.TypeInt32 && assertionVal.Type != bson.TypeInt64 { - return fmt.Errorf("expected assertionVal to be an Int32 or Int64 but got a %s", assertionVal.Type) + if assertionVal.Type != bson.TypeInt32 && assertionVal.Type != bson.TypeInt64 && assertionVal.Type != bson.TypeDouble { + return fmt.Errorf("expected assertionVal to be an Int32, Int64, or Double but got a %s", assertionVal.Type) } - if actual.Type != bson.TypeInt32 && actual.Type != bson.TypeInt64 { - return fmt.Errorf("expected value to be an Int32 or Int64 but got a %s", actual.Type) + if actual.Type != bson.TypeInt32 && actual.Type != bson.TypeInt64 && assertionVal.Type != bson.TypeDouble { + return fmt.Errorf("expected value to be an Int32, Int64, or Double but got a %s", actual.Type) } // Numeric values can be compared even if their types are different (e.g. if expected is an int32 and actual diff --git a/internal/spectest/skip.go b/internal/spectest/skip.go index c3c5d04fe3..70866530e1 100644 --- a/internal/spectest/skip.go +++ b/internal/spectest/skip.go @@ -11,10 +11,6 @@ import "testing" // skipTests is a map of "fully-qualified test name" to "the reason for skipping // the test". var skipTests = map[string][]string{ - // TODO(GODRIVER-3518): Test flexible numeric comparisons with $$lte - "Modifies $$lte operator test to also use floating point and Int64 types (GODRIVER-3518)": { - "TestUnifiedSpec/unified-test-format/tests/valid-pass/operator-lte.json/special_lte_matching_operator", - }, // SPEC-1403: This test checks to see if the correct error is thrown when auto // encrypting with a server < 4.2. Currently, the test will fail because a From ffc1b656a9ca1695768e7d43ca22dd1f83737825 Mon Sep 17 00:00:00 2001 From: Selena Zhou Date: Fri, 20 Jun 2025 15:42:25 -0400 Subject: [PATCH 2/4] convert values to float64 for comparison --- internal/integration/unified/matches.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/integration/unified/matches.go b/internal/integration/unified/matches.go index 98f14e7fc1..b3149a61a9 100644 --- a/internal/integration/unified/matches.go +++ b/internal/integration/unified/matches.go @@ -251,10 +251,22 @@ func evaluateSpecialComparison(ctx context.Context, assertionDoc bson.Raw, actua // Numeric values can be compared even if their types are different (e.g. if expected is an int32 and actual // is an int64). - expectedInt64 := assertionVal.AsInt64() - actualInt64 := actual.AsInt64() - if actualInt64 > expectedInt64 { - return fmt.Errorf("expected numeric value %d to be less than or equal %d", actualInt64, expectedInt64) + var expectedF64 float64 + if assertionVal.Type == bson.TypeDouble { + expectedF64 = assertionVal.Double() + } else { + expectedF64 = float64(assertionVal.AsInt64()) + } + + var actualF64 float64 + if actual.Type == bson.TypeDouble { + actualF64 = actual.Double() + } else { + actualF64 = float64(actual.AsInt64()) + } + + if actualF64 > expectedF64 { + return fmt.Errorf("expected numeric value %f to be less than or equal %f", actualF64, expectedF64) } return nil case "$$matchAsDocument": From 9ca1d2eb557334fec76312a082aa1feb7eca2f48 Mon Sep 17 00:00:00 2001 From: Selena Zhou Date: Fri, 20 Jun 2025 15:56:48 -0400 Subject: [PATCH 3/4] todo comment for GODRIVER-3594 --- internal/integration/unified/matches.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/integration/unified/matches.go b/internal/integration/unified/matches.go index b3149a61a9..37ae6e7d9b 100644 --- a/internal/integration/unified/matches.go +++ b/internal/integration/unified/matches.go @@ -251,6 +251,8 @@ func evaluateSpecialComparison(ctx context.Context, assertionDoc bson.Raw, actua // Numeric values can be compared even if their types are different (e.g. if expected is an int32 and actual // is an int64). + + // TODO(GODRIVER-3594): If we decide to add AsDoubleOK() as a method to RawValue, this following conversion should be updated. var expectedF64 float64 if assertionVal.Type == bson.TypeDouble { expectedF64 = assertionVal.Double() From ef9eade9c62faf534ef498ee283923b4eb280037 Mon Sep 17 00:00:00 2001 From: Selena Zhou Date: Fri, 20 Jun 2025 15:58:07 -0400 Subject: [PATCH 4/4] some cleanup --- internal/integration/unified/matches.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/integration/unified/matches.go b/internal/integration/unified/matches.go index 37ae6e7d9b..3d0f04030e 100644 --- a/internal/integration/unified/matches.go +++ b/internal/integration/unified/matches.go @@ -259,7 +259,6 @@ func evaluateSpecialComparison(ctx context.Context, assertionDoc bson.Raw, actua } else { expectedF64 = float64(assertionVal.AsInt64()) } - var actualF64 float64 if actual.Type == bson.TypeDouble { actualF64 = actual.Double()