Download src/lib/coding/__tests__/serialize.test.ts from NAP1320/RotNot: direct link, hf CLI and curl.
- Browser
- Download file 2.67 kB
-
https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/lib/coding/__tests__/serialize.test.ts
- Command line
-
hf download hf://spaces/NAP1320/RotNot/src/lib/coding/__tests__/serialize.test.ts
-
curl -L -o serialize.test.ts https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/lib/coding/__tests__/serialize.test.ts
2.67 kB
| import { toPublicProblem } from "../serialize"; | |
| import type { | |
| CodeCreationProblem, | |
| CodeReviewProblem, | |
| ArchitectureProblem, | |
| DebuggingProblem, | |
| } from "../types"; | |
| describe("toPublicProblem", () => { | |
| it("strips the reference solution and hidden tests from code-creation", () => { | |
| const p: CodeCreationProblem = { | |
| id: "p1", | |
| type: "code-creation", | |
| language: "javascript", | |
| difficulty: "easy", | |
| title: "t", | |
| prompt: "p", | |
| entryFunction: "add", | |
| starterCode: "function add(){}", | |
| referenceSolution: "function add(a,b){return a+b}", | |
| tests: [ | |
| { name: "shown", input: [1, 1], expected: 2, hidden: false }, | |
| { name: "secret", input: [9, 9], expected: 18, hidden: true }, | |
| ], | |
| }; | |
| const pub = toPublicProblem(p) as { tests: unknown[] } & Record<string, unknown>; | |
| expect("referenceSolution" in pub).toBe(false); | |
| expect(pub.tests).toHaveLength(1); | |
| expect((pub.tests[0] as { name: string }).name).toBe("shown"); | |
| expect(pub.starterCode).toBe("function add(){}"); | |
| }); | |
| it("strips the known issues from code-review", () => { | |
| const p: CodeReviewProblem = { | |
| id: "r1", | |
| type: "code-review", | |
| language: "javascript", | |
| difficulty: "medium", | |
| title: "t", | |
| prompt: "p", | |
| code: "function f(){}", | |
| issues: [{ id: "x", title: "a", description: "b", severity: "minor" }], | |
| }; | |
| const pub = toPublicProblem(p) as Record<string, unknown>; | |
| expect("issues" in pub).toBe(false); | |
| expect(pub.code).toBe("function f(){}"); | |
| }); | |
| it("strips the rubric from architecture", () => { | |
| const p: ArchitectureProblem = { | |
| id: "a1", | |
| type: "architecture", | |
| language: "go", | |
| difficulty: "hard", | |
| title: "t", | |
| prompt: "p", | |
| rubric: [{ id: "x", point: "y", weight: 1 }], | |
| }; | |
| const pub = toPublicProblem(p) as Record<string, unknown>; | |
| expect("rubric" in pub).toBe(false); | |
| expect(pub.prompt).toBe("p"); | |
| }); | |
| it("keeps the buggy code for debugging but strips the reference fix", () => { | |
| const p: DebuggingProblem = { | |
| id: "d1", | |
| type: "debugging", | |
| language: "javascript", | |
| difficulty: "medium", | |
| title: "t", | |
| prompt: "p", | |
| entryFunction: "f", | |
| buggyCode: "function f(){return 0}", | |
| referenceSolution: "function f(){return 1}", | |
| tests: [{ name: "h", input: [], expected: 1, hidden: true }], | |
| }; | |
| const pub = toPublicProblem(p) as Record<string, unknown>; | |
| expect("referenceSolution" in pub).toBe(false); | |
| expect(pub.buggyCode).toBe("function f(){return 0}"); | |
| expect(pub.tests).toHaveLength(0); // all hidden | |
| }); | |
| }); | |