add *.txt problem testcase

This commit is contained in:
Himit_ZH 2022-01-21 21:21:22 +08:00
parent ab91ffe3bc
commit 1beab3d386
2 changed files with 38 additions and 13 deletions

View File

@ -10,9 +10,9 @@
## 二、文件上传
对于通题目,测试用例文件包括`in`、`out`、`ans`种拓展名
对于通题目,测试用例文件包括`in`、`out`、`ans`、`txt`四种拓展名
例如有两组测试用例,则对于普通题目测试用例的文件名分别为`1.in, 1.out1.ans, 2.in, 2.out2.ans`其他形式的文件后台均不识别。
例如有两组测试用例,则对于普通题目测试用例的文件名分别为`*.in, *.out*.ans`,或者`*input*.txt, *output*.txt ` 其他形式的文件后台均不识别。
压缩时,请将文件都放在压缩包的根目录,而不是包含在某一个文件夹中,比如正确的格式是:
@ -30,6 +30,15 @@
├── 2.ans
```
或者
```bash
├── input1.txt
├── output1.txt
├── input2.txt
├── output2.txt
```
然后压缩测试用例到一个zip中
:::danger

View File

@ -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<HashMap<String, String>> problemCaseList = new LinkedList<>();
for (String key : inputData.keySet()) {
HashMap<String, String> 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<String, String> testcaseMap = new HashMap<>();
testcaseMap.put("input", inputData.get(key));
testcaseMap.put("output", key + ".out");
testcaseMap.put("output", outputFileName);
problemCaseList.add(testcaseMap);
}