Skip to content

Commit

Permalink
fix: automatically trim output and compare
Browse files Browse the repository at this point in the history
  • Loading branch information
seo-rii committed Dec 29, 2021
1 parent 19de162 commit 0a3e9c3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
3 changes: 2 additions & 1 deletion res/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@
source: [
{
name: '1',
source: '123',
source: `123
`,
},
],
dataSet: {
Expand Down
32 changes: 27 additions & 5 deletions src/runner/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
import {JudgeRequest, JudgeSourceType, JudgeType, OutputOnly} from "../types/request";
import {
JudgeRequest,
JudgeSourceType,
JudgeType,
OutputOnly,
} from '../types/request'

import judgeText from './text';
import judgeText from './text'

export function isSame(in1: string, in2: string): boolean {
let res1 = in1
.split('\n')
.map((str) => str.trimEnd())
.filter((x) => x),
res2 = in2
.split('\n')
.map((str) => str.trimEnd())
.filter((x) => x)
return res1.length === res2.length && res1.every((x, i) => x === res2[i])
}

export default function (data: JudgeRequest) {
switch (data.judgeType) {
case JudgeType.OutputOnly:
return judgeText(data as JudgeRequest<JudgeType.OutputOnly, JudgeSourceType.TEXT, OutputOnly>);
return judgeText(
data as JudgeRequest<
JudgeType.OutputOnly,
JudgeSourceType.TEXT,
OutputOnly
>
)
case JudgeType.CommonJudge:
switch (data.language) {

}
}
}
}
3 changes: 2 additions & 1 deletion src/runner/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import {
} from '../types/request'
import { sendMessage } from '../socket'
import { WebSocketResponseType } from '../types/response'
import { isSame } from './index'

export default function (
data: JudgeRequest<JudgeType.OutputOnly, JudgeSourceType.TEXT, OutputOnly>
) {
let match = Array(data.dataSet.data.length).fill(false)
for (const s in data.source) {
for (const i in data.dataSet.data) {
if (data.source[s].source === data.dataSet.data[i].output) {
if (isSame(data.source[s].source, data.dataSet.data[i].output)) {
match[i] = true
}
}
Expand Down

0 comments on commit 0a3e9c3

Please sign in to comment.