@@ -9,7 +9,6 @@ package bson
99import (
1010 "encoding/hex"
1111 "encoding/json"
12- "math"
1312 "os"
1413 "path"
1514 "testing"
@@ -26,13 +25,13 @@ type bsonBinaryVectorTests struct {
2625}
2726
2827type bsonBinaryVectorTestCase struct {
29- Description string `json:"description"`
30- Valid bool `json:"valid"`
31- Vector [] interface {} `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"`
28+ Description string `json:"description"`
29+ Valid bool `json:"valid"`
30+ Vector json. RawMessage `json:"vector"`
31+ DtypeHex string `json:"dtype_hex"`
32+ DtypeAlias string `json:"dtype_alias"`
33+ Padding int `json:"padding"`
34+ CanonicalBson string `json:"canonical_bson"`
3635}
3736
3837func TestBsonBinaryVectorSpec (t * testing.T ) {
@@ -82,21 +81,18 @@ func TestBsonBinaryVectorSpec(t *testing.T) {
8281 })
8382}
8483
85- func convertSlice [T int8 | float32 | byte ](s []interface {}) []T {
84+ func convertSlice [T int8 | float32 | byte ](t * testing.T , data []byte ) []T {
85+ if len (data ) == 0 {
86+ return nil
87+ }
88+ var s []float64
89+ err := UnmarshalExtJSON (data , true , & s )
90+ if err != nil {
91+ t .Fatalf ("got %q while handling %s" , err , string (data ))
92+ }
8693 v := make ([]T , len (s ))
8794 for i , e := range s {
88- f := math .NaN ()
89- switch val := e .(type ) {
90- case float64 :
91- f = val
92- case string :
93- if val == "inf" {
94- f = math .Inf (0 )
95- } else if val == "-inf" {
96- f = math .Inf (- 1 )
97- }
98- }
99- v [i ] = T (f )
95+ v [i ] = T (e )
10096 }
10197 return v
10298}
@@ -107,17 +103,17 @@ func runBsonBinaryVectorTest(t *testing.T, testKey string, test bsonBinaryVector
107103 case "0x03" :
108104 testVector [testKey ] = Vector {
109105 dType : Int8Vector ,
110- int8Data : convertSlice [int8 ](test .Vector ),
106+ int8Data : convertSlice [int8 ](t , test .Vector ),
111107 }
112108 case "0x27" :
113109 testVector [testKey ] = Vector {
114110 dType : Float32Vector ,
115- float32Data : convertSlice [float32 ](test .Vector ),
111+ float32Data : convertSlice [float32 ](t , test .Vector ),
116112 }
117113 case "0x10" :
118114 testVector [testKey ] = Vector {
119115 dType : PackedBitVector ,
120- bitData : convertSlice [byte ](test .Vector ),
116+ bitData : convertSlice [byte ](t , test .Vector ),
121117 bitPadding : uint8 (test .Padding ),
122118 }
123119 default :
0 commit comments