-
Notifications
You must be signed in to change notification settings - Fork 2
/
split_test.go
29 lines (22 loc) · 2.94 KB
/
split_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
package impact
import (
"testing"
"github.com/bmizerany/assert"
)
var (
mockLong = []float64{0.2819, -0.2685, -0.8953, -1.5097, 1.3481, 1.531, 2.8379, -1.4015, 0.6418, 0.6624, 0.0099, 1.0109, -0.4435, -0.82, -1.2299, -0.7309, 0.1284, 1.5323, 0.1371, -1.3134, -1.1574, 0.7684, -1.3807, 1.0011, 0.859, 0.5829, 1.6613, 0.9224, 0.3749, -0.2098, -0.4113, 1.5754, -0.5595, -1.1993, -0.115, 1.7752, -0.44, -0.8884, 0.0012, -1.3897, -1.1599, -1.3463, 0.6435, 0.1057, 0.6183, -0.1178, 0.4337, 0.0117, -1.4005, -0.4688, 0.8254, -0.4336, 0.2166, -1.4799, 0.1862, -0.1225, -0.7959, 0.619, 0.3448, -0.4218, -0.4955, 0.7085, 0.4557, 0.163, -0.9863, -1.1137, -0.2781, 0.89, -0.0805, -1.0104, -0.5461, 0.3711, 0.4303, 1.5358, -0.0145, 0.9244, 0.72, 0.2396, 0.3121, -0.5711, 1.7378, -1.0393, 2.8768, -1.1489, 2.8247, 0.6668, -2.4452, -0.2248, -1.4506, 0.2512, -0.6104, -0.7831, -0.9317, 0.9776, -0.2541, 0.3408, 1.9379, 0.435, 0.1587, -0.2107, 3.3023, 4.9829, 3.9371, 3.3873, 3.8503, 4.4646, 2.5079, 3.603, 2.902, 2.0079, 5.3926, 2.0144, 4.8468, 2.9475, 3.1235, 3.4594, 2.714, 1.4039, 5.7932, 2.8378, 3.6907, 2.8599, 0.8576, 3.1705, 1.9901, 3.2576, 2.1397, 2.0252, 2.0436, 2.2332, 2.5238, 3.6306, 2.2374, 3.9664, 4.5682, 2.0718, 3.4245, 3.8075, 2.8893, 4.7976, 2.2743, 3.2846, 2.5925, 2.158, 5.356, 3.1835, 2.7202, 2.8468, 1.0398, 3.3804, 6.2629, 3.5585, 2.7804, 4.4909, 2.997, 2.3899, 3.3283, 2.4281, 3.1302, 1.796, 2.4216, 4.5802, 1.9428, 2.2514, 2.543, 3.302, 4.4632, 2.7864, 3.8564, 2.2068, 4.9702, 2.9449, 3.404, 2.3057, 2.6701, 4.383, 2.4721, 2.3338, 3.3218, 3.5748, 2.5871, 3.1313, 2.1113, 3.4409, 3.6108, 1.8909, 0.7175, 2.7964, 2.9346, 2.4974, 3.2543, 3.6477, 2.2657, 2.7274, 4.4656, 3.1189, 2.2356, 3.1112, 2.0153, 3.8531, -2.2742, 0.5466, -3.5621, 0.5682, 0.0692, -0.4327, -1.0646, -1.547, -0.0711, -3.0897, -1.8727, 3.7229, 0.7642, 0.1332, 0.9649, -1.7761, -2.9089, 1.3173, 2.0166, 0.1236, 0.1901, 1.0666, 1.015, 2.2579, 0.5469, 0.4192, 2.5579, 0.2985, -0.4318, -0.2802, -3.4489, 1.8516, -0.2341, -1.4547, 0.1322, -1.1368, 1.92, 1.3704, -2.1235, -2.4244, -1.8488, 1.446, 1.4911, 3.3764, 0.002, 2.6589, -0.1781, 1.6332, 3.0993, 0.4452, 1.9963, -1.0558, 2.4251, 1.7624, -0.9189, 1.2277, -0.4107, -0.7209, -1.2883, -0.2033, -1.035, 2.1153, -0.4164, 1.4586, -0.4343, -1.2503, 0.3594, 1.7229, 1.0777, -1.6411, 1.1449, 1.0892, 0.6068, 1.109, -1.7486, 3.4536, -1.7635, 1.3976, -3.5496, -4.0665, -1.624, -0.1121, 1.2669, -1.4786, 1.4366, 0.0345, 0.5709, -0.4645, 0.6889, 1.1458, 2.628, 3.8735, -1.2663, 1.1235, 1.2226, -2.4448, 1.5101, -1.2581, -2.268, 1.6008}
)
func TestChangepoints(t *testing.T) {
sig := 0.05
R := 99
minSize := 30
changes, err := DetectChanges(mockLong, sig, R, minSize)
assert.Equal(t, nil, err)
assert.Equalf(t, []int{0, 100, 200, 300}, changes, "incorrect changepoint detection")
}
// the the accuracy of a single split
func TestSplit(t *testing.T) {
d := vectorDistance(mockLong)
split := splitPoint(0, 299, d, 30)
assert.Equalf(t, 100, split.Index, "incorrect series split")
}