-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem.js
More file actions
46 lines (40 loc) · 848 Bytes
/
Problem.js
File metadata and controls
46 lines (40 loc) · 848 Bytes
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
42
43
44
45
46
function print(st) {
process.stdout.write(st);
}
function printLn(st) {
console.log(st)
}
module.exports = class Problem {
cases = []
name = ''
run(inp) {
return inp;
}
test(inp, out) {
const ret = this.run(inp);
const res = this.compare(ret, out);
return { res, ret }
}
testAll() {
console.log(this.name);
console.log(`Running ${this.cases.length} tests:`);
this.cases.forEach((c) => {
const r = this.test(c.inp, c.out);
if (!r.res) {
print('Test failed.\n Inp: ')
printLn(c.inp)
print(' Out:\n ')
printLn(r.ret)
print(' Expected:\n ')
printLn(c.out)
} else {
print('Test passed\n Inp:\n ')
printLn(c.inp)
printLn('')
}
});
}
compare(res, out) {
return res === out;
}
}