-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-ordinal-number.test.js
More file actions
57 lines (41 loc) · 1.77 KB
/
get-ordinal-number.test.js
File metadata and controls
57 lines (41 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const getOrdinalNumber = require("./get-ordinal-number");
// In this week's prep, we started implementing getOrdinalNumber
// continue testing and implementing getOrdinalNumber for additional cases
// Write your tests using Jest - remember to run your tests often for continual feedback
// Case 1: Identify the ordinal number for 1
// When the number is 1,
// Then the function should return "1st"
test("should return '1st' for 1", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
});
test("should return '2nd' for 2", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
});
test("should return '3rd' for 3", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
});
test("should return '4th' for 4", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
});
test("should add 'th' for numbers ending in 11, 12, or 13", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(12)).toEqual("12th");
expect(getOrdinalNumber(13)).toEqual("13th");
expect(getOrdinalNumber(111)).toEqual("111th");
expect(getOrdinalNumber(112)).toEqual("112th");
expect(getOrdinalNumber(113)).toEqual("113th");
});
test("should add 'st', 'nd', or 'rd' for numbers ending in 1, 2, or 3 (except 11,13)", () => {
expect(getOrdinalNumber(21)).toEqual("21st");
expect(getOrdinalNumber(22)).toEqual("22nd");
expect(getOrdinalNumber(23)).toEqual("23rd");
expect(getOrdinalNumber(101)).toEqual("101st");
expect(getOrdinalNumber(102)).toEqual("102nd");
expect(getOrdinalNumber(103)).toEqual("103rd");
});
test("should return correct 'th' for numbers ending in 4-9 or 0", () => {
expect(getOrdinalNumber(5)).toEqual("5th");
expect(getOrdinalNumber(10)).toEqual("10th");
expect(getOrdinalNumber(24)).toEqual("24th");
expect(getOrdinalNumber(100)).toEqual("100th");
});