diff --git a/server/normalize_test.go b/server/normalize_test.go deleted file mode 100644 index f774e42d0..000000000 --- a/server/normalize_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package server - -import ( - "math" - "testing" -) - -func TestNormalize(t *testing.T) { - type testCase struct { - input []float32 - } - - testCases := []testCase{ - {input: []float32{1}}, - {input: []float32{0, 1, 2, 3}}, - {input: []float32{0.1, 0.2, 0.3}}, - {input: []float32{-0.1, 0.2, 0.3, -0.4}}, - {input: []float32{0, 0, 0}}, - } - - assertNorm := func(vec []float32) (res bool) { - sum := 0.0 - for _, v := range vec { - sum += float64(v * v) - } - if math.Abs(sum-1) > 1e-6 { - return sum == 0 - } else { - return true - } - } - - for _, tc := range testCases { - t.Run("", func(t *testing.T) { - normalized := normalize(tc.input) - if !assertNorm(normalized) { - t.Errorf("Vector %v is not normalized", tc.input) - } - }) - } -} diff --git a/server/routes_test.go b/server/routes_test.go index 5e16cfeff..cddcb0d06 100644 --- a/server/routes_test.go +++ b/server/routes_test.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "io" + "math" "net/http" "net/http/httptest" "os" @@ -325,3 +326,38 @@ func TestCase(t *testing.T) { }) } } + +func TestNormalize(t *testing.T) { + type testCase struct { + input []float32 + } + + testCases := []testCase{ + {input: []float32{1}}, + {input: []float32{0, 1, 2, 3}}, + {input: []float32{0.1, 0.2, 0.3}}, + {input: []float32{-0.1, 0.2, 0.3, -0.4}}, + {input: []float32{0, 0, 0}}, + } + + assertNorm := func(vec []float32) (res bool) { + sum := 0.0 + for _, v := range vec { + sum += float64(v * v) + } + if math.Abs(sum-1) > 1e-6 { + return sum == 0 + } else { + return true + } + } + + for _, tc := range testCases { + t.Run("", func(t *testing.T) { + normalized := normalize(tc.input) + if !assertNorm(normalized) { + t.Errorf("Vector %v is not normalized", tc.input) + } + }) + } +}