@@ -242,19 +242,32 @@ func evaluateSpecialComparison(ctx context.Context, assertionDoc bson.Raw, actua
242
242
return fmt .Errorf ("expected lsid %v, got %v" , expectedID , actualID )
243
243
}
244
244
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 )
247
247
}
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 )
250
250
}
251
251
252
252
// Numeric values can be compared even if their types are different (e.g. if expected is an int32 and actual
253
253
// 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 )
258
271
}
259
272
return nil
260
273
case "$$matchAsDocument" :
0 commit comments