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