import { describe, expect, it } from "vitest";
import {
  createDeterministicRandom,
  generationSeedHash,
  hashGenerationSeed,
} from "./seeded-random";

describe("deterministic generation random", () => {
  it("replays the same sequence and exposes a stable seed hash", () => {
    const first = createDeterministicRandom("release-seed-17");
    const second = createDeterministicRandom("release-seed-17");
    const expected = [
      997_101_319, 2_253_165_009, 3_652_172_136, 3_704_011_065, 218_024_818,
      4_086_101_089, 1_433_907_551, 2_457_124_617,
    ];

    expect(Array.from({ length: 8 }, () => first.nextUint32())).toEqual(
      expected,
    );
    expect(Array.from({ length: 8 }, () => second.nextUint32())).toEqual(
      expected,
    );
    expect(generationSeedHash("release-seed-17")).toBe("24eea7d5");
    expect(hashGenerationSeed("release-seed-17")).not.toBe(
      hashGenerationSeed("release-seed-18"),
    );
  });

  it("rejects invalid selection bounds", () => {
    const random = createDeterministicRandom("seed");
    expect(() => random.integer(0)).toThrow("positive bound");
    expect(() => random.pick([])).toThrow("empty collection");
  });
});
