Skip to content

Commit b1c0345

Browse files
authored
Write additional tests
1 parent 6f9d56b commit b1c0345

File tree

1 file changed

+44
-7
lines changed

1 file changed

+44
-7
lines changed

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

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,86 @@ test("should return '1st' for 1", () => {
1212
expect(getOrdinalNumber(1)).toEqual("1st");
1313
});
1414

15-
// Case 2: Identify the ordinal number for 2
15+
/// Case 2: Identify the ordinal number for 2
1616
// When the number is 2,
1717
// Then the function should return "2nd"
18-
1918
test("should return '2nd' for 2", () => {
2019
expect(getOrdinalNumber(2)).toEqual("2nd");
2120
});
2221

2322
// Case 3: Identify the ordinal number for 3
2423
// When the number is 3,
2524
// Then the function should return "3rd"
26-
2725
test("should return '3rd' for 3", () => {
2826
expect(getOrdinalNumber(3)).toEqual("3rd");
2927
});
3028

3129
// Case 4: Identify the ordinal number for 4
3230
// When the number is 4,
3331
// Then the function should return "4th"
34-
3532
test("should return '4th' for 4", () => {
3633
expect(getOrdinalNumber(4)).toEqual("4th");
3734
});
3835

3936
// Case 5: Identify the ordinal number for 11
4037
// When the number is 11,
4138
// Then the function should return "11th"
42-
4339
test("should return '11th' for 11", () => {
4440
expect(getOrdinalNumber(11)).toEqual("11th");
4541
});
4642

4743
// Case 6: Identify the ordinal number for 22
4844
// When the number is 22,
4945
// Then the function should return "22nd"
50-
5146
test("should return '22nd' for 22", () => {
5247
expect(getOrdinalNumber(22)).toEqual("22nd");
5348
});
49+
5450
// Case 7: Identify the ordinal number for 33
5551
// When the number is 33,
5652
// Then the function should return "33rd"
57-
5853
test("should return '33rd' for 33", () => {
5954
expect(getOrdinalNumber(33)).toEqual("33rd");
55+
});
56+
57+
// Case 8: Undefined input
58+
// When the input is undefined,
59+
// Then the function should return "Invalid input"
60+
test("should handle undefined input gracefully", () => {
61+
expect(getOrdinalNumber(undefined)).toEqual("Invalid input");
62+
});
63+
64+
// Case 9: Null input
65+
// When the input is null,
66+
// Then the function should return "Invalid input"
67+
test("should handle null input gracefully", () => {
68+
expect(getOrdinalNumber(null)).toEqual("Invalid input");
69+
});
70+
71+
// Case 10: Boolean input
72+
// When the input is a boolean value,
73+
// Then the function should return "Invalid input"
74+
test("should handle boolean input gracefully", () => {
75+
expect(getOrdinalNumber(true)).toEqual("Invalid input");
76+
});
77+
78+
// Case 11: Non-numeric string input
79+
// When the input is a non-numeric string,
80+
// Then the function should return "Invalid input"
81+
test("should handle non-numeric string input gracefully", () => {
82+
expect(getOrdinalNumber("hello")).toEqual("Invalid input");
83+
});
84+
85+
// Case 12: Negative number
86+
// When the input is a negative number,
87+
// Then the function should return the ordinal form with a negative sign
88+
test("should return '-1st' for -1", () => {
89+
expect(getOrdinalNumber(-1)).toEqual("-1st");
90+
});
91+
92+
// Case 13: Floating number
93+
// When the input is a floating number,
94+
// Then the function should return the ordinal with decimal intact
95+
test("should handle decimal numbers", () => {
96+
expect(getOrdinalNumber(21.5)).toEqual("21.5th");
6097
});

0 commit comments

Comments
 (0)