Download src/lib/coding/__tests__/bank.test.ts from NAP1320/RotNot: direct link, hf CLI and curl.
- Browser
- Download file 3.93 kB
-
https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/lib/coding/__tests__/bank.test.ts
- Command line
-
hf download hf://spaces/NAP1320/RotNot/src/lib/coding/__tests__/bank.test.ts
-
curl -L -o bank.test.ts https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/lib/coding/__tests__/bank.test.ts
3.93 kB
| import { PROBLEM_BANK, pickProblem, bankStats } from "../bank"; | |
| import { validateProblem } from "../validate"; | |
| import { | |
| CODING_PROBLEM_TYPES, | |
| CODING_DIFFICULTIES, | |
| isExecutableType, | |
| } from "../types"; | |
| describe("PROBLEM_BANK integrity", () => { | |
| it("is non-empty", () => { | |
| expect(PROBLEM_BANK.length).toBeGreaterThan(0); | |
| }); | |
| it("every problem has a known, verifiable answer (validateProblem passes)", () => { | |
| for (const problem of PROBLEM_BANK) { | |
| const res = validateProblem(problem); | |
| expect(res.valid, `${problem.id}: ${res.reason ?? ""}`).toBe(true); | |
| } | |
| }); | |
| it("has globally unique ids", () => { | |
| const ids = PROBLEM_BANK.map((p) => p.id); | |
| expect(new Set(ids).size).toBe(ids.length); | |
| }); | |
| it("only tags executable problems with executable-friendly content", () => { | |
| for (const p of PROBLEM_BANK) { | |
| if (p.type === "code-creation") { | |
| expect(p.entryFunction.length).toBeGreaterThan(0); | |
| expect(p.tests.length).toBeGreaterThan(0); | |
| } | |
| if (p.type === "debugging") { | |
| expect(p.buggyCode.length).toBeGreaterThan(0); | |
| expect(p.tests.length).toBeGreaterThan(0); | |
| } | |
| } | |
| }); | |
| it("includes at least one hidden test per executable problem", () => { | |
| for (const p of PROBLEM_BANK) { | |
| if (isExecutableType(p.type)) { | |
| const tests = (p as { tests: { hidden?: boolean }[] }).tests; | |
| expect(tests.some((t) => t.hidden)).toBe(true); | |
| } | |
| } | |
| }); | |
| it("covers every problem type", () => { | |
| for (const type of CODING_PROBLEM_TYPES) { | |
| expect(PROBLEM_BANK.some((p) => p.type === type)).toBe(true); | |
| } | |
| }); | |
| it("covers every difficulty", () => { | |
| for (const diff of CODING_DIFFICULTIES) { | |
| expect(PROBLEM_BANK.some((p) => p.difficulty === diff)).toBe(true); | |
| } | |
| }); | |
| it("offers a JavaScript executable problem for each difficulty", () => { | |
| for (const diff of CODING_DIFFICULTIES) { | |
| const match = PROBLEM_BANK.some( | |
| (p) => | |
| p.language === "javascript" && | |
| isExecutableType(p.type) && | |
| p.difficulty === diff, | |
| ); | |
| expect(match, `no executable JS problem for ${diff}`).toBe(true); | |
| } | |
| }); | |
| }); | |
| describe("pickProblem", () => { | |
| it("returns a problem matching the requested type and difficulty", () => { | |
| const p = pickProblem({ | |
| type: "code-creation", | |
| difficulty: "easy", | |
| language: "javascript", | |
| }); | |
| expect(p).not.toBeNull(); | |
| expect(p!.type).toBe("code-creation"); | |
| expect(p!.difficulty).toBe("easy"); | |
| }); | |
| it("honors the requested language when a match exists", () => { | |
| const p = pickProblem({ | |
| type: "code-review", | |
| difficulty: "medium", | |
| language: "python", | |
| }); | |
| if (p) expect(p.language).toBe("python"); | |
| }); | |
| it("is deterministic when given a fixed rng", () => { | |
| const opts = { | |
| type: "code-creation" as const, | |
| difficulty: "easy" as const, | |
| language: "javascript" as const, | |
| rng: () => 0, | |
| }; | |
| const a = pickProblem(opts); | |
| const b = pickProblem(opts); | |
| expect(a!.id).toBe(b!.id); | |
| }); | |
| it("returns null for an impossible combination", () => { | |
| const p = pickProblem({ | |
| // no executable problems exist in Go in the bank | |
| type: "code-creation", | |
| difficulty: "easy", | |
| language: "go", | |
| strictLanguage: true, | |
| }); | |
| expect(p).toBeNull(); | |
| }); | |
| it("falls back to a JS executable problem when language is non-executable and not strict", () => { | |
| const p = pickProblem({ | |
| type: "debugging", | |
| difficulty: "medium", | |
| language: "go", | |
| }); | |
| expect(p).not.toBeNull(); | |
| expect(p!.language).toBe("javascript"); | |
| }); | |
| }); | |
| describe("bankStats", () => { | |
| it("reports counts that sum to the bank size", () => { | |
| const stats = bankStats(); | |
| const total = Object.values(stats.byType).reduce((a, b) => a + b, 0); | |
| expect(total).toBe(PROBLEM_BANK.length); | |
| }); | |
| }); | |