-
Notifications
You must be signed in to change notification settings - Fork 0
/
latternfish.test.ts
78 lines (73 loc) · 1.86 KB
/
latternfish.test.ts
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
70
71
72
73
74
75
76
77
78
import { expect } from "chai";
// local import
import { Latternfish, Config } from "./latternfish.js";
interface TestCase {
config: Config;
expect: number;
}
const testCases: Record<string, TestCase> = {
simpleNoSpawning: {
config: {
fishes: [3, 2, 1],
dayToSpawn: 6,
initDayToSpawn: 8,
daySimulation: 1,
},
expect: 3,
},
simpleWithSpawning: {
config: {
fishes: [3, 2, 1],
dayToSpawn: 6,
initDayToSpawn: 8,
daySimulation: 2,
},
expect: 4,
},
givenExampleOne: {
// Come from the problem
config: {
fishes: [3, 4, 3, 1, 2],
dayToSpawn: 6,
initDayToSpawn: 8,
daySimulation: 18,
},
expect: 26,
},
givenExampleTwo: {
// Come from the problem
config: {
fishes: [3, 4, 3, 1, 2],
dayToSpawn: 6,
initDayToSpawn: 8,
daySimulation: 80,
},
expect: 5934,
},
givenExampleThree: {
// Come from the problem
config: {
fishes: [3, 4, 3, 1, 2],
dayToSpawn: 6,
initDayToSpawn: 8,
daySimulation: 256,
},
expect: 26984457539,
},
};
describe("Day 06 - Latternfish", () => {
it("test for fish of no spawning", () => runTestCase("simpleNoSpawning"));
it("test for fish with spawning", () => runTestCase("simpleWithSpawning"));
it("test for the given example I", () => runTestCase("givenExampleOne"));
it("test for the given example II", () => runTestCase("givenExampleTwo"));
it("test for the given example III", () => runTestCase("givenExampleThree"));
});
async function runTestCase(testName: string) {
if (Object.keys(testCases).includes(testName)) {
const { config, expect: expectedResult } = testCases[testName] as TestCase;
const result = Latternfish.modeling(config);
expect(result).eql(expectedResult);
} else {
throw new Error(`Test case "${testName}" not found.`);
}
}