2022-12-10 22:54:56 +00:00
|
|
|
import { test, expect, describe } from "vitest";
|
|
|
|
import * as R from "remeda";
|
|
|
|
|
|
|
|
import { expectSolution } from "../01/main.js";
|
2022-12-10 23:25:50 +00:00
|
|
|
import part1, {
|
|
|
|
comsys,
|
|
|
|
sample,
|
|
|
|
sample2,
|
|
|
|
puzzleInput,
|
|
|
|
addSignal,
|
|
|
|
} from "./part1.js";
|
2022-12-10 22:54:56 +00:00
|
|
|
import part2 from "./part2.js";
|
|
|
|
|
|
|
|
describe("part 1", () => {
|
2022-12-10 23:25:50 +00:00
|
|
|
test("comsys", () => {
|
|
|
|
let sys = comsys();
|
|
|
|
const result = sample.map(sys).map(R.prop("register"));
|
2022-12-10 22:54:56 +00:00
|
|
|
|
2022-12-10 23:25:50 +00:00
|
|
|
expect(result).toEqual([1, 1, 4]);
|
2022-12-10 22:54:56 +00:00
|
|
|
|
2022-12-10 23:25:50 +00:00
|
|
|
sys = comsys();
|
|
|
|
expect(sample.map(sys).map(R.prop("cycle"))).toEqual([2, 3, 4]);
|
|
|
|
});
|
|
|
|
test("signal strength", () => {
|
|
|
|
expect(addSignal({ cycle: 3, register: 2 })).toMatchObject({ signal: 6 });
|
|
|
|
});
|
|
|
|
test("sample2", () => {
|
2022-12-10 22:54:56 +00:00
|
|
|
expect(part1(sample2)).toEqual(13140);
|
2022-12-10 23:25:50 +00:00
|
|
|
});
|
2022-12-10 22:54:56 +00:00
|
|
|
test("solution", () => {
|
|
|
|
expectSolution(part1(puzzleInput)).toEqual(15020);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-10 23:25:50 +00:00
|
|
|
describe("part 2", () => {
|
2022-12-10 22:54:56 +00:00
|
|
|
test("sample", () => {
|
2022-12-10 23:25:50 +00:00
|
|
|
expect(part2(sample2)).toEqual(`##..##..##..##..##..##..##..##..##..##..
|
|
|
|
###...###...###...###...###...###...###.
|
|
|
|
####....####....####....####....####....
|
|
|
|
#####.....#####.....#####.....#####.....
|
|
|
|
######......######......######......####
|
|
|
|
#######.......#######.......#######.....
|
|
|
|
`);
|
2022-12-10 22:54:56 +00:00
|
|
|
});
|
2022-12-10 23:25:50 +00:00
|
|
|
test("solution", () => {
|
|
|
|
expectSolution(part2(puzzleInput)).toEqual(
|
|
|
|
`####.####.#..#..##..#....###...##..###..
|
|
|
|
#....#....#..#.#..#.#....#..#.#..#.#..#.
|
|
|
|
###..###..#..#.#....#....#..#.#..#.#..#.
|
|
|
|
#....#....#..#.#.##.#....###..####.###..
|
|
|
|
#....#....#..#.#..#.#....#....#..#.#....
|
|
|
|
####.#.....##...###.####.#....#..#.#....
|
|
|
|
`
|
|
|
|
);
|
2022-12-10 22:54:56 +00:00
|
|
|
});
|
|
|
|
});
|