mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: testlib: allow control fuction
This commit is contained in:
1 parent
f1734761c3
commit
671d8077b3
2 files changed
+23
-6
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/hydrojudge",
|
"name": "@hydrooj/hydrojudge",
|
||||||
"bin": "bin/hydrojudge.js",
|
"bin": "bin/hydrojudge.js",
|
||||||
"version": "2.14.4",
|
"version": "2.14.5",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -1,21 +1,28 @@
|
|||||||
import { STATUS } from '@hydrooj/utils/lib/status';
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
|
|
||||||
|
const operation = /^(status|score)\((\d+)\) *(.*)$/;
|
||||||
|
|
||||||
export function parse(output: string, fullscore: number) {
|
export function parse(output: string, fullscore: number) {
|
||||||
let status = STATUS.STATUS_WRONG_ANSWER;
|
let status = STATUS.STATUS_WRONG_ANSWER;
|
||||||
let score = 0;
|
let score = 0;
|
||||||
let message = output.substr(0, 1024);
|
let builder = (msg: string) => msg;
|
||||||
|
let message = output.substring(0, 1024);
|
||||||
if (output.startsWith('ok ')) {
|
if (output.startsWith('ok ')) {
|
||||||
status = STATUS.STATUS_ACCEPTED;
|
status = STATUS.STATUS_ACCEPTED;
|
||||||
score = fullscore;
|
score = fullscore;
|
||||||
} else if (output.startsWith('wrong answer ')) {
|
} else if (output.startsWith('wrong answer ')) {
|
||||||
message = output.split('wrong answer ')[1] || '';
|
message = output.split('wrong answer ')[1] || '';
|
||||||
} else if (output.startsWith('wrong output format ')) {
|
} 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 ')) {
|
} else if (output.startsWith('partially correct ')) {
|
||||||
message = `PC ${output.split('partially correct ')[1] || ''}`;
|
|
||||||
let p = +output.split('partially correct (')[1].split(')')[0] || 0;
|
let p = +output.split('partially correct (')[1].split(')')[0] || 0;
|
||||||
if (p > 1) p /= 100;
|
if (p > 1) p /= 100;
|
||||||
score = Math.floor(fullscore * p);
|
score = Math.floor(fullscore * p);
|
||||||
|
const res = message.split(')');
|
||||||
|
res.shift();
|
||||||
|
message = res.join(')').trim();
|
||||||
|
builder = (msg) => `PC ${msg}`;
|
||||||
} else if (output.startsWith('points ')) {
|
} else if (output.startsWith('points ')) {
|
||||||
let p = +output.split('points ')[1].split(' ')[0] || 0;
|
let p = +output.split('points ')[1].split(' ')[0] || 0;
|
||||||
if (p > 1) p /= 100;
|
if (p > 1) p /= 100;
|
||||||
@@ -23,8 +30,18 @@ export function parse(output: string, fullscore: number) {
|
|||||||
status = STATUS.STATUS_ACCEPTED;
|
status = STATUS.STATUS_ACCEPTED;
|
||||||
score = fullscore;
|
score = fullscore;
|
||||||
const base = output.split('points ')[1] || '';
|
const base = output.split('points ')[1] || '';
|
||||||
message = base.substr(base.indexOf(' '), 1024);
|
message = base.substring(base.indexOf(' '), 1024);
|
||||||
} else score = Math.floor(fullscore * p);
|
} 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) };
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user