Skip to content

Commit fe60b18

Browse files
authored
GODRIVER-3518: Test flexible numeric comparisons with $$lte (#2106)
1 parent 517dd58 commit fe60b18

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

internal/integration/unified/matches.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,32 @@ func evaluateSpecialComparison(ctx context.Context, assertionDoc bson.Raw, actua
242242
return fmt.Errorf("expected lsid %v, got %v", expectedID, actualID)
243243
}
244244
case "$$lte":
245-
if assertionVal.Type != bson.TypeInt32 && assertionVal.Type != bson.TypeInt64 {
246-
return fmt.Errorf("expected assertionVal to be an Int32 or Int64 but got a %s", assertionVal.Type)
245+
if assertionVal.Type != bson.TypeInt32 && assertionVal.Type != bson.TypeInt64 && assertionVal.Type != bson.TypeDouble {
246+
return fmt.Errorf("expected assertionVal to be an Int32, Int64, or Double but got a %s", assertionVal.Type)
247247
}
248-
if actual.Type != bson.TypeInt32 && actual.Type != bson.TypeInt64 {
249-
return fmt.Errorf("expected value to be an Int32 or Int64 but got a %s", actual.Type)
248+
if actual.Type != bson.TypeInt32 && actual.Type != bson.TypeInt64 && assertionVal.Type != bson.TypeDouble {
249+
return fmt.Errorf("expected value to be an Int32, Int64, or Double but got a %s", actual.Type)
250250
}
251251

252252
// Numeric values can be compared even if their types are different (e.g. if expected is an int32 and actual
253253
// is an int64).
254-
expectedInt64 := assertionVal.AsInt64()
255-
actualInt64 := actual.AsInt64()
256-
if actualInt64 > expectedInt64 {
257-
return fmt.Errorf("expected numeric value %d to be less than or equal %d", actualInt64, expectedInt64)
254+
255+
// TODO(GODRIVER-3594): If we decide to add AsDoubleOK() as a method to RawValue, this following conversion should be updated.
256+
var expectedF64 float64
257+
if assertionVal.Type == bson.TypeDouble {
258+
expectedF64 = assertionVal.Double()
259+
} else {
260+
expectedF64 = float64(assertionVal.AsInt64())
261+
}
262+
var actualF64 float64
263+
if actual.Type == bson.TypeDouble {
264+
actualF64 = actual.Double()
265+
} else {
266+
actualF64 = float64(actual.AsInt64())
267+
}
268+
269+
if actualF64 > expectedF64 {
270+
return fmt.Errorf("expected numeric value %f to be less than or equal %f", actualF64, expectedF64)
258271
}
259272
return nil
260273
case "$$matchAsDocument":

internal/spectest/skip.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import "testing"
1111
// skipTests is a map of "fully-qualified test name" to "the reason for skipping
1212
// the test".
1313
var skipTests = map[string][]string{
14-
// TODO(GODRIVER-3518): Test flexible numeric comparisons with $$lte
15-
"Modifies $$lte operator test to also use floating point and Int64 types (GODRIVER-3518)": {
16-
"TestUnifiedSpec/unified-test-format/tests/valid-pass/operator-lte.json/special_lte_matching_operator",
17-
},
1814

1915
// SPEC-1403: This test checks to see if the correct error is thrown when auto
2016
// encrypting with a server < 4.2. Currently, the test will fail because a

0 commit comments

Comments
 (0)