Skip to content

Commit f14ec50

Browse files
committed
Group tests together
1 parent 0e834a6 commit f14ec50

File tree

1 file changed

+24
-89
lines changed

1 file changed

+24
-89
lines changed
Lines changed: 24 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,45 @@
1-
const getOrdinalNumber = require("./get-ordinal-number");
2-
// In this week's prep, we started implementing getOrdinalNumber
31

4-
// continue testing and implementing getOrdinalNumber for additional cases
5-
// Write your tests using Jest - remember to run your tests often for continual feedback
2+
const getOrdinalNumber = require("./get-ordinal-number");
63

7-
// Case 1: Identify the ordinal number for 1
8-
// When the number is 1,
9-
// Then the function should return "1st"
4+
// To ensure thorough testing, we need broad scenario coverage. Listing individual values, however, can quickly lead to an unmanageable number of test cases.
5+
// Instead of writing tests for individual numbers, we group all possible input values into meaningful categories and select representative samples from each category to test. This approach improves coverage and makes our tests easier to maintain.
106

11-
test("should return '1st' for 1", () => {
7+
// Numbers ending in 1 (except those ending in 11): should append 'st'
8+
test("append 'st' to numbers ending in 1, except those ending in 11", () => {
129
expect(getOrdinalNumber(1)).toEqual("1st");
10+
expect(getOrdinalNumber(21)).toEqual("21st");
11+
expect(getOrdinalNumber(101)).toEqual("101st");
1312
});
1413

15-
// Case 2: Identify the ordinal number for 2
16-
// When the number is 2,
17-
// Then the function should return "2nd"
18-
19-
test("should return '2nd' for 2", () => {
14+
// Numbers ending in 2 (except those ending in 12): should append 'nd'
15+
test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
2016
expect(getOrdinalNumber(2)).toEqual("2nd");
17+
expect(getOrdinalNumber(22)).toEqual("22nd");
18+
expect(getOrdinalNumber(132)).toEqual("132nd");
2119
});
2220

23-
// Case 3: Identify the ordinal number for 3
24-
// When the number is 3,
25-
// Then the function should return "3rd"
26-
27-
test("should return '3rd' for 3", () => {
21+
// Numbers ending in 3 (except those ending in 13): should append 'rd'
22+
test("append 'rd' to numbers ending in 3, except those ending in 13", () => {
2823
expect(getOrdinalNumber(3)).toEqual("3rd");
24+
expect(getOrdinalNumber(23)).toEqual("23rd");
25+
expect(getOrdinalNumber(103)).toEqual("103rd");
2926
});
3027

31-
// Case 4: Identify the ordinal number for 4
32-
// When the number is 4,
33-
// Then the function should return "4th"
34-
35-
test("should return '4th' for 4", () => {
36-
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", () => {
28+
// Numbers ending in 11, 12, 13: should append 'th'
29+
test("append 'th' to numbers ending in 11, 12, 13", () => {
4430
expect(getOrdinalNumber(11)).toEqual("11th");
45-
});
46-
47-
// Case 6: Identify the ordinal number for 12
48-
// When the number is 12,
49-
// Then the function should return "12th"
50-
51-
test("should return '12th' for 12", () => {
5231
expect(getOrdinalNumber(12)).toEqual("12th");
53-
});
54-
55-
// Case 7: Identify the ordinal number for 13
56-
// When the number is 13,
57-
// Then the function should return "13th"
58-
59-
test("should return '13th' for 13", () => {
6032
expect(getOrdinalNumber(13)).toEqual("13th");
61-
});
62-
63-
// Case 8: Identify the ordinal number for 21
64-
// When the number is 21,
65-
// Then the function should return "21st"
66-
67-
test("should return '21st' for 21", () => {
68-
expect(getOrdinalNumber(21)).toEqual("21st");
69-
});
70-
71-
// Case 9: Identify the ordinal number for 22
72-
// When the number is 22,
73-
// Then the function should return "22nd"
74-
75-
test("should return '22nd' for 22", () => {
76-
expect(getOrdinalNumber(22)).toEqual("22nd");
77-
});
78-
79-
// Case 10: Identify the ordinal number for 23
80-
// When the number is 23,
81-
// Then the function should return "23rd"
82-
83-
test("should return '23rd' for 23", () => {
84-
expect(getOrdinalNumber(23)).toEqual("23rd");
85-
});
86-
87-
// Case 11: Identify the ordinal number for 101
88-
// When the number is 101,
89-
// Then the function should return "101st"
90-
91-
test("should return '101st' for 101", () => {
92-
expect(getOrdinalNumber(101)).toEqual("101st");
93-
});
94-
95-
// Case 12: Identify the ordinal number for 111
96-
// When the number is 111,
97-
// Then the function should return "111th"
98-
99-
test("should return '111th' for 111", () => {
10033
expect(getOrdinalNumber(111)).toEqual("111th");
34+
expect(getOrdinalNumber(112)).toEqual("112th");
35+
expect(getOrdinalNumber(113)).toEqual("113th");
10136
});
10237

103-
// Case 13: Identify the ordinal number for 0
104-
// When the number is 0,
105-
// Then the function should return "0th"
106-
107-
test("should return '0th' for 0", () => {
38+
// All other numbers: should append 'th'
39+
test("append 'th' to all other numbers", () => {
40+
expect(getOrdinalNumber(4)).toEqual("4th");
41+
expect(getOrdinalNumber(10)).toEqual("10th");
42+
expect(getOrdinalNumber(14)).toEqual("14th");
10843
expect(getOrdinalNumber(0)).toEqual("0th");
10944
});
11045

0 commit comments

Comments
 (0)