diff --git a/halfvec_test.go b/halfvec_test.go index 04c7e76..343ce0a 100644 --- a/halfvec_test.go +++ b/halfvec_test.go @@ -23,6 +23,17 @@ func TestHalfVectorString(t *testing.T) { } } +func TestHalfVectorParse(t *testing.T) { + var vec pgvector.HalfVector + err := vec.Parse("[1,2,3]") + if err != nil { + panic(err) + } + if !reflect.DeepEqual(vec.Slice(), []float32{1, 2, 3}) { + t.Errorf("Bad parse") + } +} + func TestHalfVectorMarshal(t *testing.T) { vec := pgvector.NewHalfVector([]float32{1, 2, 3}) data, err := json.Marshal(vec) diff --git a/sparsevec_test.go b/sparsevec_test.go index 9232e41..3d8de53 100644 --- a/sparsevec_test.go +++ b/sparsevec_test.go @@ -21,3 +21,14 @@ func TestSparseVectorString(t *testing.T) { t.Errorf("Bad string") } } + +func TestSparseVectorParse(t *testing.T) { + var vec pgvector.SparseVector + err := vec.Parse("{1:1,3:2,5:3}/6") + if err != nil { + panic(err) + } + if !reflect.DeepEqual(vec.Slice(), []float32{1, 0, 2, 0, 3, 0}) { + t.Errorf("Bad parse") + } +} diff --git a/vector_test.go b/vector_test.go index 6db56ea..44832f2 100644 --- a/vector_test.go +++ b/vector_test.go @@ -23,6 +23,17 @@ func TestVectorString(t *testing.T) { } } +func TestVectorParse(t *testing.T) { + var vec pgvector.Vector + err := vec.Parse("[1,2,3]") + if err != nil { + panic(err) + } + if !reflect.DeepEqual(vec.Slice(), []float32{1, 2, 3}) { + t.Errorf("Bad parse") + } +} + func TestVectorMarshal(t *testing.T) { vec := pgvector.NewVector([]float32{1, 2, 3}) data, err := json.Marshal(vec)