Skip to content

Commit

Permalink
Improved tests [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jul 23, 2024
1 parent f00164e commit 5c2ad58
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
12 changes: 6 additions & 6 deletions bun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ func TestBun(t *testing.T) {
panic(err)
}
if items[0].Id != 1 || items[1].Id != 3 || items[2].Id != 2 {
t.Errorf("Bad ids")
t.Error()
}
if !reflect.DeepEqual(items[1].Embedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad embedding")
t.Error()
}
if !reflect.DeepEqual(items[1].HalfEmbedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad half embedding")
t.Error()
}
if items[0].BinaryEmbedding != "000" || items[1].BinaryEmbedding != "111" || items[2].BinaryEmbedding != "101" {
t.Errorf("Bad binary embeddings")
t.Error()
}
if !reflect.DeepEqual(items[1].SparseEmbedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad sparse embedding")
t.Error()
}

var distances []float64
Expand All @@ -97,6 +97,6 @@ func TestBun(t *testing.T) {
panic(err)
}
if distances[0] != 0 || distances[1] != math.Sqrt(3) || distances[2] != 1 {
t.Errorf("Bad distances")
t.Error()
}
}
8 changes: 4 additions & 4 deletions ent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ func TestEnt(t *testing.T) {
panic(err)
}
if items[0].ID != 1 || items[1].ID != 3 || items[2].ID != 2 {
t.Errorf("Bad ids")
t.Error()
}
if !reflect.DeepEqual(items[1].Embedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad embedding")
t.Error()
}
if !reflect.DeepEqual(items[1].HalfEmbedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad half embedding")
t.Error()
}
if !reflect.DeepEqual(items[1].SparseEmbedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad sparse embedding")
t.Error()
}
}
12 changes: 6 additions & 6 deletions gorm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,24 @@ func TestGorm(t *testing.T) {
Expression: clause.Expr{SQL: "embedding <-> ?", Vars: []interface{}{pgvector.NewVector([]float32{1, 1, 1})}},
}).Limit(5).Find(&items)
if items[0].ID != 1 || items[1].ID != 3 || items[2].ID != 2 {
t.Errorf("Bad ids")
t.Error()
}
if !reflect.DeepEqual(items[1].Embedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad embedding")
t.Error()
}
if !reflect.DeepEqual(items[1].HalfEmbedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad half embedding")
t.Error()
}
if items[0].BinaryEmbedding != "000" || items[1].BinaryEmbedding != "111" || items[2].BinaryEmbedding != "101" {
t.Errorf("Bad binary embeddings")
t.Error()
}
if !reflect.DeepEqual(items[1].SparseEmbedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad sparse embedding")
t.Error()
}

var distances []float64
db.Model(&GormItem{}).Select("embedding <-> ?", pgvector.NewVector([]float32{1, 1, 1})).Order("id").Find(&distances)
if distances[0] != 0 || distances[1] != math.Sqrt(3) || distances[2] != 1 {
t.Errorf("Bad distances")
t.Error()
}
}
12 changes: 6 additions & 6 deletions pg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ func TestPg(t *testing.T) {
panic(err)
}
if items[0].Id != 1 || items[1].Id != 3 || items[2].Id != 2 {
t.Errorf("Bad ids")
t.Error()
}
if !reflect.DeepEqual(items[1].Embedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad embedding")
t.Error()
}
if !reflect.DeepEqual(items[1].HalfEmbedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad half embedding")
t.Error()
}
if items[0].BinaryEmbedding != "000" || items[1].BinaryEmbedding != "111" || items[2].BinaryEmbedding != "101" {
t.Errorf("Bad binary embeddings")
t.Error()
}
if !reflect.DeepEqual(items[1].SparseEmbedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad sparse embedding")
t.Error()
}

var distances []float64
Expand All @@ -85,6 +85,6 @@ func TestPg(t *testing.T) {
panic(err)
}
if distances[0] != 0 || distances[1] != math.Sqrt(3) || distances[2] != 1 {
t.Errorf("Bad distances")
t.Error()
}
}
10 changes: 5 additions & 5 deletions pgx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ func TestPgx(t *testing.T) {
}

if items[0].Id != 1 || items[1].Id != 3 || items[2].Id != 2 {
t.Errorf("Bad ids")
t.Error()
}
if !reflect.DeepEqual(items[1].Embedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad embedding")
t.Error()
}
if !reflect.DeepEqual(items[1].HalfEmbedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad half embedding")
t.Error()
}
if !reflect.DeepEqual(items[1].SparseEmbedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad sparse embedding")
t.Error()
}
if distances[0] != 0 || distances[1] != 1 || distances[2] != math.Sqrt(3) {
t.Errorf("Bad distances")
t.Error()
}
}
10 changes: 5 additions & 5 deletions sqlx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ func TestSqlx(t *testing.T) {
var items []SqlxItem
db.Select(&items, "SELECT * FROM sqlx_items ORDER BY embedding <-> $1 LIMIT 5", pgvector.NewVector([]float32{1, 1, 1}))
if items[0].Id != 1 || items[1].Id != 3 || items[2].Id != 2 {
t.Errorf("Bad ids")
t.Error()
}
if !reflect.DeepEqual(items[1].Embedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad embedding")
t.Error()
}
if !reflect.DeepEqual(items[1].HalfEmbedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad half embedding")
t.Error()
}
if items[0].BinaryEmbedding != "000" || items[1].BinaryEmbedding != "111" || items[2].BinaryEmbedding != "101" {
t.Errorf("Bad binary embeddings")
t.Error()
}
if !reflect.DeepEqual(items[1].SparseEmbedding.Slice(), []float32{1, 1, 2}) {
t.Errorf("Bad sparse embedding")
t.Error()
}
}

0 comments on commit 5c2ad58

Please sign in to comment.