Skip to content

Commit 2bdd2a5

Browse files
committed
test(alerting): improve naming for test scenario
1 parent e082d78 commit 2bdd2a5

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

pkg/services/alerting/conditions/reducer_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,6 @@ import (
1111

1212
func TestSimpleReducer(t *testing.T) {
1313
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-
3314
Convey("sum", func() {
3415
result := testReducer("sum", 1, 2, 3)
3516
So(result, ShouldEqual, float64(6))
@@ -69,6 +50,25 @@ func TestSimpleReducer(t *testing.T) {
6950
result := testReducer("median", 1)
7051
So(result, ShouldEqual, float64(1))
7152
})
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+
})
7272
})
7373
}
7474

0 commit comments

Comments
 (0)