Skip to content

Commit

Permalink
chore: trim "\n\r\t "
Browse files Browse the repository at this point in the history
  • Loading branch information
yhzhu99 committed Apr 4, 2021
1 parent 14a2dd0 commit 100f83c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
6 changes: 3 additions & 3 deletions initialize/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ func ParseTestData(testData *[][]string) (testInputList []string, testInput stri
if lenSinglePoint == 0 || lenSinglePoint > 2 {
panic("Wrong Test Case Format!")
}
testInputList = append(testInputList, strings.TrimRight(v[0], "\r\n"))
testInputList = append(testInputList, strings.Trim(v[0], "\r\n\t "))
if lenSinglePoint == 2 {
curOutput := strings.TrimRight(v[1], "\r\n")
curOutput := strings.Trim(v[1], "\r\n\t ")
curOutputLines := strings.Split(curOutput, "\n")
for _, s := range curOutputLines {
testOutputLines = append(testOutputLines, s)
testOutputLines = append(testOutputLines, strings.Trim(s, "\r\n\t "))
mapTable = append(mapTable, i)
linesInOutput++
}
Expand Down
6 changes: 3 additions & 3 deletions judge/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ func Compare(testOutputLines []string, actualOutputLines []string, mapTable []in

i := 0
for i < smallerLen {
if strings.Compare(strings.TrimRight(testOutputLines[i], "\r\n"), strings.TrimRight(actualOutputLines[i], "\r\n")) != 0 {
// fmt.Println(strings.Compare(strings.TrimRight(testOutputLines[i], "\r\n"), strings.TrimRight(actualOutputLines[i], "\r\n")))
if strings.Compare(strings.Trim(testOutputLines[i], "\r\n\t "), strings.Trim(actualOutputLines[i], "\r\n\t ")) != 0 {

compareResult = mapTable[i] // 输出第几个输入时,出现错误
// fmt.Println("Error\n", len(strings.TrimRight(testOutputLines[i], "\r\n")), "\n", len(strings.TrimRight(actualOutputLines[i], "\r\n")))

return compareResult, smallerLen, i
}
i++
Expand Down
31 changes: 31 additions & 0 deletions judge/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,37 @@ func ReportGen(reportName string, runStatus int, compareResult int, smallerLen i
}
}

func TaJudgeReportGen(reportName string, runStatus int, compareResult int, smallerLen int, wrongOutputPos int, testInputList []string, testOutputLines []string, actualOutputLines []string, testOutput string, actualOutput string) {
content := "# " + reportName + " 评测情况\n\n" + "## 通过情况\n\n"
if runStatus == 0 && compareResult == -3 {
content += "Congratulations, AC!\n"
} else if runStatus == 1 && compareResult == -3 {
content += "TLE,输出结果正确\n"
} else if runStatus == 2 && compareResult == -3 {
content += "RE,输出结果正确\n"
} else {
if runStatus == 0 {
content += "WA,输出结果错误\n\n"
} else if runStatus == 1 {
content += "TLE,输出结果错误\n\n"
} else if runStatus == 2 {
content += "RE,输出结果错误\n\n"
}
content += "## 输出比较\n\n"
if compareResult == -1 {
content += "实际输出行数 < 期望输出行数。\n\n"
} else if compareResult == -2 {
content += "实际输出行数 > 期望输出行数。\n\n"
} else {
content += "### 期望输出行\n\n```java\n" + testOutputLines[wrongOutputPos] + "\n```\n\n"
content += "### 实际输出行\n\n```java\n" + actualOutputLines[wrongOutputPos] + "\n```\n"
}
}
if err := os.WriteFile(reportName+"_result"+".md", []byte(content), 0644); err != nil {
panic(err)
}
}

func CalcGrade(runStatus int, compareResult int) (result int) {
// AC 完全正确 1
// TLE 超时 -1
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ func main() {
_, _, testName, testData := initialize.ParseFormalTestCase(t)
// testName, testData := initialize.FetchTestCase("test/" + t)
fmt.Println(testName)
_, testInput, testOutputLines, _, mapTable := initialize.ParseTestData(testData)
testInputList, testInput, testOutputLines, testOutput, mapTable := initialize.ParseTestData(testData)

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

compareResult, _, _ := judge.Compare(testOutputLines, actualOutputLines, mapTable)
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)
judge.TaJudgeReportGen(t.FileName, runStatus, compareResult, smallerLen, wrongOutputPos, testInputList, testOutputLines, actualOutputLines, testOutput, actualOutput)
judge.GradeUploadFormal(num, sid, name, t.FileName, judge.CalcGrade(runStatus, compareResult), *tagPtr)
}
}
Expand Down
2 changes: 1 addition & 1 deletion run/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ func CompileJava(name string, args ...string) (exitCode int) {
ws := cmd.ProcessState.Sys().(syscall.WaitStatus)
exitCode = ws.ExitStatus()
}
fmt.Printf("Compile result: (stdout: %v) (stderr: %v) (exitCode: %v)\n", stdout, strings.TrimRight(stderr, "\r\n"), exitCode)
fmt.Printf("Compile result: (stdout: %v) (stderr: %v) (exitCode: %v)\n", stdout, strings.Trim(stderr, "\r\n\t "), exitCode)
return exitCode
}
2 changes: 1 addition & 1 deletion run/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ func RunJava(timeout int, testInput string, command string, args ...string) (int
fmt.Println("END RUN JAVA")
}
actualOutput := buf.String()
actualOutputLines := strings.Split(strings.TrimRight(actualOutput, "\r\n"), "\n")
actualOutputLines := strings.Split(strings.Trim(actualOutput, "\r\n\t "), "\n")
return runStatus, actualOutput, actualOutputLines
}

0 comments on commit 100f83c

Please sign in to comment.