Skip to content

Commit b2a9f10

Browse files
committed
Refactor tests for countChar and getOrdinalNumber functions for clarity and consistency
1 parent d961cef commit b2a9f10

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

Sprint-3/2-practice-tdd/count.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test("should count multiple occurrences of a character", () => {
2323
// When the function is called with these inputs,
2424
// Then it should return 0, indicating that no occurrences of `char` were found.
2525

26-
test("should show no occurrences of a character", () => {
26+
test("should return 0 when the character is not present in the string", () => {
2727
const str = "aaaaa";
2828
const char = "c";
2929
const count = countChar(str, char);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
function getOrdinalNumber(num) {
2-
// 1. Handle the 11, 12, 13 exceptions first
3-
if (num === 11 || num === 12 || num === 13) {
2+
const lastTwoDigits = num % 100;
3+
4+
if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13) {
45
return num + "th";
56
}
67

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ test("should append 'th' for numbers ending with 11, 12, or 13", () => {
4444
expect(getOrdinalNumber(11)).toEqual("11th");
4545
expect(getOrdinalNumber(12)).toEqual("12th");
4646
expect(getOrdinalNumber(13)).toEqual("13th");
47+
expect(getOrdinalNumber(1312)).toEqual("1312th");
4748
});
4849

4950
// Case 5: Numbers ending with 0, 4, 5, 6, 7, 8, or 9 (but not 10)
5051
// When the number ends with 0, 4, 5, 6, 7, 8, or 9, except those ending with 10,
5152
// Then the function should return a string by appending "th" to the number.
52-
test("should append 'th' for numbers ending with 0, 4-9, except those ending with 10", () => {
53+
test("should return 'th' for numbers ending in 0 or 4 through 9", () => {
54+
expect(getOrdinalNumber(0)).toEqual("0th");
5355
expect(getOrdinalNumber(4)).toEqual("4th");
5456
expect(getOrdinalNumber(10)).toEqual("10th");
55-
expect(getOrdinalNumber(14)).toEqual("14th");
57+
expect(getOrdinalNumber(110)).toEqual("110th");
5658
});

0 commit comments

Comments
 (0)