forked from nim-ka/aocutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
33 lines (27 loc) · 893 Bytes
/
test.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
if (typeof window == "undefined" && process.argv[2] == "test") {
const fs = require("fs")
function test(name, answer, func, ...args) {
console.time(name)
let res = func(...args)
console.timeEnd(name)
console.log(`${name}: Got ${res}, expected ${answer}`)
if (res == answer) {
console.log(`${name}: SUCCESS`)
} else {
console.error(`${name}: FAIL`)
process.exit(1)
}
}
const year = "2021"
for (let i = +process.argv[3] || 1; i <= 25; i++) {
const func = require(`./${year}/${i}.js`)
const input = fs.readFileSync(`./${year}/inputs/${i}`, "utf8")
const answers = fs.readFileSync(`./${year}/answers/${i}`, "utf8").split("\n-----\n")
if (i != 25) {
test(`${year} day ${i} part 1`, answers[0], func, input, false)
test(`${year} day ${i} part 2`, answers[1], func, input, true)
} else {
test(`${year} day ${i}`, answers[0], func, input)
}
}
}