Skip to content

Commit

Permalink
Added tests for String method
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jun 4, 2024
1 parent e41d95f commit ef87dad
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions halfvec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ package pgvector_test

import (
"encoding/json"
"fmt"
"reflect"
"testing"

"github.com/pgvector/pgvector-go"
)

func TestHalfVectorString(t *testing.T) {
vec := pgvector.NewHalfVector([]float32{1, 2, 3})
if fmt.Sprint(vec) != "[1,2,3]" {
t.Errorf("Bad marshal")
}
}

func TestHalfVectorMarshal(t *testing.T) {
vec := pgvector.NewHalfVector([]float32{1, 2, 3})
data, err := json.Marshal(vec)
Expand Down
15 changes: 15 additions & 0 deletions sparsevec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package pgvector_test

import (
"fmt"
"testing"

"github.com/pgvector/pgvector-go"
)

func TestSparseVectorString(t *testing.T) {
vec := pgvector.NewSparseVector([]float32{1, 0, 2, 0, 3, 0})
if fmt.Sprint(vec) != "{1:1,3:2,5:3}/6" {
t.Errorf("Bad marshal")
}
}
8 changes: 8 additions & 0 deletions vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ package pgvector_test

import (
"encoding/json"
"fmt"
"reflect"
"testing"

"github.com/pgvector/pgvector-go"
)

func TestVectorString(t *testing.T) {
vec := pgvector.NewVector([]float32{1, 2, 3})
if fmt.Sprint(vec) != "[1,2,3]" {
t.Errorf("Bad marshal")
}
}

func TestVectorMarshal(t *testing.T) {
vec := pgvector.NewVector([]float32{1, 2, 3})
data, err := json.Marshal(vec)
Expand Down

0 comments on commit ef87dad

Please sign in to comment.