MCPcopy Create free account
hub / github.com/LanceLRQ/deer-executor / lineDiff

Function lineDiff

executor/checker.go:48–91  ·  view source on GitHub ↗

逐行比较,获取错误行数 Compare each line, to find out the number of wrong line

(session *JudgeSession, rst *commonStructs.TestCaseResult)

Source from the content-addressed store, hash-verified

46// 逐行比较,获取错误行数
47// Compare each line, to find out the number of wrong line
48func lineDiff(session *JudgeSession, rst *commonStructs.TestCaseResult) (sameLines int, totalLines int) {
49 answer, err := os.OpenFile(path.Join(session.ConfigDir, rst.Output), os.O_RDONLY|syscall.O_NONBLOCK, 0)
50 if err != nil {
51 return 0, 0
52 }
53 defer answer.Close()
54 userout, err := os.Open(path.Join(session.SessionDir, rst.ProgramOut))
55 if err != nil {
56 return 0, 0
57 }
58 defer userout.Close()
59
60 useroutBuffer := bufio.NewReader(userout)
61 answerBuffer := bufio.NewReader(answer)
62
63 var (
64 leftStr = ""
65 rightStr = ""
66 leftErr error = nil
67 rightErr error = nil
68 leftCnt = 0
69 rightCnt = 0
70 )
71
72 for leftErr == nil {
73 leftStr, leftErr = readLineAndRemoveSpaceChar(answerBuffer)
74 if leftStr == "" {
75 continue
76 }
77
78 leftCnt++
79
80 for rightStr == "" && rightErr == nil {
81 rightStr, rightErr = readLineAndRemoveSpaceChar(useroutBuffer)
82 }
83
84 if rightStr == leftStr {
85 rightCnt++
86 }
87 rightStr = ""
88 }
89
90 return rightCnt, leftCnt
91}
92
93// 严格比较每一个字符
94// Compare each char in buffer strictly

Callers 1

DiffTextMethod · 0.85

Calls 1

Tested by

no test coverage detected