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

30 lines
847 B
TypeScript

import {totalFocusingPower, hash, hashSum} from "./day_fifteen";
describe('Day Fifteen', () => {
it.each([
['HASH', 52],
['rn=1', 30],
['cm-', 253],
['qp=3', 97],
['cm=2', 47],
['qp-', 14],
['pc=4', 180],
['ot=9', 9],
['ab=5', 197],
['pc-', 48],
['pc=6', 214],
['ot=7', 231],
])('calculates the hash of %s to %s', (input, expected) => {
expect(hash(input)).toBe(expected);
});
it('calculates the hash of the example', () => {
const input = 'rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7';
expect(hashSum(input)).toEqual(1320);
});
it('calculates the focusing power', () => {
const input = 'rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7';
expect(totalFocusingPower(input)).toEqual(145);
})
});