Skip to content
19 changes: 10 additions & 9 deletions Sprint-3/2-practice-tdd/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ test("counts a single occurrence of a character", () => {
// When the function is called with these inputs,
// Then it should correctly count overlapping occurrences of char (e.g., 'a' appears five times in 'aaaaa').
test("counts multiple occurrences of a character", () => {
expect(countChar("banana", "a")).toEqual(3);
expect(countChar("mississippi", "s")).toEqual(4);
});

test("should count multiple occurrences of a character", () => {
const str = "aaaaa";
const Char = "a";
const count = countChar(str,Char);
expect(count).toEqual(5);
expect(countChar("aaaaa", "a")).toEqual(5);
expect(countChar("banana", "a")).toEqual(3);
expect(countChar("mississippi", "s")).toEqual(4);
});

//test("should count multiple occurrences of a character", () => {
// const str = "aaaaa";
//const Char = "a";
//const count = countChar(str,Char);
// expect(count).toEqual(5);
//});

Comment on lines +24 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep the code clean, why not delete all unused code?

// Scenario: No Occurrences
// Given the input string str,
// And a character char that does not exist within the case-sensitive str,
Expand Down
1 change: 1 addition & 0 deletions Sprint-3/2-practice-tdd/get-ordinal-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function getOrdinalNumber(num) {
return num + "rd";
default:
return num + "th";

}
}

Expand Down
53 changes: 39 additions & 14 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
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", () => {
// Case 1: Numbers ending in 1 (but not 11)
test("append 'st' to numbers ending in 1, except those ending in 11", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(21)).toEqual("21st");
expect(getOrdinalNumber(101)).toEqual("101st");
expect(getOrdinalNumber(111)).toEqual("111th"); // exception
});

// Case 2: Numbers ending in 2 (but not 12)
test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
expect(getOrdinalNumber(22)).toEqual("22nd");
expect(getOrdinalNumber(102)).toEqual("102nd");
expect(getOrdinalNumber(112)).toEqual("112th"); // exception
});
test("should return 'th' for 11, 12, 13", () => {
expect(getOrdinalNumber(11)).toBe("11th");
expect(getOrdinalNumber(12)).toBe("12th");
expect(getOrdinalNumber(13)).toBe("13th");
// Case 3: Numbers ending in 3 (but not 13)
test("append 'rd' to numbers ending in 3, except those ending in 13", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
expect(getOrdinalNumber(23)).toEqual("23rd");
expect(getOrdinalNumber(103)).toEqual("103rd");
expect(getOrdinalNumber(113)).toEqual("113th"); // exception
});
test("should return correct ordinal for numbers > 20", () => {
expect(getOrdinalNumber(21)).toBe("21st");
expect(getOrdinalNumber(22)).toBe("22nd");
expect(getOrdinalNumber(23)).toBe("23rd");
});
// Case 4: Numbers ending in 4–9 or exceptions (11, 12, 13)
test("append 'th' to numbers ending in 4–9 or ending with 11, 12, or 13", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
expect(getOrdinalNumber(9)).toEqual("9th");
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(12)).toEqual("12th");
expect(getOrdinalNumber(13)).toEqual("13th");
});
// Optional: edge cases
test("should handle 0 and large numbers correctly", () => {
expect(getOrdinalNumber(0)).toBe("0th");
expect(getOrdinalNumber(1000001)).toBe("1000001st"); // ends with 1, not teen
expect(getOrdinalNumber(1000012)).toBe("1000012th"); // ends with 12 -> teen

});