@@ -11,25 +11,6 @@ import (
11
11
12
12
func TestSimpleReducer (t * testing.T ) {
13
13
Convey ("Test simple reducer by calculating" , t , func () {
14
- Convey ("avg" , func () {
15
- result := testReducer ("avg" , 1 , 2 , 3 )
16
- So (result , ShouldEqual , float64 (2 ))
17
- })
18
-
19
- Convey ("avg of none null data" , func () {
20
- reducer := NewSimpleReducer ("avg" )
21
- series := & tsdb.TimeSeries {
22
- Name : "test time serie" ,
23
- }
24
-
25
- series .Points = append (series .Points , tsdb .NewTimePoint (null .FloatFrom (3 ), 1 ))
26
- series .Points = append (series .Points , tsdb .NewTimePoint (null .FloatFromPtr (nil ), 2 ))
27
- series .Points = append (series .Points , tsdb .NewTimePoint (null .FloatFromPtr (nil ), 3 ))
28
- series .Points = append (series .Points , tsdb .NewTimePoint (null .FloatFrom (3 ), 4 ))
29
-
30
- So (reducer .Reduce (series ).Float64 , ShouldEqual , float64 (3 ))
31
- })
32
-
33
14
Convey ("sum" , func () {
34
15
result := testReducer ("sum" , 1 , 2 , 3 )
35
16
So (result , ShouldEqual , float64 (6 ))
@@ -69,6 +50,25 @@ func TestSimpleReducer(t *testing.T) {
69
50
result := testReducer ("median" , 1 )
70
51
So (result , ShouldEqual , float64 (1 ))
71
52
})
53
+
54
+ Convey ("avg" , func () {
55
+ result := testReducer ("avg" , 1 , 2 , 3 )
56
+ So (result , ShouldEqual , float64 (2 ))
57
+ })
58
+
59
+ Convey ("avg of number values and null values should ignore nulls" , func () {
60
+ reducer := NewSimpleReducer ("avg" )
61
+ series := & tsdb.TimeSeries {
62
+ Name : "test time serie" ,
63
+ }
64
+
65
+ series .Points = append (series .Points , tsdb .NewTimePoint (null .FloatFrom (3 ), 1 ))
66
+ series .Points = append (series .Points , tsdb .NewTimePoint (null .FloatFromPtr (nil ), 2 ))
67
+ series .Points = append (series .Points , tsdb .NewTimePoint (null .FloatFromPtr (nil ), 3 ))
68
+ series .Points = append (series .Points , tsdb .NewTimePoint (null .FloatFrom (3 ), 4 ))
69
+
70
+ So (reducer .Reduce (series ).Float64 , ShouldEqual , float64 (3 ))
71
+ })
72
72
})
73
73
}
74
74
0 commit comments