github.com/go-graphite/carbonapi@v0.17.0/expr/functions/pow/function_test.go (about) 1 package pow 2 3 import ( 4 "math" 5 "testing" 6 "time" 7 8 "github.com/go-graphite/carbonapi/expr/interfaces" 9 "github.com/go-graphite/carbonapi/expr/metadata" 10 "github.com/go-graphite/carbonapi/expr/types" 11 "github.com/go-graphite/carbonapi/pkg/parser" 12 th "github.com/go-graphite/carbonapi/tests" 13 ) 14 15 var ( 16 md []interfaces.FunctionMetadata = New("") 17 ) 18 19 func init() { 20 for _, m := range md { 21 metadata.RegisterFunction(m.Name, m.F) 22 } 23 } 24 25 func TestFunction(t *testing.T) { 26 now32 := int64(time.Now().Unix()) 27 28 tests := []th.EvalTestItem{ 29 { 30 "pow(metric1,3)", 31 map[parser.MetricRequest][]*types.MetricData{ 32 {Metric: "metric1", From: 0, Until: 1}: {types.MakeMetricData("metric1", []float64{5, 1, math.NaN(), 0, 12, 125, 10.4, 1.1}, 60, now32)}, 33 }, 34 []*types.MetricData{types.MakeMetricData("pow(metric1,3)", []float64{125, 1, math.NaN(), 0, 1728, 1953125, 1124.864, 1.331}, 60, now32).SetTag("pow", "3")}, 35 }, 36 { 37 "pow(metric1,0)", 38 map[parser.MetricRequest][]*types.MetricData{ 39 {Metric: "metric1", From: 0, Until: 1}: {types.MakeMetricData("metric1", []float64{math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 60, now32)}, 40 }, 41 []*types.MetricData{types.MakeMetricData("pow(metric1,0)", []float64{math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN(), math.NaN()}, 60, now32).SetTag("pow", "0")}, 42 }, 43 } 44 45 for _, tt := range tests { 46 testName := tt.Target 47 t.Run(testName, func(t *testing.T) { 48 eval := th.EvaluatorFromFunc(md[0].F) 49 th.TestEvalExpr(t, eval, &tt) 50 }) 51 } 52 53 }