forked from codechefPesuecc/CodeChef-PESUECC-Chapter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenges.test.ts
More file actions
68 lines (61 loc) · 2.18 KB
/
Copy pathchallenges.test.ts
File metadata and controls
68 lines (61 loc) · 2.18 KB
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
import { describe, it, expect } from "vitest";
import {
parseTimeLimitMs,
parseMemoryLimitBytes,
isReleased,
toPublicContent,
type Challenge,
} from "./challenges";
// These cover the pure helpers only. The readers (getDailyChallenge, …) hit the
// database and are exercised by the end-to-end/seed flow, not unit tests.
describe("parseTimeLimitMs", () => {
it("parses seconds and milliseconds", () => {
expect(parseTimeLimitMs("1s")).toBe(1000);
expect(parseTimeLimitMs("2 s")).toBe(2000);
expect(parseTimeLimitMs("500ms")).toBe(500);
expect(parseTimeLimitMs("1.5s")).toBe(1500);
});
it("falls back when absent or unparseable", () => {
expect(parseTimeLimitMs(undefined)).toBe(2000);
expect(parseTimeLimitMs("abc")).toBe(2000);
expect(parseTimeLimitMs(undefined, 3000)).toBe(3000);
});
});
describe("parseMemoryLimitBytes", () => {
it("parses binary units (MB == MiB)", () => {
expect(parseMemoryLimitBytes("256 MB", 0)).toBe(256 * 1024 * 1024);
expect(parseMemoryLimitBytes("256MiB", 0)).toBe(256 * 1024 * 1024);
expect(parseMemoryLimitBytes("512m", 0)).toBe(512 * 1024 * 1024);
expect(parseMemoryLimitBytes("1g", 0)).toBe(1024 ** 3);
});
it("falls back when absent or unparseable", () => {
expect(parseMemoryLimitBytes(undefined, 42)).toBe(42);
expect(parseMemoryLimitBytes("nope", 42)).toBe(42);
});
});
describe("isReleased", () => {
it("releases past-dated problems and hides future-dated ones", () => {
expect(isReleased({ date: "2000-01-01" })).toBe(true);
expect(isReleased({ date: "2999-12-31" })).toBe(false);
});
});
describe("toPublicContent", () => {
it("strips hidden tests and the checker", () => {
const full: Challenge = {
slug: "sample",
title: "Sample",
difficulty: "Easy",
tags: ["x"],
date: "2026-01-01",
statement: "…",
samples: [{ input: "1", output: "2" }],
checker: { type: "token" },
tests: [{ input: "3", output: "4" }],
};
const pub = toPublicContent(full);
expect(pub).not.toHaveProperty("tests");
expect(pub).not.toHaveProperty("checker");
expect(pub.slug).toBe("sample");
expect(pub.samples).toHaveLength(1);
});
});