@@ -9,7 +9,6 @@ package bson
9
9
import (
10
10
"encoding/hex"
11
11
"encoding/json"
12
- "math"
13
12
"os"
14
13
"path"
15
14
"testing"
@@ -27,13 +26,13 @@ type bsonBinaryVectorTests struct {
27
26
}
28
27
29
28
type bsonBinaryVectorTestCase struct {
30
- Description string `json:"description"`
31
- Valid bool `json:"valid"`
32
- Vector [] interface {} `json:"vector"`
33
- DtypeHex string `json:"dtype_hex"`
34
- DtypeAlias string `json:"dtype_alias"`
35
- Padding int `json:"padding"`
36
- CanonicalBson string `json:"canonical_bson"`
29
+ Description string `json:"description"`
30
+ Valid bool `json:"valid"`
31
+ Vector json. RawMessage `json:"vector"`
32
+ DtypeHex string `json:"dtype_hex"`
33
+ DtypeAlias string `json:"dtype_alias"`
34
+ Padding int `json:"padding"`
35
+ CanonicalBson string `json:"canonical_bson"`
37
36
}
38
37
39
38
func TestBsonBinaryVectorSpec (t * testing.T ) {
@@ -83,21 +82,19 @@ func TestBsonBinaryVectorSpec(t *testing.T) {
83
82
})
84
83
}
85
84
86
- func convertSlice [T int8 | float32 | byte ](s []interface {}) []T {
85
+ func decodeTestSlice [T int8 | float32 | byte ](t * testing.T , data []byte ) []T {
86
+ t .Helper ()
87
+
88
+ if len (data ) == 0 {
89
+ return nil
90
+ }
91
+ var s []float64
92
+ err := UnmarshalExtJSON (data , true , & s )
93
+ require .NoError (t , err )
94
+
87
95
v := make ([]T , len (s ))
88
96
for i , e := range s {
89
- f := math .NaN ()
90
- switch val := e .(type ) {
91
- case float64 :
92
- f = val
93
- case string :
94
- if val == "inf" {
95
- f = math .Inf (0 )
96
- } else if val == "-inf" {
97
- f = math .Inf (- 1 )
98
- }
99
- }
100
- v [i ] = T (f )
97
+ v [i ] = T (e )
101
98
}
102
99
return v
103
100
}
@@ -108,17 +105,17 @@ func runBsonBinaryVectorTest(t *testing.T, testKey string, test bsonBinaryVector
108
105
case "0x03" :
109
106
testVector [testKey ] = Vector {
110
107
dType : Int8Vector ,
111
- int8Data : convertSlice [int8 ](test .Vector ),
108
+ int8Data : decodeTestSlice [int8 ](t , test .Vector ),
112
109
}
113
110
case "0x27" :
114
111
testVector [testKey ] = Vector {
115
112
dType : Float32Vector ,
116
- float32Data : convertSlice [float32 ](test .Vector ),
113
+ float32Data : decodeTestSlice [float32 ](t , test .Vector ),
117
114
}
118
115
case "0x10" :
119
116
testVector [testKey ] = Vector {
120
117
dType : PackedBitVector ,
121
- bitData : convertSlice [byte ](test .Vector ),
118
+ bitData : decodeTestSlice [byte ](t , test .Vector ),
122
119
bitPadding : uint8 (test .Padding ),
123
120
}
124
121
default :
0 commit comments