-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem.js
41 lines (36 loc) · 1.16 KB
/
problem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const yaml = require('yaml');
const fs = require('fs');
class Problem {
constructor(dir){
this.baseDir = dir;
this.rawConf = fs.readFileSync(`${this.baseDir}/problem.yml`).toString();
this.conf = yaml.parse(this.rawConf);
this.cases = this.scanTestCases();
console.log(this.conf);
console.log(this.cases);
}
scanTestCases() {
const files = fs.readdirSync(`${this.baseDir}/testcase`);
const cases = {};
const retCases = {};
for(const f of files) {
const k = f.split('.');
const suffix = k.slice(-1)[0];
if(/^(in|ans)$/g.test(suffix)){
const name = k.slice(0,-1).join('.');
// if(parseInt(name)) {
if(cases[name]) cases[name][`${suffix}File`] = f;
else cases[name] = {
[`${suffix}File`]: f,
};
// }
}
}
for(const el of Object.keys(cases)){
if(Object.keys(cases[el]).length != 2) continue;
retCases[el] = cases[el];
}
return retCases;
}
}
module.exports = Problem;