Skip to content

Commit

Permalink
update: add tests for decoding base64 encoded emeddings
Browse files Browse the repository at this point in the history
Signed-off-by: Milos Gajdos <[email protected]>
  • Loading branch information
milosgajdos committed Mar 24, 2024
1 parent dfa2b14 commit d67a5cf
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion embeddings_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package embeddings

import "testing"
import (
"reflect"
"testing"
)

func TestToFloat32(t *testing.T) {
e := Embedding{
Expand All @@ -20,3 +23,47 @@ func TestToFloat32(t *testing.T) {
}
}
}

func TestBase64Decode(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
given string
exp []float64
wantErr bool
}{
{
name: "valid",
given: "H4XrUbgeCUAAAAAAAABFwESLbOf7QI9A",
exp: []float64{3.14, -42.0, 1000.123},
wantErr: false,
},
{
name: "invalid",
given: "garbage",
wantErr: true,
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
embBase64 := Base64(tc.given)
got, err := embBase64.Decode()
if err != nil {
if !tc.wantErr {
t.Fatalf("unexpected error: %v", err)
}
return
}
// no error, but we expect one
if tc.wantErr {
t.Fatal("expected error")
}
if !reflect.DeepEqual(got, tc.exp) {
t.Fatalf("expected: %v, got: %v", tc.exp, got)
}
})
}
}

0 comments on commit d67a5cf

Please sign in to comment.