Download src/lib/debate/__tests__/opponents.test.ts from NAP1320/RotNot: direct link, hf CLI and curl.
- Browser
- Download file 7.11 kB
-
https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/lib/debate/__tests__/opponents.test.ts
- Command line
-
hf download hf://spaces/NAP1320/RotNot/src/lib/debate/__tests__/opponents.test.ts
-
curl -L -o opponents.test.ts https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/lib/debate/__tests__/opponents.test.ts
7.11 kB
| import { describe, it, expect } from "vitest"; | |
| import { | |
| ALL_OPPONENTS, | |
| getOpponentsByDifficulty, | |
| getRandomOpponent, | |
| getOpponentById, | |
| getOpponentSampler, | |
| type OpponentDifficulty, | |
| } from "@/lib/debate/opponents"; | |
| // --------------------------------------------------------------------------- | |
| // Data integrity | |
| // --------------------------------------------------------------------------- | |
| describe("ALL_OPPONENTS data integrity", () => { | |
| it("has at least 10 opponents", () => { | |
| expect(ALL_OPPONENTS.length).toBeGreaterThanOrEqual(10); | |
| }); | |
| it("has unique IDs", () => { | |
| const ids = ALL_OPPONENTS.map((o) => o.id); | |
| expect(new Set(ids).size).toBe(ids.length); | |
| }); | |
| it("all IDs follow opp-<difficulty>-<name> format", () => { | |
| for (const opp of ALL_OPPONENTS) { | |
| expect(opp.id).toMatch(/^opp-(easy|med|hard)-[a-z]+$/); | |
| } | |
| }); | |
| it("every opponent has a non-empty name", () => { | |
| for (const opp of ALL_OPPONENTS) { | |
| expect(opp.name.trim().length).toBeGreaterThan(0); | |
| } | |
| }); | |
| it("every opponent has a non-empty description", () => { | |
| for (const opp of ALL_OPPONENTS) { | |
| expect(opp.description.trim().length).toBeGreaterThan(0); | |
| } | |
| }); | |
| it("every opponent has a non-empty systemPrompt", () => { | |
| for (const opp of ALL_OPPONENTS) { | |
| expect(opp.systemPrompt.trim().length).toBeGreaterThan(50); | |
| } | |
| }); | |
| it("every opponent has a non-empty icon", () => { | |
| for (const opp of ALL_OPPONENTS) { | |
| expect(opp.icon.trim().length).toBeGreaterThan(0); | |
| } | |
| }); | |
| it("every opponent has a valid difficulty", () => { | |
| const validDifficulties: OpponentDifficulty[] = ["easy", "medium", "hard"]; | |
| for (const opp of ALL_OPPONENTS) { | |
| expect(validDifficulties).toContain(opp.difficulty); | |
| } | |
| }); | |
| it("has opponents at all three difficulty levels", () => { | |
| const difficulties = new Set(ALL_OPPONENTS.map((o) => o.difficulty)); | |
| expect(difficulties.has("easy")).toBe(true); | |
| expect(difficulties.has("medium")).toBe(true); | |
| expect(difficulties.has("hard")).toBe(true); | |
| }); | |
| it("has at least 2 easy opponents", () => { | |
| expect(ALL_OPPONENTS.filter((o) => o.difficulty === "easy").length).toBeGreaterThanOrEqual(2); | |
| }); | |
| it("has at least 3 medium opponents", () => { | |
| expect(ALL_OPPONENTS.filter((o) => o.difficulty === "medium").length).toBeGreaterThanOrEqual(3); | |
| }); | |
| it("has at least 5 hard opponents (historical figures)", () => { | |
| expect(ALL_OPPONENTS.filter((o) => o.difficulty === "hard").length).toBeGreaterThanOrEqual(5); | |
| }); | |
| it("all hard opponents have an era field", () => { | |
| for (const opp of ALL_OPPONENTS.filter((o) => o.difficulty === "hard")) { | |
| expect(opp.era).toBeDefined(); | |
| expect(opp.era!.trim().length).toBeGreaterThan(0); | |
| } | |
| }); | |
| it("easy and medium opponents do NOT have an era field", () => { | |
| for (const opp of ALL_OPPONENTS.filter((o) => o.difficulty !== "hard")) { | |
| expect(opp.era).toBeUndefined(); | |
| } | |
| }); | |
| it("unique names across all opponents", () => { | |
| const names = ALL_OPPONENTS.map((o) => o.name); | |
| expect(new Set(names).size).toBe(names.length); | |
| }); | |
| }); | |
| // --------------------------------------------------------------------------- | |
| // getOpponentsByDifficulty | |
| // --------------------------------------------------------------------------- | |
| describe("getOpponentsByDifficulty", () => { | |
| it("returns only easy opponents for 'easy'", () => { | |
| const opponents = getOpponentsByDifficulty("easy"); | |
| expect(opponents.length).toBeGreaterThan(0); | |
| for (const opp of opponents) { | |
| expect(opp.difficulty).toBe("easy"); | |
| } | |
| }); | |
| it("returns only medium opponents for 'medium'", () => { | |
| const opponents = getOpponentsByDifficulty("medium"); | |
| expect(opponents.length).toBeGreaterThan(0); | |
| for (const opp of opponents) { | |
| expect(opp.difficulty).toBe("medium"); | |
| } | |
| }); | |
| it("returns only hard opponents for 'hard'", () => { | |
| const opponents = getOpponentsByDifficulty("hard"); | |
| expect(opponents.length).toBeGreaterThan(0); | |
| for (const opp of opponents) { | |
| expect(opp.difficulty).toBe("hard"); | |
| } | |
| }); | |
| it("returns complete set — sum equals ALL_OPPONENTS length", () => { | |
| const easy = getOpponentsByDifficulty("easy"); | |
| const medium = getOpponentsByDifficulty("medium"); | |
| const hard = getOpponentsByDifficulty("hard"); | |
| expect(easy.length + medium.length + hard.length).toBe(ALL_OPPONENTS.length); | |
| }); | |
| }); | |
| // --------------------------------------------------------------------------- | |
| // getRandomOpponent | |
| // --------------------------------------------------------------------------- | |
| describe("getRandomOpponent", () => { | |
| it("returns an easy opponent", () => { | |
| const opp = getRandomOpponent("easy"); | |
| expect(opp.difficulty).toBe("easy"); | |
| expect(ALL_OPPONENTS).toContain(opp); | |
| }); | |
| it("returns a medium opponent", () => { | |
| const opp = getRandomOpponent("medium"); | |
| expect(opp.difficulty).toBe("medium"); | |
| }); | |
| it("returns a hard opponent", () => { | |
| const opp = getRandomOpponent("hard"); | |
| expect(opp.difficulty).toBe("hard"); | |
| }); | |
| it("returns different hard opponents over multiple calls", () => { | |
| const names = new Set<string>(); | |
| for (let i = 0; i < 50; i++) { | |
| names.add(getRandomOpponent("hard").name); | |
| } | |
| expect(names.size).toBeGreaterThan(1); | |
| }); | |
| }); | |
| // --------------------------------------------------------------------------- | |
| // getOpponentById | |
| // --------------------------------------------------------------------------- | |
| describe("getOpponentById", () => { | |
| it("finds an opponent by valid ID", () => { | |
| const opp = getOpponentById("opp-hard-socrates"); | |
| expect(opp).toBeDefined(); | |
| expect(opp!.name).toBe("Socrates"); | |
| expect(opp!.difficulty).toBe("hard"); | |
| }); | |
| it("returns undefined for invalid ID", () => { | |
| expect(getOpponentById("nonexistent")).toBeUndefined(); | |
| }); | |
| it("returns undefined for empty string", () => { | |
| expect(getOpponentById("")).toBeUndefined(); | |
| }); | |
| it("finds opponents at each difficulty", () => { | |
| expect(getOpponentById("opp-easy-balanced")?.difficulty).toBe("easy"); | |
| expect(getOpponentById("opp-med-analyst")?.difficulty).toBe("medium"); | |
| expect(getOpponentById("opp-hard-voltaire")?.difficulty).toBe("hard"); | |
| }); | |
| }); | |
| // --------------------------------------------------------------------------- | |
| // getOpponentSampler | |
| // --------------------------------------------------------------------------- | |
| describe("getOpponentSampler", () => { | |
| it("returns exactly 3 opponents", () => { | |
| const sample = getOpponentSampler(); | |
| expect(sample).toHaveLength(3); | |
| }); | |
| it("returns [easy, medium, hard] in order", () => { | |
| const [easy, medium, hard] = getOpponentSampler(); | |
| expect(easy.difficulty).toBe("easy"); | |
| expect(medium.difficulty).toBe("medium"); | |
| expect(hard.difficulty).toBe("hard"); | |
| }); | |
| it("all three are from ALL_OPPONENTS", () => { | |
| const sample = getOpponentSampler(); | |
| for (const opp of sample) { | |
| expect(ALL_OPPONENTS).toContain(opp); | |
| } | |
| }); | |
| }); | |