diff --git a/bson/bson_binary_vector_spec_test.go b/bson/bson_binary_vector_spec_test.go index dcd987b3e5..37529a4686 100644 --- a/bson/bson_binary_vector_spec_test.go +++ b/bson/bson_binary_vector_spec_test.go @@ -9,7 +9,6 @@ package bson import ( "encoding/hex" "encoding/json" - "math" "os" "path" "testing" @@ -26,13 +25,13 @@ type bsonBinaryVectorTests struct { } type bsonBinaryVectorTestCase struct { - Description string `json:"description"` - Valid bool `json:"valid"` - Vector []interface{} `json:"vector"` - DtypeHex string `json:"dtype_hex"` - DtypeAlias string `json:"dtype_alias"` - Padding int `json:"padding"` - CanonicalBson string `json:"canonical_bson"` + Description string `json:"description"` + Valid bool `json:"valid"` + Vector json.RawMessage `json:"vector"` + DtypeHex string `json:"dtype_hex"` + DtypeAlias string `json:"dtype_alias"` + Padding int `json:"padding"` + CanonicalBson string `json:"canonical_bson"` } func TestBsonBinaryVectorSpec(t *testing.T) { @@ -82,21 +81,19 @@ func TestBsonBinaryVectorSpec(t *testing.T) { }) } -func convertSlice[T int8 | float32 | byte](s []interface{}) []T { +func decodeTestSlice[T int8 | float32 | byte](t *testing.T, data []byte) []T { + t.Helper() + + if len(data) == 0 { + return nil + } + var s []float64 + err := UnmarshalExtJSON(data, true, &s) + require.NoError(t, err) + v := make([]T, len(s)) for i, e := range s { - f := math.NaN() - switch val := e.(type) { - case float64: - f = val - case string: - if val == "inf" { - f = math.Inf(0) - } else if val == "-inf" { - f = math.Inf(-1) - } - } - v[i] = T(f) + v[i] = T(e) } return v } @@ -107,17 +104,17 @@ func runBsonBinaryVectorTest(t *testing.T, testKey string, test bsonBinaryVector case "0x03": testVector[testKey] = Vector{ dType: Int8Vector, - int8Data: convertSlice[int8](test.Vector), + int8Data: decodeTestSlice[int8](t, test.Vector), } case "0x27": testVector[testKey] = Vector{ dType: Float32Vector, - float32Data: convertSlice[float32](test.Vector), + float32Data: decodeTestSlice[float32](t, test.Vector), } case "0x10": testVector[testKey] = Vector{ dType: PackedBitVector, - bitData: convertSlice[byte](test.Vector), + bitData: decodeTestSlice[byte](t, test.Vector), bitPadding: uint8(test.Padding), } default: diff --git a/testdata/bson-binary-vector/float32.json b/testdata/bson-binary-vector/float32.json index 845f504ff3..0bc88fc65a 100644 --- a/testdata/bson-binary-vector/float32.json +++ b/testdata/bson-binary-vector/float32.json @@ -32,7 +32,7 @@ { "description": "Infinity Vector FLOAT32", "valid": true, - "vector": ["-inf", 0.0, "inf"], + "vector": [{"$numberDouble": "-Infinity"}, 0.0, {"$numberDouble": "Infinity"}], "dtype_hex": "0x27", "dtype_alias": "FLOAT32", "padding": 0,