Skip to content

Commit 32a8c02

Browse files
committed
add judge skeleton
1 parent 1f6fc48 commit 32a8c02

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

commands/run.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package commands
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"strings"
7+
8+
"github.com/urfave/cli/v2"
9+
)
10+
11+
// Checks the output of a given testcase against it's expected output
12+
type Checker interface {
13+
// Execute the check (got, expected) and returns
14+
// nil if the output match, otherwise an error with a description message.
15+
Check(string, string) error
16+
}
17+
18+
// Default implementation of the Checker interface.
19+
type DiffChecker struct {
20+
}
21+
22+
func (c *DiffChecker) Check(got, expected string) error {
23+
// Compre the trimmed output from both input and output
24+
if strings.Trim(got, " \t\n\r") != strings.Trim(expected, " \t\n\r") {
25+
return errors.New(fmt.Sprintf("Checker failed, expected %s, found %s", got, expected))
26+
}
27+
return nil
28+
}
29+
30+
// Case description contains minimum information required to run one test case.
31+
type CaseDescription struct {
32+
InputFile string
33+
OutputFile string
34+
CustomCase bool
35+
}
36+
37+
// Report the execution status for a given testcase.
38+
// Type also stores the compiler output, and the checker response
39+
type CaseStatus struct {
40+
}
41+
42+
// Implementation must be able to prepare the working environement to compile and execute testscases,
43+
// And run each testcase and report the status back to the invoker, and perform any necessary cleanup (binaries created, directories created ...)
44+
type Judge interface {
45+
// setup the working directory and perform any necessary compilation of the task
46+
// if the setup returned an error, the Judge should abort the operation and report the error back.
47+
Setup() error
48+
49+
// Run on every testcase, and the status is reported back to the invoker.
50+
// The implementation is free to Run all testcases at once, or report every testcase execution status once it finishes.
51+
// If it's needed, running independent cases can be done on different go routines.
52+
RunTestCase(CaseDescription) CaseStatus
53+
54+
// Cleanup the working directory, if an error occured, implementation must report it to the caller.
55+
Cleanup() error
56+
}
57+
58+
func RunAction(context *cli.Context) error {
59+
return nil
60+
}
61+
62+
var RunCommand = cli.Command{
63+
Name: "run",
64+
Aliases: []string{"r"},
65+
Usage: "Run the current task testcases",
66+
UsageText: "Run the current task testcases",
67+
Action: RunAction,
68+
}

commands/run_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package commands
2+
3+
import "testing"
4+
5+
func TestNothing(t *testing.T) {
6+
// NO-OP
7+
}

0 commit comments

Comments
 (0)