judge: better read_cases (#111)

This commit is contained in:
undefined committed 2021-05-01 12:35:17 +08:00
1 parent 9cdd47d256
commit cc0fc9e5b3
4 files changed
+14 -9

No files matched your search

+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js",
"version": "2.5.17",
"version": "2.5.18",
"main": "package.json",
"author": "undefined <i@undefined.moe>",
"repository": "https://github.com/hydro-dev/Hydro.git",
"dependencies": {
"@hydrooj/utils": "^1.0.8",
"@hydrooj/utils": "^1.0.9",
"adm-zip": "^0.5.5",
"axios": "^0.21.1",
"bson": "^4.3.0",
+10 -5
View File
@@ -104,8 +104,9 @@ async function read0(folder: string, files: string[], checkFile, cfg) {
return config;
}
async function read1(folder: string, files: string[], checkFile, cfg) {
async function read1(folder: string, files: string[], checkFile, cfg, rst) {
const subtask = {};
for (const s of rst.subtasks) if (s.id) subtask[s.id] = s;
const subtasks = [];
for (const file of files) {
for (const REG of RE1) {
@@ -150,7 +151,7 @@ async function read1(folder: string, files: string[], checkFile, cfg) {
return config;
}
async function readAutoCases(folder, { next }, cfg) {
async function readAutoCases(folder, { next }, cfg, rst) {
const config = {
checker_type: 'default',
count: 0,
@@ -170,7 +171,7 @@ async function readAutoCases(folder, { next }, cfg) {
files.push(...outputs.map((i) => `output/${i}`));
}
let result = await read0(folder, files, checkFile, cfg);
if (!result.count) result = await read1(folder, files, checkFile, cfg);
if (!result.count) result = await read1(folder, files, checkFile, cfg, rst);
Object.assign(config, result);
next({ message: { message: 'Found {0} testcases.', params: [config.count] } });
} catch (e) {
@@ -214,8 +215,12 @@ export default async function readCases(folder: string, cfg: Record<string, any>
} catch (e) {
throw changeErrorType(e, FormatError);
}
if (!(result.outputs?.length || result.subtasks.length)) {
const c = await readAutoCases(folder, args, config);
let auto = !result.outputs?.length;
if (!result.subtasks.length) {
auto = !Math.sum(result.subtasks.map((subtask) => subtask.cases.length));
}
if (auto) {
const c = await readAutoCases(folder, args, config, result);
result.subtasks = c.subtasks;
result.count = c.count;
}
+1 -1
View File
@@ -51,7 +51,7 @@ export default async function readYamlCases(cfg: Record<string, any> = {}, check
} else if (cfg.subtasks) {
for (const subtask of cfg.subtasks) {
const cases = [];
for (const c of subtask.cases) {
for (const c of subtask.cases || []) {
config.count++;
cases.push({
input: c.input ? checkFile(c.input, 'Cannot find input file {0}.') : '/dev/null',
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/utils",
"version": "1.0.8",
"version": "1.0.9",
"description": "hydrooj utils",
"main": "package.json",
"repository": "https://github.com/hydro-dev/Hydro.git",