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

Function TestDurationComponents

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

Source from the content-addressed store, hash-verified

1449}
1450
1451func 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
1481func TestDurationFromUnits(t *testing.T) {
1482 tests := []struct {

Callers

nothing calls this directly

Calls 5

Float64Function · 0.92
NumberFunction · 0.92
DurationFunction · 0.92
EvalApplyFnFunction · 0.85
EqualsMethod · 0.65

Tested by

no test coverage detected