(t *testing.T)
| 1449 | } |
| 1450 | |
| 1451 | func TestDurationComponents(t *testing.T) { |
| 1452 | // 2 hours, 30 minutes, 45 seconds = 9045 seconds total |
| 1453 | // = 9045 * 1e9 nanoseconds |
| 1454 | nanos := int64(9045000000000) |
| 1455 | |
| 1456 | tests := []struct { |
| 1457 | name string |
| 1458 | fn ast.FunctionSym |
| 1459 | want ast.Constant |
| 1460 | }{ |
| 1461 | {"hours", symbols.DurationHours, ast.Float64(2.5125)}, // 9045/3600 = 2.5125 |
| 1462 | {"minutes", symbols.DurationMinutes, ast.Float64(150.75)}, // 9045/60 = 150.75 |
| 1463 | {"seconds", symbols.DurationSeconds, ast.Float64(9045)}, |
| 1464 | {"nanos", symbols.DurationNanos, ast.Number(nanos)}, |
| 1465 | } |
| 1466 | |
| 1467 | for _, test := range tests { |
| 1468 | t.Run(test.name, func(t *testing.T) { |
| 1469 | expr := ast.ApplyFn{test.fn, []ast.BaseTerm{ast.Duration(nanos)}} |
| 1470 | got, err := EvalApplyFn(expr, ast.ConstSubstMap{}) |
| 1471 | if err != nil { |
| 1472 | t.Fatalf("EvalApplyFn(%v) failed with %v", expr, err) |
| 1473 | } |
| 1474 | if !got.Equals(test.want) { |
| 1475 | t.Errorf("EvalApplyFn(%v) = %v, want %v", expr, got, test.want) |
| 1476 | } |
| 1477 | }) |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | func TestDurationFromUnits(t *testing.T) { |
| 1482 | tests := []struct { |
nothing calls this directly
no test coverage detected