-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombine_test.go
76 lines (66 loc) · 1.74 KB
/
combine_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
package traces
import (
"testing"
)
type combineTestCase struct {
Vals []map[int64]int64
Sum map[int64]int64
Diff map[int64]int64
Any map[int64]int64
All map[int64]int64
}
var combineTestCases = []combineTestCase{
combineTestCase{
Vals: []map[int64]int64{},
Sum: map[int64]int64{},
Diff: map[int64]int64{},
Any: map[int64]int64{},
All: map[int64]int64{},
},
combineTestCase{
Vals: []map[int64]int64{
map[int64]int64{-5: 3, 0: 0, 123: 1},
map[int64]int64{-10: 1, 0: 2, 50: 0},
},
Sum: map[int64]int64{-10: 1, -5: 4, 0: 2, 50: 0, 123: 1},
Diff: map[int64]int64{-10: -1, -5: 2, 0: -2, 50: 0, 123: 1},
Any: map[int64]int64{-10: 1, 50: 0, 123: 1},
All: map[int64]int64{-10: 0, -5: 1, 0: 0},
},
}
func TestCombine(t *testing.T) {
for _, c := range combineTestCases {
list := make([]*Series, len(c.Vals))
for i, val := range c.Vals {
list[i] = NewSeriesData(val)
}
sum := Combine(Sum, list...)
expectedSum := NewSeriesData(c.Sum)
expectedSum.Compact()
assertConsistent(t, sum)
sum.Compact()
assertConsistent(t, sum)
assert(t, "Combine as sum", expectedSum, sum)
diff := Combine(Diff, list...)
expectedDiff := NewSeriesData(c.Diff)
expectedDiff.Compact()
assertConsistent(t, diff)
diff.Compact()
assertConsistent(t, diff)
assert(t, "Combine as diff", expectedDiff, diff)
any := Combine(Any, list...)
expectedAny := NewSeriesData(c.Any)
expectedAny.Compact()
assertConsistent(t, any)
any.Compact()
assertConsistent(t, any)
assert(t, "Combine as any", expectedAny, any)
all := Combine(All, list...)
expectedAll := NewSeriesData(c.All)
expectedAll.Compact()
assertConsistent(t, all)
all.Compact()
assertConsistent(t, all)
assert(t, "Combine as or", expectedAll, all)
}
}