-
Notifications
You must be signed in to change notification settings - Fork 5
/
change_test.go
40 lines (34 loc) · 944 Bytes
/
change_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
package change
import "testing"
func TestDetectChange(t *testing.T) {
var tests = []struct {
w []float64
idx int
}{
{
[]float64{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
0, // no change point found
},
{
[]float64{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
10, // the first 2
},
{
[]float64{1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 3, 0, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2},
0, // change occurs but not statistically significant
},
}
var detector = Detector{
MinSampleSize: 5,
}
for _, tt := range tests {
r := detector.Check(tt.w)
if (r == nil || r.Confidence < 0.95) && tt.idx == 0 {
// no difference found and no difference expected -- good
} else if r.Confidence >= 0.95 && r.Index == tt.idx {
// difference found at expected location -- good
} else {
t.Errorf("DetectChange confidence=%f index=%d, wanted %d", r.Confidence, r.Index, tt.idx)
}
}
}