judge: better config validate

This commit is contained in:
undefined committed 2020-12-09 23:42:01 +08:00
1 parent 68286607e9
commit 5dd5dca675
3 files changed
+5 -7

No files matched your search

+4 -5
View File
@@ -1,7 +1,7 @@
import fs from 'fs-extra';
import path from 'path';
import yaml from 'js-yaml';
import { Dictionary } from 'lodash';
import { Dictionary, sum } from 'lodash';
import { argv } from 'yargs';
import { FormatError, SystemError } from './error';
import { parseTimeMS, parseMemoryMB, ensureFile } from './utils';
@@ -285,11 +285,10 @@ function convertIniConfig(ini: string) {
}
function isValidConfig(config) {
if (config.count > (argv.max_testcases_count as string || 100)) throw new FormatError('Too many testcases. Cancelled.');
let total_time = 0;
for (const subtask of config.subtasks) {
total_time += subtask.time_limit_ms * subtask.cases.length;
if (config.count > (argv.max_testcases_count as string || 100)) {
throw new FormatError('Too many testcases. Cancelled.');
}
const total_time = sum(config.subtasks.map((subtask) => subtask.time_limit_ms * subtask.cases.length));
if (total_time > (+argv.max_time_limit || 60) * 1000) {
throw new FormatError('Total time limit longer than {0}s. Cancelled.', [+argv.max_time_limit || 60]);
}