From b70cf9d07e00580eb52f094e701b92f8bbaae008 Mon Sep 17 00:00:00 2001 From: kevindiu Date: Wed, 1 Jun 2022 17:46:55 +0900 Subject: [PATCH] fix comment Signed-off-by: kevindiu --- internal/conv/conv_test.go | 18 +++++ internal/test/data/request/insert_test.go | 12 ++- internal/test/data/vector/gen.go | 16 ++-- internal/test/data/vector/gen_test.go | 90 ----------------------- 4 files changed, 29 insertions(+), 107 deletions(-) diff --git a/internal/conv/conv_test.go b/internal/conv/conv_test.go index c91d4904fbc..4495cdeecbf 100644 --- a/internal/conv/conv_test.go +++ b/internal/conv/conv_test.go @@ -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 { @@ -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 { diff --git a/internal/test/data/request/insert_test.go b/internal/test/data/request/insert_test.go index 3ded576b113..a1ec1f2c309 100644 --- a/internal/test/data/request/insert_test.go +++ b/internal/test/data/request/insert_test.go @@ -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 { diff --git a/internal/test/data/vector/gen.go b/internal/test/data/vector/gen.go index 2c3e0b3dfa6..54017826105 100644 --- a/internal/test/data/vector/gen.go +++ b/internal/test/data/vector/gen.go @@ -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 } diff --git a/internal/test/data/vector/gen_test.go b/internal/test/data/vector/gen_test.go index 637ae1199d5..6177ee59856 100644 --- a/internal/test/data/vector/gen_test.go +++ b/internal/test/data/vector/gen_test.go @@ -16,7 +16,6 @@ package vector import ( - "math" "reflect" "testing" @@ -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) - } - }) } }