-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaggregation_test.go
More file actions
82 lines (77 loc) · 1.55 KB
/
aggregation_test.go
File metadata and controls
82 lines (77 loc) · 1.55 KB
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
package itt
import (
"math"
"testing"
)
func TestAggMean(t *testing.T) {
tests := []struct {
input []float64
expected float64
}{
{nil, 0},
{[]float64{}, 0},
{[]float64{5}, 5},
{[]float64{1, 2, 3, 4, 5}, 3},
{[]float64{0, 10}, 5},
}
for _, tt := range tests {
got := AggMean(tt.input)
if math.Abs(got-tt.expected) > 1e-10 {
t.Errorf("AggMean(%v) = %f, want %f", tt.input, got, tt.expected)
}
}
}
func TestAggMax(t *testing.T) {
tests := []struct {
input []float64
expected float64
}{
{nil, 0},
{[]float64{}, 0},
{[]float64{5}, 5},
{[]float64{1, 3, 2}, 3},
{[]float64{-1, -5, -2}, -1},
}
for _, tt := range tests {
got := AggMax(tt.input)
if math.Abs(got-tt.expected) > 1e-10 {
t.Errorf("AggMax(%v) = %f, want %f", tt.input, got, tt.expected)
}
}
}
func TestAggMedian(t *testing.T) {
tests := []struct {
input []float64
expected float64
}{
{nil, 0},
{[]float64{}, 0},
{[]float64{5}, 5},
{[]float64{1, 3}, 2},
{[]float64{3, 1, 2}, 2},
{[]float64{4, 1, 3, 2}, 2.5},
}
for _, tt := range tests {
got := AggMedian(tt.input)
if math.Abs(got-tt.expected) > 1e-10 {
t.Errorf("AggMedian(%v) = %f, want %f", tt.input, got, tt.expected)
}
}
}
func TestAggSum(t *testing.T) {
tests := []struct {
input []float64
expected float64
}{
{nil, 0},
{[]float64{}, 0},
{[]float64{5}, 5},
{[]float64{1, 2, 3}, 6},
}
for _, tt := range tests {
got := AggSum(tt.input)
if math.Abs(got-tt.expected) > 1e-10 {
t.Errorf("AggSum(%v) = %f, want %f", tt.input, got, tt.expected)
}
}
}