-
Notifications
You must be signed in to change notification settings - Fork 14
/
numerical_test.go
53 lines (44 loc) · 1.18 KB
/
numerical_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
package aggregation
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSimpleNumericalAggregation(t *testing.T) {
aggr := NewNumericalAggregator(&NumericalConfig{
KeepValuesForAnalysis: true,
})
aggr.Samplef(5)
aggr.Samplef(10)
aggr.Samplef(15)
assert.Equal(t, uint64(3), aggr.Count())
assert.Equal(t, 10.0, aggr.Mean())
assert.Equal(t, 5.0, aggr.Min())
assert.Equal(t, 15.0, aggr.Max())
assert.InEpsilon(t, 5.0, aggr.StdDev(), 0.001)
data := aggr.Analyze()
assert.Equal(t, 10.0, data.Median())
assert.Equal(t, 10.0, data.Quantile(0.5))
assert.Equal(t, 5.0, data.Mode())
}
func TestSimpleMode(t *testing.T) {
aggr := NewNumericalAggregator(&NumericalConfig{
KeepValuesForAnalysis: true,
})
aggr.Samplef(5)
aggr.Samplef(10)
aggr.Samplef(15)
aggr.Samplef(5)
aggr.Samplef(10)
aggr.Samplef(5)
data := aggr.Analyze()
assert.Equal(t, 5.0, data.Mode())
assert.Equal(t, 15.0, data.Quantile(0.9))
}
func TestSampleString(t *testing.T) {
aggr := NewNumericalAggregator(&NumericalConfig{})
aggr.Sample("abc")
assert.Equal(t, uint64(1), aggr.ParseErrors())
aggr.Sample("100.1")
assert.Equal(t, uint64(1), aggr.Count())
assert.Equal(t, 100.1, aggr.Mean())
}