-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevaluator.go
50 lines (44 loc) · 1.39 KB
/
evaluator.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
package main
import (
"io/ioutil"
"log"
"os"
"github.com/udhos/equalfile"
// "io"
// "bytes"
)
// EvaluateSubmission : Evaluates the submission
func EvaluateSubmission(submissionID string, questionID string) int32 {
// Path refers to path inside the cpjudge_webserver container because
// directory is already mounted.
base := "/media/vaibhav/Coding/go/src/github.com/cpjudge/cpjudge_webserver"
submissionsPath := base + "/submissions/" + submissionID
expectedOutputPath := base + "/questions/testcases/" +
questionID +
"/output/"
expectedOutputFiles, err := ioutil.ReadDir(expectedOutputPath)
if err != nil {
log.Fatal(err)
}
for _, f := range expectedOutputFiles {
errorFilePath := submissionsPath + "/error/" + f.Name()
compilationErrorFilePath := submissionsPath + "/compilation_error.err"
outputFilePath := submissionsPath + "/output/" + f.Name()
expectedOutputFilePath := expectedOutputPath + f.Name()
if fileInfo, err := os.Stat(compilationErrorFilePath); err == nil {
if fileInfo.Size() != 0 {
return 3 //Compilation Error
}
}
if fileInfo, err := os.Stat(errorFilePath); err == nil {
if fileInfo.Size() != 0 {
return 4 //Runtime Error
}
}
cmp := equalfile.New(nil, equalfile.Options{Debug: false})
if equal, _ := cmp.CompareFile(outputFilePath, expectedOutputFilePath); !equal {
return 1 // Wrong Answer
}
}
return 0 // Correct Answer
}