forked from go-gota/gota
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrolling_window_test.go
85 lines (78 loc) · 1.64 KB
/
rolling_window_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package series
import (
"math"
"strings"
"testing"
)
func TestSeries_RollingMean(t *testing.T) {
tests := []struct {
window int
series Series
expected Series
}{
{
3,
Ints([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
Floats([]float64{math.NaN(), math.NaN(), 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}),
},
{
2,
Floats([]float64{1.0, 2.0, 3.0}),
Floats([]float64{math.NaN(), 1.5, 2.5}),
},
{
0,
Floats([]float64{}),
Floats([]float64{}),
},
}
for testnum, test := range tests {
expected := test.expected
received := test.series.Rolling(test.window).Mean()
for i := 0; i < expected.Len(); i++ {
if strings.Compare(expected.Elem(i).String(),
received.Elem(i).String()) != 0 {
t.Errorf(
"Test:%v\nExpected:\n%v\nReceived:\n%v",
testnum, expected, received,
)
}
}
}
}
func TestSeries_RollingStdDev(t *testing.T) {
tests := []struct {
window int
series Series
expected Series
}{
{
3,
Ints([]int{5, 5, 6, 7, 5, 5, 5}),
Floats([]float64{math.NaN(), math.NaN(), 0.5773502691896257, 1.0, 1.0, 1.1547005383792515, 0.0}),
},
{
2,
Floats([]float64{1.0, 2.0, 3.0}),
Floats([]float64{math.NaN(), 0.7071067811865476, 0.7071067811865476}),
},
{
0,
Floats([]float64{}),
Floats([]float64{}),
},
}
for testnum, test := range tests {
expected := test.expected
received := test.series.Rolling(test.window).StdDev()
for i := 0; i < expected.Len(); i++ {
if strings.Compare(expected.Elem(i).String(),
received.Elem(i).String()) != 0 {
t.Errorf(
"Test:%v\nExpected:\n%v\nReceived:\n%v",
testnum, expected, received,
)
}
}
}
}