import { describe, it, expect } from "vitest";
import { stringHashPalette } from "./string_hash_palette";

const PALETTE = ["blue", "cyan", "teal", "green", "lime", "yellow", "orange", "red", "pink", "grape", "violet", "indigo"];

describe("stringHashPalette", () => {
  it("string vacio retorna palette[0]", () => {
    // h empieza en 0, loop no itera, h%n = 0 => palette[0]
    expect(stringHashPalette("", PALETTE)).toBe(PALETTE[0]);
  });

  it("mismo string siempre retorna mismo color", () => {
    const a = stringHashPalette("frontend", PALETTE);
    const b = stringHashPalette("frontend", PALETTE);
    expect(a).toBe(b);
  });

  it("strings distintos pueden dar colores distintos", () => {
    const colors = new Set(["alpha", "beta", "gamma", "delta", "epsilon"].map((s) => stringHashPalette(s, PALETTE)));
    // Con 5 strings distintos y paleta de 12 es muy probable obtener al menos 2 distintos
    expect(colors.size).toBeGreaterThan(1);
  });

  it("paleta vacia lanza error", () => {
    expect(() => stringHashPalette("hello", [])).toThrow("palette must not be empty");
  });

  it("paleta de un elemento siempre retorna ese elemento", () => {
    expect(stringHashPalette("anything", ["only"])).toBe("only");
    expect(stringHashPalette("", ["only"])).toBe("only");
    expect(stringHashPalette("xyz", ["only"])).toBe("only");
  });
});
