-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_yaml.go
57 lines (46 loc) · 1.33 KB
/
task_yaml.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package checker
import (
"bytes"
"fmt"
"github.com/mraron/njudge/pkg/language/runner"
"github.com/mraron/njudge/pkg/problems"
)
// TaskYAML checker format is used by CMS as described in
// the CMS documentation's [Checker] and [Standard manager output] sections.
//
// [Checker]: https://cms.readthedocs.io/en/v1.4/Task%20types.html#checker
// [Standard manager output]: https://cms.readthedocs.io/en/v1.4/Task%20types.html#standard-manager-output
type TaskYAML struct {
path string
executable runner.Executable
}
func NewTaskYAML(path string) *TaskYAML {
return &TaskYAML{
path: path,
executable: runner.NewStdlib(path),
}
}
func (t *TaskYAML) Name() string {
return "taskyaml"
}
func (t *TaskYAML) Check(tc *problems.Testcase) error {
stdout, stderr := bytes.Buffer{}, bytes.Buffer{}
t.executable.Stdout(&stdout)
t.executable.Stderr(&stderr)
if err := t.executable.Run([]string{tc.InputPath, tc.AnswerPath, tc.OutputPath}); err != nil {
return fmt.Errorf("can't check task_yaml task: %w", err)
}
if _, err := fmt.Fscanf(&stdout, "%f", &tc.Score); err != nil {
return err
}
if tc.Score == 1.0 {
tc.VerdictName = problems.VerdictAC
} else if tc.Score > 0 {
tc.VerdictName = problems.VerdictPC
} else {
tc.VerdictName = problems.VerdictWA
}
tc.Score *= tc.MaxScore
tc.CheckerOutput = stderr.String()
return nil
}