adventofcode/2022/10/test.js
2022-12-10 18:25:50 -05:00

57 lines
1.5 KiB
JavaScript

import { test, expect, describe } from "vitest";
import * as R from "remeda";
import { expectSolution } from "../01/main.js";
import part1, {
comsys,
sample,
sample2,
puzzleInput,
addSignal,
} from "./part1.js";
import part2 from "./part2.js";
describe("part 1", () => {
test("comsys", () => {
let sys = comsys();
const result = sample.map(sys).map(R.prop("register"));
expect(result).toEqual([1, 1, 4]);
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", () => {
expect(part1(sample2)).toEqual(13140);
});
test("solution", () => {
expectSolution(part1(puzzleInput)).toEqual(15020);
});
});
describe("part 2", () => {
test("sample", () => {
expect(part2(sample2)).toEqual(`##..##..##..##..##..##..##..##..##..##..
###...###...###...###...###...###...###.
####....####....####....####....####....
#####.....#####.....#####.....#####.....
######......######......######......####
#######.......#######.......#######.....
`);
});
test("solution", () => {
expectSolution(part2(puzzleInput)).toEqual(
`####.####.#..#..##..#....###...##..###..
#....#....#..#.#..#.#....#..#.#..#.#..#.
###..###..#..#.#....#....#..#.#..#.#..#.
#....#....#..#.#.##.#....###..####.###..
#....#....#..#.#..#.#....#....#..#.#....
####.#.....##...###.####.#....#..#.#....
`
);
});
});