Skip to content

Commit 5b62a72

Browse files
committed
Added possible and invalid cases and tested using npx jest
1 parent a1a791e commit 5b62a72

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

Sprint-3/2-practice-tdd/get-ordinal-number.test.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,39 @@ const getOrdinalNumber = require("./get-ordinal-number");
88
// When the number is 1,
99
// Then the function should return "1st"
1010

11-
test("should return '1st' for 1", () => {
11+
// Case 1: 1 → Standard ordinals
12+
13+
test("should return correct ordinals for 1, 2, 3, 4, 21, 22, 23, 24", () => {
1214
expect(getOrdinalNumber(1)).toEqual("1st");
15+
expect(getOrdinalNumber(2)).toEqual("2nd");
16+
expect(getOrdinalNumber(3)).toEqual("3rd");
17+
expect(getOrdinalNumber(4)).toEqual("4th");
18+
expect(getOrdinalNumber(21)).toEqual("21st");
19+
expect(getOrdinalNumber(22)).toEqual("22nd");
20+
expect(getOrdinalNumber(23)).toEqual("23rd");
21+
expect(getOrdinalNumber(24)).toEqual("24th");
22+
});
23+
24+
// Case 2: Exceptions 11, 12, 13
25+
test("should handle exceptions 11, 12, 13 correctly", () => {
26+
expect(getOrdinalNumber(11)).toEqual("11th");
27+
expect(getOrdinalNumber(12)).toEqual("12th");
28+
expect(getOrdinalNumber(13)).toEqual("13th");
29+
expect(getOrdinalNumber(111)).toEqual("111th");
30+
});
31+
32+
// Case 3: Large numbers
33+
test("should handle larger numbers correctly", () => {
34+
expect(getOrdinalNumber(101)).toEqual("101st");
35+
expect(getOrdinalNumber(112)).toEqual("112th");
36+
expect(getOrdinalNumber(123)).toEqual("123rd");
37+
});
38+
39+
// Case 4: Invalid cases / inputs
40+
test("should throw error for zero, negative or non-integer inputs", () => {
41+
expect(() => getOrdinalNumber(0)).toThrow("Only positive integers are allowed");
42+
expect(() => getOrdinalNumber(-5)).toThrow("Only positive integers are allowed");
43+
expect(() => getOrdinalNumber(2.5)).toThrow("Only positive integers are allowed");
1344
});
45+
46+
// Added possible and invalid cases and tested using npx jest

0 commit comments

Comments
 (0)