MCPcopy
hub / github.com/google/mangle / TestReducerFloatMinMaxSum

Function TestReducerFloatMinMaxSum

functional/functional_test.go:334–385  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

332}
333
334func TestReducerFloatMinMaxSum(t *testing.T) {
335 tests := []struct {
336 rows [][]ast.Constant
337 wantMin ast.Constant
338 wantMax ast.Constant
339 wantSum ast.Constant
340 }{
341 {
342 rows: [][]ast.Constant{
343 {ast.Float64(1.0)},
344 {ast.Float64(1.1)},
345 {ast.Float64(3.0)},
346 },
347 wantMin: ast.Float64(1.0),
348 wantMax: ast.Float64(3.0),
349 wantSum: ast.Float64(5.1),
350 },
351 {
352 rows: nil,
353 wantMin: ast.Float64(math.MaxFloat64),
354 wantMax: ast.Float64(-1 * math.MaxFloat64),
355 wantSum: ast.Float64(0.0),
356 },
357 }
358 for _, test := range tests {
359 var rows []ast.ConstSubstList
360 for _, row := range test.rows {
361 rows = append(rows, makeConstSubstList([]ast.Variable{ast.Variable{"X"}}, row))
362 }
363 gotMax, err := EvalReduceFn(ast.ApplyFn{symbols.FloatMax, []ast.BaseTerm{ast.Variable{"X"}}}, rows)
364 if err != nil {
365 t.Fatalf("EvalReduceFn(FloatMax,%v) failed with %v", rows, err)
366 }
367 if test.wantMax != gotMax {
368 t.Errorf("EvalReduceFn(FloatMax, %v)=%v want %v", rows, gotMax, test.wantMax)
369 }
370 gotMin, err := EvalReduceFn(ast.ApplyFn{symbols.FloatMin, []ast.BaseTerm{ast.Variable{"X"}}}, rows)
371 if err != nil {
372 t.Fatalf("EvalReduceFn(FloatMin,%v) failed with %v", rows, err)
373 }
374 if test.wantMin != gotMin {
375 t.Errorf("EvalReduceFn(FloatMin, %v)=%v want %v", rows, gotMin, test.wantMin)
376 }
377 gotSum, err := EvalReduceFn(ast.ApplyFn{symbols.FloatSum, []ast.BaseTerm{ast.Variable{"X"}}}, rows)
378 if err != nil {
379 t.Fatalf("EvalReduceFn(FloatSum, %v) failed with %v", rows, err)
380 }
381 if test.wantSum != gotSum {
382 t.Errorf("EvalReduceFn(FloatSum, %v)=%v want %v", rows, gotSum, test.wantSum)
383 }
384 }
385}
386
387func pair(a, b ast.Constant) *ast.Constant {
388 p := ast.Pair(&a, &b)

Callers

nothing calls this directly

Calls 3

Float64Function · 0.92
makeConstSubstListFunction · 0.85
EvalReduceFnFunction · 0.85

Tested by

no test coverage detected