All checks were successful
Deploy to K8s / deploy (push) Successful in 6s
Ports calculate_fee and calculate_junior_fee from scripts/attendance.py into a new go/internal/domain/fees package. Introduces the Expected type (Value int, Unknown bool) for the junior "?" sentinel, keeping the Go API strictly typed instead of mirroring Python's str|int return. All 20 table-driven tests pass with -race; golangci-lint clean. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
38 lines
1.4 KiB
Go
38 lines
1.4 KiB
Go
package fees
|
|
|
|
import "testing"
|
|
|
|
func TestCalculateJuniorFee(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// All expected outputs verified against live Python implementation on 2026-05-06:
|
|
// PYTHONPATH=scripts:. python -c 'from attendance import calculate_junior_fee; print([calculate_junior_fee(c,m) for c,m in [(0,"2026-05"),(0,""),(1,"2026-05"),(1,"unknown"),(2,"2026-05"),(2,"2025-09"),(2,"2026-03"),(5,"2025-09"),(2,"2027-01"),(2,"")]])'
|
|
tests := []struct {
|
|
name string
|
|
count int
|
|
month string
|
|
want Expected
|
|
}{
|
|
{"zero short-circuits", 0, "2026-05", Expected{Value: 0}},
|
|
{"zero empty month", 0, "", Expected{Value: 0}},
|
|
{"single practice sentinel", 1, "2026-05", Expected{Unknown: true}},
|
|
{"single ignores monthKey", 1, "unknown", Expected{Unknown: true}},
|
|
{"two practices default month", 2, "2026-05", Expected{Value: 500}},
|
|
{"two practices reduced sept", 2, "2025-09", Expected{Value: 250}},
|
|
{"two practices reduced march", 2, "2026-03", Expected{Value: 250}},
|
|
{"high count same as two", 5, "2025-09", Expected{Value: 250}},
|
|
{"unknown future month falls back", 2, "2027-01", Expected{Value: 500}},
|
|
{"empty month falls back", 2, "", Expected{Value: 500}},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
got := CalculateJuniorFee(tc.count, tc.month)
|
|
if got != tc.want {
|
|
t.Errorf("CalculateJuniorFee(%d, %q) = %+v, want %+v", tc.count, tc.month, got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|