|
1 | 1 | const getOrdinalNumber = require("./get-ordinal-number"); |
2 | | -// In this week's prep, we started implementing getOrdinalNumber. |
3 | 2 |
|
4 | | -// Continue testing and implementing getOrdinalNumber for additional cases. |
5 | | -// Write your tests using Jest — remember to run your tests often for continual feedback. |
6 | | - |
7 | | -// To ensure thorough testing, we need broad scenarios that cover all possible cases. |
8 | | -// Listing individual values, however, can quickly lead to an unmanageable number of test cases. |
9 | | -// Instead of writing tests for individual numbers, consider grouping all possible input values |
10 | | -// into meaningful categories. Then, select representative samples from each category to test. |
11 | | -// This approach improves coverage and makes our tests easier to maintain. |
12 | | - |
13 | | -// Case 1: Numbers ending with 1 (but not 11) |
14 | | -// When the number ends with 1, except those ending with 11, |
15 | | -// Then the function should return a string by appending "st" to the number. |
16 | 3 | test("should append 'st' for numbers ending with 1, except those ending with 11", () => { |
17 | 4 | expect(getOrdinalNumber(1)).toEqual("1st"); |
18 | 5 | expect(getOrdinalNumber(21)).toEqual("21st"); |
19 | 6 | expect(getOrdinalNumber(131)).toEqual("131st"); |
20 | 7 | }); |
| 8 | + |
| 9 | +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { |
| 10 | + expect(getOrdinalNumber(2)).toEqual("2nd"); |
| 11 | + expect(getOrdinalNumber(22)).toEqual("22nd"); |
| 12 | + expect(getOrdinalNumber(132)).toEqual("132nd"); |
| 13 | +}); |
| 14 | + |
| 15 | +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { |
| 16 | + expect(getOrdinalNumber(3)).toEqual("3rd"); |
| 17 | + expect(getOrdinalNumber(23)).toEqual("23rd"); |
| 18 | + expect(getOrdinalNumber(133)).toEqual("133rd"); |
| 19 | +}); |
| 20 | + |
| 21 | +test("should append 'th' for numbers ending with 11, 12, and 13", () => { |
| 22 | + expect(getOrdinalNumber(11)).toEqual("11th"); |
| 23 | + expect(getOrdinalNumber(12)).toEqual("12th"); |
| 24 | + expect(getOrdinalNumber(13)).toEqual("13th"); |
| 25 | + expect(getOrdinalNumber(111)).toEqual("111th"); |
| 26 | + expect(getOrdinalNumber(112)).toEqual("112th"); |
| 27 | + expect(getOrdinalNumber(113)).toEqual("113th"); |
| 28 | +}); |
| 29 | + |
| 30 | +test("should append 'th' for all other numbers", () => { |
| 31 | + expect(getOrdinalNumber(4)).toEqual("4th"); |
| 32 | + expect(getOrdinalNumber(10)).toEqual("10th"); |
| 33 | + expect(getOrdinalNumber(20)).toEqual("20th"); |
| 34 | + expect(getOrdinalNumber(24)).toEqual("24th"); |
| 35 | +}); |
0 commit comments