advent-of-code-2023/src/day_four.test.ts

41 lines
1.5 KiB
TypeScript

import {Scratchcard, ScratchcardSet} from "./day_four";
describe('Day 4', () => {
const inputs: [string, number][] = [
['Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53', 8],
['Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19', 2],
['Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1', 2],
['Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83', 1],
['Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36', 0],
['Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11', 0]
];
it.each(inputs)('should score %s with %d', (input, expectedScore) => {
const scratchcard = new Scratchcard(input);
expect(scratchcard.score).toEqual(expectedScore);
});
it.each(inputs.map(([input, score]) => [input, score !== 0]))('should return whether %s is a winner', (input, winner) => {
const scratchcard = new Scratchcard(input);
expect(scratchcard.isWinner).toEqual(winner);
});
it('should report the correct scratchcard size', () => {
const scratchcard = new Scratchcard(inputs[0][0]);
const children = inputs.slice(1, 5).map(([input]) => new Scratchcard(input));
scratchcard.setChildren(children);
expect(scratchcard.size).toEqual(5);
});
it('should calculate the total score', () => {
const scratchcards = new ScratchcardSet(inputs.map(([input]) => input));
expect(scratchcards.totalScore).toEqual(13);
});
it('should calculate the total number of scratchcards', () => {
const scratchcards = new ScratchcardSet(inputs.map(([input]) => input));
expect(scratchcards.length).toEqual(30);
});
});