Skip to content

Commit 17ec43c

Browse files
committed
get-ordinal-number-jest
1 parent 9d4dd77 commit 17ec43c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const getOrdinalNumber = require("./get-ordinal-number");
1010
// into meaningful categories. Then, select representative samples from each category to test.
1111
// This approach improves coverage and makes our tests easier to maintain.
1212

13+
1314
// Case 1: Numbers ending with 1 (but not 11)
1415
// When the number ends with 1, except those ending with 11,
1516
// Then the function should return a string by appending "st" to the number.
@@ -18,3 +19,47 @@ test("should append 'st' for numbers ending with 1, except those ending with 11"
1819
expect(getOrdinalNumber(21)).toEqual("21st");
1920
expect(getOrdinalNumber(131)).toEqual("131st");
2021
});
22+
23+
24+
// Case 2: Numbers ending with 2 (but not 12)
25+
// When the number ends with 2, except those ending with 12,
26+
// Then the function should return a string by appending "nd" to the number.
27+
test("should append 'nd' for numbers ending with 2, except those ending with 12", () => {
28+
expect(getOrdinalNumber(2)).toEqual("2nd");
29+
expect(getOrdinalNumber(22)).toEqual("22nd");
30+
expect(getOrdinalNumber(102)).toEqual("102nd");
31+
});
32+
33+
34+
// Case 3: Numbers ending with 3 (but not 13)
35+
// When the number ends with 3, except those ending with 13,
36+
// Then the function should return a string by appending "rd" to the number.
37+
test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
38+
expect(getOrdinalNumber(3)).toEqual("3rd");
39+
expect(getOrdinalNumber(23)).toEqual("23rd");
40+
expect(getOrdinalNumber(503)).toEqual("503rd");
41+
});
42+
43+
44+
// Case 4: Numbers ending with 11, 12, or 13
45+
// When the number ends with 11, 12, or 13,
46+
// Then the function should return a string by appending "th" to the number.
47+
test("should append 'th' for numbers ending with 11, 12, or 13", () => {
48+
expect(getOrdinalNumber(11)).toEqual("11th");
49+
expect(getOrdinalNumber(12)).toEqual("12th");
50+
expect(getOrdinalNumber(13)).toEqual("13th");
51+
expect(getOrdinalNumber(111)).toEqual("111th");
52+
expect(getOrdinalNumber(112)).toEqual("112th");
53+
expect(getOrdinalNumber(113)).toEqual("113th");
54+
});
55+
56+
57+
// Case 5: All other numbers
58+
// For numbers not ending in 1, 2, or 3 (and not 11–13),
59+
// The function should return a string by appending "th".
60+
test("should append 'th' for all other numbers", () => {
61+
expect(getOrdinalNumber(4)).toEqual("4th");
62+
expect(getOrdinalNumber(10)).toEqual("10th");
63+
expect(getOrdinalNumber(25)).toEqual("25th");
64+
expect(getOrdinalNumber(100)).toEqual("100th");
65+
});

0 commit comments

Comments
 (0)