adventofcode/2022/02/test.js

42 lines
926 B
JavaScript

import { test, expect, describe } from "vitest";
import { expectSolution } from "../01/main.js";
import {
parseInput,
sampleInput,
puzzleInput,
mapScores,
solutionPart1,
} from "./part1.js";
import { solutionPart2 } from "./part2.js";
describe("part 1", () => {
test("input parsing", () => {
expect(parseInput(sampleInput)).toEqual([
["A", "Y"],
["B", "X"],
["C", "Z"],
]);
});
test("mapScore", () => {
expect(mapScores(["A", "B"])).toEqual([6, 2]);
expect(mapScores(["B", "A"])).toEqual([0, 1]);
expect(mapScores(["C", "C"])).toEqual([3, 3]);
});
test("part 1, sample", () => {
expect(solutionPart1(sampleInput)).toEqual(15);
});
test("solution", () => {
expectSolution(solutionPart1(puzzleInput)).toEqual(12458);
});
});
describe("part 2", () => {
test("part 2", () => {
expectSolution(solutionPart2(puzzleInput)).toEqual(12683);
});
});