File size: 2,668 Bytes
9580dce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | 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
});
});
|