-
Notifications
You must be signed in to change notification settings - Fork 8
/
halfvec_test.go
57 lines (50 loc) · 1.05 KB
/
halfvec_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 TestHalfVectorSlice(t *testing.T) {
vec := pgvector.NewHalfVector([]float32{1, 2, 3})
if !reflect.DeepEqual(vec.Slice(), []float32{1, 2, 3}) {
t.Error()
}
}
func TestHalfVectorString(t *testing.T) {
vec := pgvector.NewHalfVector([]float32{1, 2, 3})
if fmt.Sprint(vec) != "[1,2,3]" {
t.Error()
}
}
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.Error()
}
}
func TestHalfVectorMarshal(t *testing.T) {
vec := pgvector.NewHalfVector([]float32{1, 2, 3})
data, err := json.Marshal(vec)
if err != nil {
panic(err)
}
if string(data) != "[1,2,3]" {
t.Error()
}
}
func TestHalfVectorUnmarshal(t *testing.T) {
var vec pgvector.HalfVector
err := json.Unmarshal([]byte("[1,2,3]"), &vec)
if err != nil {
panic(err)
}
if !reflect.DeepEqual(vec.Slice(), []float32{1, 2, 3}) {
t.Error()
}
}