github.com/go-graphite/carbonapi@v0.17.0/expr/functions/compressPeriodicGaps/function_test.go (about) 1 package compressPeriodicGaps 2 3 import ( 4 "math" 5 "testing" 6 7 "github.com/go-graphite/carbonapi/expr/interfaces" 8 "github.com/go-graphite/carbonapi/expr/metadata" 9 "github.com/go-graphite/carbonapi/expr/types" 10 "github.com/go-graphite/carbonapi/pkg/parser" 11 th "github.com/go-graphite/carbonapi/tests" 12 ) 13 14 var ( 15 md []interfaces.FunctionMetadata = New("") 16 ) 17 18 func init() { 19 for _, m := range md { 20 metadata.RegisterFunction(m.Name, m.F) 21 } 22 } 23 24 func TestCompressPeriodicGaps(t *testing.T) { 25 var startTime int64 = 100 26 27 tests := []th.EvalTestItemWithRange{ 28 { 29 Target: `compressPeriodicGaps(metric*)`, 30 M: map[parser.MetricRequest][]*types.MetricData{ 31 {Metric: "metric*", From: startTime, Until: startTime + 160}: { 32 types.MakeMetricData("metric1", []float64{math.NaN(), 1, math.NaN(), math.NaN(), 2, math.NaN(), math.NaN(), 3, math.NaN(), math.NaN(), 4, math.NaN(), math.NaN(), 5, math.NaN(), math.NaN()}, 10, startTime), 33 types.MakeMetricData("metric2", []float64{1, math.NaN(), math.NaN(), 2, math.NaN(), math.NaN(), 3, math.NaN(), math.NaN(), 4, math.NaN(), math.NaN(), 5, math.NaN(), math.NaN(), 6}, 10, startTime+10), 34 types.MakeMetricData("metric3", []float64{math.NaN(), math.NaN(), 1, math.NaN(), math.NaN(), 2, math.NaN(), math.NaN(), 3, math.NaN(), math.NaN(), 4, math.NaN(), math.NaN(), 5, math.NaN()}, 10, startTime), 35 types.MakeMetricData("metric4", []float64{math.NaN(), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, math.NaN()}, 10, startTime), 36 types.MakeMetricData("metric5", []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 10, startTime), 37 types.MakeMetricData("metric6", []float64{math.NaN(), 1, math.NaN(), 3, math.NaN(), 5, math.NaN(), 7, math.NaN(), 9, math.NaN(), 11, math.NaN(), 13, math.NaN(), 15}, 10, startTime), 38 types.MakeMetricData("metric7", []float64{math.NaN(), 1, 2, 3, math.NaN(), 5, math.NaN(), 7, math.NaN(), 9, math.NaN(), math.NaN(), math.NaN(), 13, math.NaN(), math.NaN()}, 10, startTime), 39 types.MakeMetricData("metric8", []float64{1, 2, 3, math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), 13, 14, 15}, 10, startTime), 40 }, 41 }, 42 Want: []*types.MetricData{ 43 types.MakeMetricData("compressPeriodicGaps(metric1)", []float64{1, 2, 3, 4, 5}, 30, startTime+10), 44 types.MakeMetricData("compressPeriodicGaps(metric2)", []float64{1, 2, 3, 4, 5, 6}, 30, startTime+10), 45 types.MakeMetricData("compressPeriodicGaps(metric3)", []float64{1, 2, 3, 4, 5}, 30, startTime+20), 46 types.MakeMetricData("compressPeriodicGaps(metric4)", []float64{math.NaN(), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, math.NaN()}, 10, startTime), 47 types.MakeMetricData("compressPeriodicGaps(metric5)", []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 10, startTime), 48 types.MakeMetricData("compressPeriodicGaps(metric6)", []float64{1, 3, 5, 7, 9, 11, 13, 15}, 20, startTime+10), 49 types.MakeMetricData("compressPeriodicGaps(metric7)", []float64{math.NaN(), 1, 2, 3, math.NaN(), 5, math.NaN(), 7, math.NaN(), 9, math.NaN(), math.NaN(), math.NaN(), 13, math.NaN(), math.NaN()}, 10, startTime), 50 types.MakeMetricData("compressPeriodicGaps(metric8)", []float64{1, 2, 3, math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), 13, 14, 15}, 10, startTime), 51 }, 52 From: startTime, 53 Until: 260, 54 }, 55 } 56 57 for _, tt := range tests { 58 testName := tt.Target 59 t.Run(testName, func(t *testing.T) { 60 eval := th.EvaluatorFromFunc(md[0].F) 61 th.TestEvalExprWithRange(t, eval, &tt) 62 }) 63 } 64 65 }