-
Notifications
You must be signed in to change notification settings - Fork 6
/
mrpt_test.go
49 lines (41 loc) · 971 Bytes
/
mrpt_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package ann
import (
"reflect"
"testing"
)
func TestMRPTNNer(t *testing.T) {
nn := NewMRPTANNer(1, 3, [][]float64{
[]float64{0, 0, 0, 0},
[]float64{1.1, 1.1, 1.1, 1.1},
[]float64{2, 2, 2, 2},
[]float64{-1, 1, 2, 2},
[]float64{2, 2, -1, 2},
[]float64{2, 3, 2, -4},
[]float64{-2, -3, 2, -4},
[]float64{-2, -3, -2, 4},
})
q := []float64{1, 1, 1, 1}
indices := nn.ANN(q, 1)
// Should be closest to vector #1
expectedIndices := []int{1}
if !reflect.DeepEqual(indices, expectedIndices) {
t.Fatalf("expected nn to be %v, got indices %v", expectedIndices, indices)
}
}
func TestMedian(t *testing.T) {
type testCase struct {
vs []float64
m float64
}
testCases := []testCase{
testCase{vs: []float64{1}, m: 1},
testCase{vs: []float64{1, 2, 3}, m: 2},
testCase{vs: []float64{1, 2, 3, 4}, m: 2.5},
}
for _, tc := range testCases {
m := median(tc.vs)
if m != tc.m {
t.Fatalf("wrong median: %f, expected %f", m, tc.m)
}
}
}