-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
112 lines (87 loc) · 1.87 KB
/
main.go
File metadata and controls
112 lines (87 loc) · 1.87 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
"time"
)
var (
extentions = map[string]string{
"py": "python3",
"js": "node",
"ex": "elixir",
"cpp": "gcc",
"go": "go",
"java": "java",
}
testCases []testCase
)
type testCase struct {
Args []string `json:"args"`
Truth string `json:"truth"`
}
func init() {
jsonFile, err := os.Open("sample_test_case.json")
defer jsonFile.Close()
if err != nil {
panic(err)
}
scanner := bufio.NewScanner(jsonFile)
for scanner.Scan() {
var test testCase
json.Unmarshal([]byte(scanner.Text()), &test)
testCases = append(testCases, test)
}
if err != nil {
fmt.Println(err)
}
fmt.Println(testCases)
fmt.Println(len(testCases))
}
func main() {
cwd, _ := os.Getwd()
files, _ := ioutil.ReadDir(fmt.Sprintf("%s/submissions", cwd))
for _, file := range files {
fn := fmt.Sprintf("submissions/%s", file.Name())
cmnd := GetFileCommand(file.Name())
var failed bool
start := time.Now()
for _, testcase := range testCases {
c := exec.Command(cmnd)
if cmnd == "go" {
c.Args = append(c.Args, "run")
c.Args = append(c.Args, fn)
} else {
c.Args = append(c.Args, fn)
}
args := testcase.Args
truth := testcase.Truth
for _, arg := range args {
c.Args = append(c.Args, arg)
}
out, err := c.Output()
if err != nil {
fmt.Println(err)
}
resp := strings.ToLower(strings.Replace(string(out), "\n", "", -1))
if resp != truth {
failed = true
fmt.Printf("testcase: %v truth: %s found: %s\n", args, truth, resp)
break
}
}
if failed == true {
fmt.Printf("%v failed! %v\n", fn, time.Now().Sub(start))
} else {
fmt.Printf("%v correct! %v\n", fn, time.Now().Sub(start))
}
}
}
func GetFileCommand(filename string) string {
s := strings.Split(filename, ".")
return extentions[s[len(s)-1]]
}