Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
Signed-off-by: kevindiu <kevindiujp@gmail.com>
  • Loading branch information
kevindiu committed Jun 1, 2022
1 parent 3700ad8 commit b70cf9d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 107 deletions.
18 changes: 18 additions & 0 deletions internal/conv/conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ func TestUtf8ToSjis(t *testing.T) {
want: "\x82\xb1\x82\xf1\x82ɂ\xbf\x82\xcd",
},
},
{
name: "return empty string when the UTF8 string is empty",
args: args{
s: "",
},
want: want{
want: "",
},
},
}

for _, tc := range tests {
Expand Down Expand Up @@ -333,6 +342,15 @@ func TestUtf8ToEucjp(t *testing.T) {
want: "\xa4\xb3\xa4\xf3\xa4ˤ\xc1\xa4\xcf",
},
},
{
name: "return empty string when the UTF8 string is empty",
args: args{
s: "",
},
want: want{
want: "",
},
},
}

for _, tc := range tests {
Expand Down
12 changes: 5 additions & 7 deletions internal/test/data/request/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ import (
"github.com/vdaas/vald/internal/test/goleak"
)

var (
defaultMultiInsertReqComparators = []cmp.Option{
comparator.IgnoreUnexported(payload.Insert_Request{}),
comparator.IgnoreUnexported(payload.Insert_MultiRequest{}),
comparator.IgnoreUnexported(payload.Object_Vector{}),
}
)
var defaultMultiInsertReqComparators = []cmp.Option{
comparator.IgnoreUnexported(payload.Insert_Request{}),
comparator.IgnoreUnexported(payload.Insert_MultiRequest{}),
comparator.IgnoreUnexported(payload.Object_Vector{}),
}

func TestGenMultiInsertReq(t *testing.T) {
type args struct {
Expand Down
16 changes: 6 additions & 10 deletions internal/test/data/vector/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,12 @@ func GenSameValueVec(size int, val float32) []float32 {
// ConvertVectorsUint8ToFloat32 converts uint8 vectors and return float32 vectors
func ConvertVectorsUint8ToFloat32(vectors [][]uint8) (ret [][]float32) {
ret = make([][]float32, 0, len(vectors))
for _, v := range vectors {
ret = append(ret, convertVectorUint8ToFloat32(v))
}
return
}

func convertVectorUint8ToFloat32(vector []uint8) (ret []float32) {
ret = make([]float32, len(vector))
for i, e := range vector {
ret[i] = float32(e)
for _, vec := range vectors {
fvec := make([]float32, len(vec))
for i, v := range vec {
fvec[i] = float32(v)
}
ret = append(ret, fvec)
}
return
}
90 changes: 0 additions & 90 deletions internal/test/data/vector/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package vector

import (
"math"
"reflect"
"testing"

Expand Down Expand Up @@ -1093,95 +1092,6 @@ func TestConvertVectorsUint8ToFloat32(t *testing.T) {
if err := checkFunc(test.want, gotRet); err != nil {
tt.Errorf("error = %v", err)
}

})
}
}

func Test_convertVectorUint8ToFloat32(t *testing.T) {
type args struct {
vector []uint8
}
type want struct {
wantRet []float32
}
type test struct {
name string
args args
want want
checkFunc func(want, []float32) error
beforeFunc func(args)
afterFunc func(args)
}
defaultCheckFunc := func(w want, gotRet []float32) error {
if !reflect.DeepEqual(gotRet, w.wantRet) {
return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotRet, w.wantRet)
}
return nil
}
tests := []test{
{
name: "return float32 vector from uint8 vector",
args: args{
vector: []uint8{
1, 2, 3,
},
},
want: want{
wantRet: []float32{
1, 2, 3,
},
},
},
{
name: "return float32 vector from uint8 vector with min value",
args: args{
vector: []uint8{
0, 0, 0,
},
},
want: want{
wantRet: []float32{
0, 0, 0,
},
},
},
{
name: "return float32 vector from uint8 vector with max value",
args: args{
vector: []uint8{
math.MaxUint8, math.MaxUint8, math.MaxUint8,
},
},
want: want{
wantRet: []float32{
math.MaxUint8, math.MaxUint8, math.MaxUint8,
},
},
},
}

for _, tc := range tests {
test := tc
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
defer goleak.VerifyNone(tt, goleak.IgnoreCurrent())
if test.beforeFunc != nil {
test.beforeFunc(test.args)
}
if test.afterFunc != nil {
defer test.afterFunc(test.args)
}
checkFunc := test.checkFunc
if test.checkFunc == nil {
checkFunc = defaultCheckFunc
}

gotRet := convertVectorUint8ToFloat32(test.args.vector)
if err := checkFunc(test.want, gotRet); err != nil {
tt.Errorf("error = %v", err)
}

})
}
}

0 comments on commit b70cf9d

Please sign in to comment.