import { test, expect, describe } from "vitest";

import { expectSolution } from "../01/main.js";
import part1, { puzzleInput } from "./part1.js";
import part2 from "./part2.js";

describe("part 1", () => {
  test("samples", () => {
    expect(part1("mjqjpqmgbljsphdztnvjfqwrcgsmlb")).toEqual(7);

    Object.entries({
      bvwbjplbgvbhsrlpgdmjqwftvncz: 5,
      nppdvjthqldpwncqszvftbrmjlhg: 6,
      nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: 10,
      zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: 11,
    }).forEach(([code, index]) => expect(part1(code)).toEqual(index));
  });
  test("solution", () => {
    expectSolution(part1(puzzleInput)).toEqual(1640);
  });
});

describe("part 2", () => {
  test("samples", () => {
    expect(part2("mjqjpqmgbljsphdztnvjfqwrcgsmlb")).toEqual(19);

    Object.entries({
      bvwbjplbgvbhsrlpgdmjqwftvncz: 23,
      nppdvjthqldpwncqszvftbrmjlhg: 23,
      nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: 29,
      zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: 26,
    }).forEach(([code, index]) => expect(part2(code)).toEqual(index));
  });
  test("solution", () => {
    expectSolution(part2(puzzleInput)).toEqual(3613);
  });
});