-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathsolutionTemplate.ts.dat
69 lines (56 loc) · 1.99 KB
/
solutionTemplate.ts.dat
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import _ from "lodash";
import * as util from "../../../util/util";
import * as test from "../../../util/test";
import chalk from "chalk";
import { log, logSolution, trace } from "../../../util/log";
import { performance } from "perf_hooks";
import { normalizeTestCases } from "../../../util/test";
const YEAR = {year};
const DAY = {day};
// solution path: {solution_path}
// data path : {data_path}
// problem url : {problem_url}
async function p{year}day{day}_part1(input: string, ...params: any[]) {
return "Not implemented";
}
async function p{year}day{day}_part2(input: string, ...params: any[]) {
return "Not implemented";
}
async function run() {
const part1tests: TestCase[] = [];
const part2tests: TestCase[] = [];
const [p1testsNormalized, p2testsNormalized] = normalizeTestCases(part1tests, part2tests);
// Run tests
test.beginTests();
await test.section(async () => {
for (const testCase of p1testsNormalized) {
test.logTestResult(testCase, String(await p{year}day{day}_part1(testCase.input, ...(testCase.extraArgs || []))));
}
});
await test.section(async () => {
for (const testCase of p2testsNormalized) {
test.logTestResult(testCase, String(await p{year}day{day}_part2(testCase.input, ...(testCase.extraArgs || []))));
}
});
test.endTests();
// Get input and run program while measuring performance
const input = await util.getInput(DAY, YEAR);
const part1Before = performance.now();
const part1Solution = String(await p{year}day{day}_part1(input));
const part1After = performance.now();
const part2Before = performance.now()
const part2Solution = String(await p{year}day{day}_part2(input));
const part2After = performance.now();
logSolution({day}, {year}, part1Solution, part2Solution);
log(chalk.gray("--- Performance ---"));
log(chalk.gray(`Part 1: ${util.formatTime(part1After - part1Before)}`));
log(chalk.gray(`Part 2: ${util.formatTime(part2After - part2Before)}`));
log();
}
run()
.then(() => {
process.exit();
})
.catch(error => {
throw error;
});