diff --git a/docs/docs/use/testcase.md b/docs/docs/use/testcase.md index 5dd6d629..da4531b4 100644 --- a/docs/docs/use/testcase.md +++ b/docs/docs/use/testcase.md @@ -10,14 +10,14 @@ ## 二、文件上传 -对于通题目,测试用例文件包括`in`、`out`、`ans`三种拓展名 +对于普通题目,测试用例文件包括`in`、`out`、`ans`、`txt`四种拓展名 -例如有两组测试用例,则对于普通题目测试用例的文件名分别为`1.in, 1.out(1.ans), 2.in, 2.out(2.ans)`其他形式的文件后台均不识别。 +例如有两组测试用例,则对于普通题目测试用例的文件名分别为`*.in, *.out(*.ans)`,或者`*input*.txt, *output*.txt ` ,其他形式的文件后台均不识别。 压缩时,请将文件都放在压缩包的根目录,而不是包含在某一个文件夹中,比如正确的格式是: ```bash -├── 1.in +├── 1.in ├── 1.out ├── 2.in ├── 2.out @@ -30,6 +30,15 @@ ├── 2.ans ``` +或者 + +```bash +├── input1.txt +├── output1.txt +├── input2.txt +├── output2.txt +``` + 然后压缩测试用例到一个zip中 :::danger diff --git a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/controller/file/TestCaseController.java b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/controller/file/TestCaseController.java index 3cc42012..0ccb7a4f 100644 --- a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/controller/file/TestCaseController.java +++ b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/controller/file/TestCaseController.java @@ -81,28 +81,44 @@ public class TestCaseController { // 遍历读取与检查是否in和out文件一一对应,否则报错 for (File tmp : files) { String tmpPreName = null; - try { - tmpPreName = tmp.getName().substring(0, tmp.getName().lastIndexOf(".")); - } catch (Exception ignored) { - } - if (tmp.getName().endsWith("in")) { + if (tmp.getName().endsWith(".in")) { + tmpPreName = tmp.getName().substring(0, tmp.getName().lastIndexOf(".in")); inputData.put(tmpPreName, tmp.getName()); - } else if (tmp.getName().endsWith("out") || tmp.getName().endsWith("ans")) { + } else if (tmp.getName().endsWith(".out")) { + tmpPreName = tmp.getName().substring(0, tmp.getName().lastIndexOf(".out")); outputData.put(tmpPreName, tmp.getName()); + } else if (tmp.getName().endsWith(".ans")) { + tmpPreName = tmp.getName().substring(0, tmp.getName().lastIndexOf(".ans")); + outputData.put(tmpPreName, tmp.getName()); + } else if (tmp.getName().endsWith(".txt")) { + tmpPreName = tmp.getName().substring(0, tmp.getName().lastIndexOf(".txt")); + if (tmpPreName.contains("input")) { + inputData.put(tmpPreName.replaceAll("input", "$*$"), tmp.getName()); + } else if (tmpPreName.contains("output")) { + outputData.put(tmpPreName.replaceAll("output", "$*$"), tmp.getName()); + } } } // 进行数据对应检查,同时生成返回数据 List> problemCaseList = new LinkedList<>(); for (String key : inputData.keySet()) { + HashMap testcaseMap = new HashMap<>(); + String inputFileName = inputData.get(key); + testcaseMap.put("input", inputFileName); + + String outputFileName = key + ".out"; + if (inputFileName.endsWith(".txt")) { + outputFileName = inputFileName.replaceAll("input", "output"); + } + // 若有名字对应的out文件不存在的,直接生成对应的out文件 if (outputData.getOrDefault(key, null) == null) { - FileWriter fileWriter = new FileWriter(fileDir + File.separator + key + ".out"); + FileWriter fileWriter = new FileWriter(fileDir + File.separator + outputFileName); fileWriter.write(""); } - HashMap testcaseMap = new HashMap<>(); - testcaseMap.put("input", inputData.get(key)); - testcaseMap.put("output", key + ".out"); + + testcaseMap.put("output", outputFileName); problemCaseList.add(testcaseMap); }