forked from codechefPesuecc/CodeChef-PESUECC-Chapter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoints.test.ts
More file actions
54 lines (48 loc) · 1.58 KB
/
Copy pathpoints.test.ts
File metadata and controls
54 lines (48 loc) · 1.58 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
import { describe, it, expect } from "vitest";
import {
pointsForRank,
ordinal,
BOUNTY_LADDER,
SPEED_BOUNTY,
BASE_POINTS,
} from "./points";
describe("pointsForRank", () => {
it("awards the speed bounty for the top ranks", () => {
expect(pointsForRank(1)).toBe(1000);
expect(pointsForRank(2)).toBe(800);
expect(pointsForRank(9)).toBe(150);
});
it("awards base points from 10th onward", () => {
expect(pointsForRank(10)).toBe(BASE_POINTS);
expect(pointsForRank(100)).toBe(BASE_POINTS);
});
it("treats non-positive/invalid ranks as base", () => {
expect(pointsForRank(0)).toBe(BASE_POINTS);
expect(pointsForRank(-3)).toBe(BASE_POINTS);
});
});
describe("ordinal", () => {
it("uses the right suffix for common numbers", () => {
expect(ordinal(1)).toBe("1st");
expect(ordinal(2)).toBe("2nd");
expect(ordinal(3)).toBe("3rd");
expect(ordinal(4)).toBe("4th");
expect(ordinal(21)).toBe("21st");
expect(ordinal(22)).toBe("22nd");
expect(ordinal(23)).toBe("23rd");
});
it("handles the 11-13 exception", () => {
expect(ordinal(11)).toBe("11th");
expect(ordinal(12)).toBe("12th");
expect(ordinal(13)).toBe("13th");
expect(ordinal(111)).toBe("111th");
expect(ordinal(112)).toBe("112th");
});
});
describe("BOUNTY_LADDER", () => {
it("is one row per bounty tier plus a base row", () => {
expect(BOUNTY_LADDER).toHaveLength(SPEED_BOUNTY.length + 1);
expect(BOUNTY_LADDER[0]).toEqual({ label: "1st", points: 1000 });
expect(BOUNTY_LADDER.at(-1)).toEqual({ label: "10th+", points: BASE_POINTS });
});
});