浏览代码

move normalize test

Roy Han 10 月之前
父节点
当前提交
95e46eeedf
共有 2 个文件被更改,包括 36 次插入41 次删除
  1. 0 41
      server/normalize_test.go
  2. 36 0
      server/routes_test.go

+ 0 - 41
server/normalize_test.go

@@ -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)
-			}
-		})
-	}
-}

+ 36 - 0
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)
+			}
+		})
+	}
+}