Skip to content

Commit

Permalink
Added tests for Parse method
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jun 4, 2024
1 parent 0549774 commit 818b8f5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions halfvec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions sparsevec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
11 changes: 11 additions & 0 deletions vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 818b8f5

Please sign in to comment.