judge: testlib: allow control fuction

This commit is contained in:
undefined committed 2022-03-11 13:35:32 +08:00
1 parent f1734761c3
commit 671d8077b3
2 files changed
+23 -6

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js",
"version": "2.14.4",
"version": "2.14.5",
"main": "package.json",
"author": "undefined <i@undefined.moe>",
"repository": "https://github.com/hydro-dev/Hydro.git",
+22 -5
View File
@@ -1,21 +1,28 @@
import { STATUS } from '@hydrooj/utils/lib/status';
const operation = /^(status|score)\((\d+)\) *(.*)$/;
export function parse(output: string, fullscore: number) {
let status = STATUS.STATUS_WRONG_ANSWER;
let score = 0;
let message = output.substr(0, 1024);
let builder = (msg: string) => msg;
let message = output.substring(0, 1024);
if (output.startsWith('ok ')) {
status = STATUS.STATUS_ACCEPTED;
score = fullscore;
} else if (output.startsWith('wrong answer ')) {
message = output.split('wrong answer ')[1] || '';
} else if (output.startsWith('wrong output format ')) {
message = `PE ${output.split('wrong output format ')[1] || ''}`;
message = output.split('wrong output format ')[1] || '';
builder = (msg) => `PE ${msg}`;
} else if (output.startsWith('partially correct ')) {
message = `PC ${output.split('partially correct ')[1] || ''}`;
let p = +output.split('partially correct (')[1].split(')')[0] || 0;
if (p > 1) p /= 100;
score = Math.floor(fullscore * p);
const res = message.split(')');
res.shift();
message = res.join(')').trim();
builder = (msg) => `PC ${msg}`;
} else if (output.startsWith('points ')) {
let p = +output.split('points ')[1].split(' ')[0] || 0;
if (p > 1) p /= 100;
@@ -23,8 +30,18 @@ export function parse(output: string, fullscore: number) {
status = STATUS.STATUS_ACCEPTED;
score = fullscore;
const base = output.split('points ')[1] || '';
message = base.substr(base.indexOf(' '), 1024);
message = base.substring(base.indexOf(' '), 1024);
} else score = Math.floor(fullscore * p);
}
return { status, score, message };
while (operation.test(message)) {
const [, op, val, rest] = message.match(operation);
if (op === 'status') {
status = +val;
message = rest;
} else if (op === 'score') {
score = +val;
message = rest;
}
}
return { status, score, message: builder(message) };
}