Skip to content

Commit

Permalink
feat: support java package
Browse files Browse the repository at this point in the history
  • Loading branch information
yhzhu99 committed Apr 17, 2021
1 parent 1224e8c commit 72be4b2
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ func main() {
stuCmd := flag.NewFlagSet("stu", flag.ExitOnError)
judgePtr := stuCmd.String("judge", "0-12345-hanhan", "Please specify the name of the folder containing Java files to judge.")
onlineModePtr := stuCmd.Bool("online", true, "Online or offline mode")
stuPkgPtr := stuCmd.Bool("pkg", false, "Use package or not.")

taCmd := flag.NewFlagSet("ta", flag.ExitOnError)
taJudgePtr := taCmd.String("judge", "0-12345-hanhan", "Please specify the name of the folder containing Java files to judge.")
taPwdPtr := taCmd.String("pwd", "888888", "Please enter your password.")
tagPtr := taCmd.String("tag", "test", "Tag for this judge.")
taPkgPtr := taCmd.Bool("pkg", false, "Use package or not.")

regCmd := flag.NewFlagSet("reg", flag.ExitOnError)
regSidPtr := regCmd.Int("sid", 123456, "Please specify your SID.")
Expand Down Expand Up @@ -56,9 +58,17 @@ func main() {
var exitCode int
switch goos {
case "windows":
exitCode = run.CompileJava("javac", "-encoding", "UTF-8", folderName+"/src/*.java")
if *stuPkgPtr {
exitCode = run.CompileJava("javac", "-encoding", "UTF-8", "-cp", "./"+folderName+"/src", "-d", "./"+folderName+"/out", "./"+folderName+"/src"+"/Test.java")
} else {
exitCode = run.CompileJava("javac", "-encoding", "UTF-8", folderName+"/src/*.java")
}
case "darwin", "linux":
exitCode = run.CompileJava("/bin/sh", "-c", "javac -encoding UTF-8 "+folderName+"/src/*.java")
if *stuPkgPtr {
exitCode = run.CompileJava("javac", "-encoding", "UTF-8", "-cp", "./"+folderName+"/src", "-d", "./"+folderName+"/out", "./"+folderName+"/src"+"/Test.java")
} else {
exitCode = run.CompileJava("/bin/sh", "-c", "javac -encoding UTF-8 "+folderName+"/src/*.java")
}
}
if exitCode != 0 {
fmt.Println("Compile Error!")
Expand All @@ -71,7 +81,14 @@ func main() {
testName, testData := initialize.FetchTestCase("test/" + t)
fmt.Println(testName)
testInputList, testInput, testOutputLines, testOutput, mapTable := initialize.ParseTestData(testData)
runStatus, actualOutput, actualOutputLines := run.RunJava(2, testInput, "java", "-classpath", folderName+"/src", "Test")
var runStatus int
var actualOutput string
var actualOutputLines []string
if *stuPkgPtr {
runStatus, actualOutput, actualOutputLines = run.RunJava(2, testInput, "java", "-classpath", "./"+folderName+"/out", "Test")
} else {
runStatus, actualOutput, actualOutputLines = run.RunJava(2, testInput, "java", "-classpath", folderName+"/src", "Test")
}
compareResult, smallerLen, wrongOutputPos := judge.Compare(testOutputLines, actualOutputLines, mapTable)
resultMessage := "Num = " + strconv.Itoa(num) + ", 评测点 = " + t[0:len(t)-5] + ", Grade = " + strconv.Itoa(judge.CalcGrade(runStatus, compareResult))
fmt.Println(resultMessage)
Expand Down Expand Up @@ -107,9 +124,17 @@ func main() {
var exitCode int
switch goos {
case "windows":
exitCode = run.CompileJava("javac", "-encoding", "UTF-8", folderName+"/src/*.java")
if *taPkgPtr {
exitCode = run.CompileJava("javac", "-encoding", "UTF-8", "-cp", "./"+folderName+"/src", "-d", "./"+folderName+"/out", "./"+folderName+"/src"+"/Test.java")
} else {
exitCode = run.CompileJava("javac", "-encoding", "UTF-8", folderName+"/src/*.java")
}
case "darwin", "linux":
exitCode = run.CompileJava("/bin/sh", "-c", "javac -encoding UTF-8 "+folderName+"/src/*.java")
if *taPkgPtr {
exitCode = run.CompileJava("javac", "-encoding", "UTF-8", "-cp", "./"+folderName+"/src", "-d", "./"+folderName+"/out", "./"+folderName+"/src"+"/Test.java")
} else {
exitCode = run.CompileJava("/bin/sh", "-c", "javac -encoding UTF-8 "+folderName+"/src/*.java")
}
}
if exitCode != 0 {
fmt.Println("Compile Error!")
Expand All @@ -121,9 +146,14 @@ func main() {
// testName, testData := initialize.FetchTestCase("test/" + t)
fmt.Println(testName)
testInputList, testInput, testOutputLines, testOutput, mapTable := initialize.ParseTestData(testData)

runStatus, actualOutput, actualOutputLines := run.RunJava(2, testInput, "java", "-classpath", folderName+"/src", "Test")

var runStatus int
var actualOutput string
var actualOutputLines []string
if *taPkgPtr {
runStatus, actualOutput, actualOutputLines = run.RunJava(2, testInput, "java", "-classpath", "./"+folderName+"/out", "Test")
} else {
runStatus, actualOutput, actualOutputLines = run.RunJava(2, testInput, "java", "-classpath", folderName+"/src", "Test")
}
compareResult, smallerLen, wrongOutputPos := judge.Compare(testOutputLines, actualOutputLines, mapTable)
resultMessage := "Num = " + strconv.Itoa(num) + ", 评测点 = " + t.FileName + ", Grade = " + strconv.Itoa(judge.CalcGrade(runStatus, compareResult))
fmt.Println(resultMessage)
Expand Down

0 comments on commit 72be4b2

Please sign in to comment.