-
Notifications
You must be signed in to change notification settings - Fork 8
/
vector_test.go
57 lines (50 loc) · 1.01 KB
/
vector_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package pgvector_test
import (
"encoding/json"
"fmt"
"reflect"
"testing"
"github.com/pgvector/pgvector-go"
)
func TestVectorSlice(t *testing.T) {
vec := pgvector.NewVector([]float32{1, 2, 3})
if !reflect.DeepEqual(vec.Slice(), []float32{1, 2, 3}) {
t.Error()
}
}
func TestVectorString(t *testing.T) {
vec := pgvector.NewVector([]float32{1, 2, 3})
if fmt.Sprint(vec) != "[1,2,3]" {
t.Error()
}
}
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.Error()
}
}
func TestVectorMarshal(t *testing.T) {
vec := pgvector.NewVector([]float32{1, 2, 3})
data, err := json.Marshal(vec)
if err != nil {
panic(err)
}
if string(data) != "[1,2,3]" {
t.Error()
}
}
func TestVectorUnmarshal(t *testing.T) {
var vec pgvector.Vector
err := json.Unmarshal([]byte("[1,2,3]"), &vec)
if err != nil {
panic(err)
}
if !reflect.DeepEqual(vec.Slice(), []float32{1, 2, 3}) {
t.Error()
}
}