diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf..1a5c29421 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -18,6 +18,25 @@ test("should count multiple occurrences of a character", () => { }); // Scenario: No Occurrences +test(`should return zero the character doesn't exist in the string`, () => { + const str = "bravo"; + const char = "u"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + +// Empty String +test(`should return zero when the string is empty`, () => { + expect(countChar("", "a")).toEqual(0); +}); + +// Scenario: Multiple Occurrences +test("should count multiple occurrences of characters (including mixed and case-sensitive)", () => { + expect(countChar("aaaaa", "a")).toEqual(5); // simple multiple + expect(countChar("1-2-3-4-5-", "-")).toEqual(5); // mixed characters + expect(countChar("AaAa", "A")).toEqual(2); // case sensitivity +}); + // Given the input string `str`, // And a character `char` that does not exist within `str`. // When the function is called with these inputs, diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index adfa58560..17b39984b 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -13,8 +13,37 @@ const getOrdinalNumber = require("./get-ordinal-number"); // Case 1: Numbers ending with 1 (but not 11) // When the number ends with 1, except those ending with 11, // Then the function should return a string by appending "st" to the number. + test("should append 'st' for numbers ending with 1, except those ending with 11", () => { expect(getOrdinalNumber(1)).toEqual("1st"); expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + +// Case 2: Numbers ending with 2 (but NOT 12) +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); + expect(getOrdinalNumber(102)).toEqual("102"); +}); + +// Case 3: Numbers ending with 3 (but NOT 13) +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(33)).toEqual("33rd"); + expect(getOrdinalNumber(103)).toEqual("103rd"); +}); + +// Case 4: Numbers ending with 11, 12, or 13 --- 11,12,13,111,121,131, +test("should append 'th' for numbers ending with 11, 12, 13", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); +}); + +// Case 5: Numbers ending with larger numbers of 111, 121, 131 +test("should append 'th' for numbers ending with 111, 121, 131", () => { + expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(121)).toEqual("121th"); + expect(getOrdinalNumber(131)).toEqual("131th"); +}); diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 2af0a2cea..923599a0c 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,7 +1,7 @@ function repeatStr() { // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat). // The goal is to re-implement that function, not to use it. - return "hellohellohello"; + return String.repeat(count); } module.exports = repeatStr; diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c..e6e5058df 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -11,22 +11,39 @@ const repeatStr = require("./repeat-str"); test("should repeat the string count times", () => { const str = "hello"; - const count = 3; + const count = -5; const repeatedStr = repeatStr(str, count); expect(repeatedStr).toEqual("hellohellohello"); }); // Case: handle count of 1: +test("should repeat the string count of 1", () => { + const str = "fella"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("fella"); +}); + // Given a target string `str` and a `count` equal to 1, // When the repeatStr function is called with these inputs, // Then it should return the original `str` without repetition. // Case: Handle count of 0: +test("should repeat the string count of 0", () => { + const str = "fella"; + const count = 0; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual(""); +}); + // Given a target string `str` and a `count` equal to 0, // When the repeatStr function is called with these inputs, // Then it should return an empty string. // Case: Handle negative count: +test(`should throw an error for negative count`, () => { + expect(() => repeatedStr("fella", -2)).toThrowError(); +}); // Given a target string `str` and a negative integer `count`, // When the repeatStr function is called with these inputs, // Then it should throw an error, as negative counts are not valid.