diff --git a/initialize/config.go b/initialize/config.go index 95b0318..1ee4e12 100644 --- a/initialize/config.go +++ b/initialize/config.go @@ -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++ } diff --git a/judge/compare.go b/judge/compare.go index d98ea5a..5bb91cf 100644 --- a/judge/compare.go +++ b/judge/compare.go @@ -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++ diff --git a/judge/result.go b/judge/result.go index 5bfe3fa..1b99bea 100644 --- a/judge/result.go +++ b/judge/result.go @@ -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 diff --git a/main.go b/main.go index 17b29ba..13cc2b1 100644 --- a/main.go +++ b/main.go @@ -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) } } diff --git a/run/compile.go b/run/compile.go index b8a107b..889526d 100644 --- a/run/compile.go +++ b/run/compile.go @@ -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 } diff --git a/run/execute.go b/run/execute.go index cbca8d1..82a379f 100644 --- a/run/execute.go +++ b/run/execute.go @@ -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 }