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

import { deckOrderFromSeed, normalizeSeed, randomSeed } from "./random";
import { resetFromOrder } from "./engine";
import { N_CARDS } from "./types";

describe("seeded deals", () => {
  test("a seed always produces the same 60-card permutation", () => {
    const first = deckOrderFromSeed("lost-cities");
    expect(first).toHaveLength(N_CARDS);
    expect(new Set(first).size).toBe(N_CARDS);
    expect(deckOrderFromSeed("lost-cities")).toEqual(first);
  });

  test("different seeds deal different games", () => {
    expect(deckOrderFromSeed("a")).not.toEqual(deckOrderFromSeed("b"));
  });

  test("a seeded deck order is a playable initial state", () => {
    const state = resetFromOrder(deckOrderFromSeed(randomSeed()));
    expect(state.drawPtr).toBe(16);
    expect(state.toMove).toBe(0);
  });

  test("seed input is trimmed and length-capped", () => {
    expect(normalizeSeed("  abc  ")).toBe("abc");
    expect(normalizeSeed("x".repeat(50))).toHaveLength(32);
  });
});
