Skip to content

Commit 8b8e22f

Browse files
committed
categorised the test-cases
1 parent a87356b commit 8b8e22f

File tree

1 file changed

+28
-39
lines changed

1 file changed

+28
-39
lines changed

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

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,70 +8,59 @@ 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+
// category 1: ends with 1 (but not 11) -> "st"
12+
test("append 'st' to numbers ending in 1, except those ending in 11", () => {
1213
expect(getOrdinalNumber(1)).toEqual("1st");
14+
expect(getOrdinalNumber(21)).toEqual("21st");
15+
expect(getOrdinalNumber(101)).toEqual("101st");
1316
});
1417

1518
// Case 2: Identify the ordinal number for 2
1619
// When the number is 2,
1720
// Then the function should return "2nd"
1821

19-
test("should return '2nd' for 2", () => {
22+
// category 2: ends with 2 (but not 12) -> "nd"
23+
test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
2024
expect(getOrdinalNumber(2)).toEqual("2nd");
25+
expect(getOrdinalNumber(22)).toEqual("22nd");
26+
expect(getOrdinalNumber(102)).toEqual("102nd");
2127
});
2228

2329
// Case 3: Identify the ordinal number for 3
2430
// When the number is 3,
2531
// Then the function should return "3rd"
2632

27-
test("should return '3rd' for 3", () => {
33+
// category 3: ends with 3 (but not 13) -> "rd"
34+
test("append 'rd' to numbers ending in 3, except those ending in 13", () => {
2835
expect(getOrdinalNumber(3)).toEqual("3rd");
36+
expect(getOrdinalNumber(23)).toEqual("23rd");
37+
expect(getOrdinalNumber(103)).toEqual("103rd");
2938
});
3039

3140
// Case 4: Identify the ordinal number for 4
3241
// When the number is 4,
3342
// Then the function should return "4th"
3443

35-
test("should return '4th' for 4", () => {
44+
// category 4: all other numbers -> "th"
45+
test("append 'th' to all other numbers", () => {
3646
expect(getOrdinalNumber(4)).toEqual("4th");
37-
});
38-
39-
// Case 5: Identify the ordinal number for 11
40-
// When the number is 11,
41-
// Then the function should return "11th"
42-
43-
test("should return '11th' for 11", () => {
4447
expect(getOrdinalNumber(11)).toEqual("11th");
48+
expect(getOrdinalNumber(12)).toEqual("12th");
49+
expect(getOrdinalNumber(13)).toEqual("13th");
50+
expect(getOrdinalNumber(14)).toEqual("14th");
51+
expect(getOrdinalNumber(111)).toEqual("111th");
52+
expect(getOrdinalNumber(112)).toEqual("112th");
53+
expect(getOrdinalNumber(113)).toEqual("113th");
54+
expect(getOrdinalNumber(114)).toEqual("114th");
4555
});
4656

47-
// Case 6: Identify the ordinal number for 21
48-
// When the number is 21,
49-
// Then the function should return "21st"
50-
51-
test("should return '21st' for 21", () => {
52-
expect(getOrdinalNumber(21)).toEqual("21st");
53-
});
54-
55-
// Case 7: Identify the ordinal number for 102
56-
// When the number is 102,
57-
// Then the function should return "102nd"
58-
59-
test("should return '102nd' for 102", () => {
60-
expect(getOrdinalNumber(102)).toEqual("102nd");
61-
});
62-
63-
// Case 8: Identify the ordinal number for 111
64-
// When the number is 111,
65-
// Then the function should return "111th"
66-
67-
test("should return '111th' for 111", () => {
57+
// category 5: special case for 11, 12, 13 -> "th"
58+
test("append 'th' to numbers ending in 11, 12, or 13", () => {
59+
expect(getOrdinalNumber(11)).toEqual("11th");
60+
expect(getOrdinalNumber(12)).toEqual("12th");
61+
expect(getOrdinalNumber(13)).toEqual("13th");
6862
expect(getOrdinalNumber(111)).toEqual("111th");
63+
expect(getOrdinalNumber(112)).toEqual("112th");
64+
expect(getOrdinalNumber(113)).toEqual("113th");
6965
});
7066

71-
// case 9: identify the ordinal number for 211
72-
// when the number is 211
73-
// then the function should return "211th"
74-
75-
test("should return '33rd' for 33", () => {
76-
expect(getOrdinalNumber(33)).toEqual("33rd");
77-
});

0 commit comments

Comments
 (0)