grade.gno
1.09 Kb · 48 lines
1package gauntlet
2
3// Report is the result of grading one solution.
4type Report struct {
5 Passed int
6 Total int
7 // Details of the first failing test, if any.
8 FailIn string
9 FailGot string
10 FailWant string
11}
12
13// OK reports whether every test passed.
14func (r Report) OK() bool { return r.Total > 0 && r.Passed == r.Total }
15
16// GradeCases runs solve against fixed cases. It stops at the first failure:
17// a solution either passes everything or it does not.
18func GradeCases(cases []Case, solve Solver) Report {
19 r := Report{Total: len(cases)}
20 for _, c := range cases {
21 got := solve(c.In)
22 if got != c.Want {
23 r.FailIn, r.FailGot, r.FailWant = c.In, got, c.Want
24 return r
25 }
26 r.Passed++
27 }
28 return r
29}
30
31// GradeJudge runs solve against inputs generated from seed and checked by the
32// judge.
33func GradeJudge(j *Judge, seed uint64, solve Solver) Report {
34 ins := j.Inputs(seed)
35 if len(ins) > MaxCases {
36 ins = ins[:MaxCases]
37 }
38 r := Report{Total: len(ins)}
39 for _, in := range ins {
40 got := solve(in)
41 if !j.Check(in, got) {
42 r.FailIn, r.FailGot = in, got
43 return r
44 }
45 r.Passed++
46 }
47 return r
48}