adventofcode/2022/09/test.js
2022-12-09 13:05:42 -05:00

45 lines
1.0 KiB
JavaScript

import { test, expect, describe } from "vitest";
import Victor from "@a-robu/victor";
const V = (...args) => new Victor(...args);
import { expectSolution } from "../01/main.js";
import part1, { moveOnce, sample, puzzleInput } from "./part1.js";
import part2, { bigSample } from "./part2.js";
describe("part 1", () => {
test("moveOnce", () => {
let head = V(1, 0);
let tail = V(0, 0);
moveOnce(head, tail)(V(1, 0));
expect(tail).toMatchObject({ x: 1, y: 0 });
moveOnce(head, tail)(V(0, 1));
expect(tail).toMatchObject({ x: 1, y: 0 });
moveOnce(head, tail)(V(0, 1));
expect(tail).toMatchObject({ x: 2, y: 1 });
});
test("sample", () => {
expect(part1(sample)).toEqual(13);
});
test("solution", () => {
expectSolution(part1(puzzleInput)).toEqual(6030);
});
});
describe("part 2", () => {
test("sample", () => {
expect(part2(sample)).toEqual(1);
expect(part2(bigSample)).toEqual(36);
});
test("solution", () => {
expectSolution(part2(puzzleInput)).toEqual(2545);
});
});