-
Notifications
You must be signed in to change notification settings - Fork 4
/
wheel_test.go
65 lines (61 loc) · 1.37 KB
/
wheel_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"testing"
"time"
)
func TestWheelNormalizer(t *testing.T) {
interval := 10 * time.Millisecond
testCases := map[string]struct {
pre []float64
input []float64
expected []float64
tolerance float64
}{
"BinaryWheel1": {
pre: []float64{1, 1, -1, 0, -1, -1},
input: []float64{1, -1, 0},
expected: []float64{1, -1, 0},
},
"BinaryWheel10": {
pre: []float64{10, 10, -10, 0, -10, -10},
input: []float64{10, -10, 0},
expected: []float64{1, -1, 0},
},
"AnalogWheel3": {
pre: []float64{2, 4, 3, 0, -1, 2},
input: []float64{3, -2, 0},
expected: []float64{3, -2, 0},
tolerance: 1,
},
"AnalogWheel30": {
pre: []float64{20, 40, 30, 0, -10, 20},
input: []float64{30, -20, 0},
expected: []float64{3, -2, 0},
tolerance: 1,
},
}
for name, tt := range testCases {
tt := tt
t.Run(name, func(t *testing.T) {
wn := &wheelNormalizer{}
tick := time.NewTicker(interval)
defer tick.Stop()
for _, v := range tt.pre {
<-tick.C
wn.Normalize(v)
}
for i, v := range tt.input {
<-tick.C
o, ok := wn.Normalize(v)
if !ok {
t.Error("Normalizer should be ready")
continue
}
if o < tt.expected[i]-tt.tolerance || tt.expected[i]+tt.tolerance < o {
t.Errorf("Expected: %f, got: %f", tt.expected[i], o)
continue
}
}
})
}
}