From bd8ab4b8d6bf6244b7882b7df1d0e8a3a1910ce6 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Fri, 14 Nov 2025 23:30:14 +0000 Subject: [PATCH 1/8] I Added working countChar function --- Sprint-3/2-practice-tdd/count.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 42baf4b4b..76c091514 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -3,6 +3,14 @@ const countChar = require("./count"); // Given a string str and a single character char to search for, // When the countChar function is called with these inputs, // Then it should: +test("count how many times a character occurs a string", () => { + const stringOfCharacters = "kiwi"; + const findCharacter = "w"; + + const result = countChar(stringOfCharacters, findCharacter); + + expect(result).toBe(5); +}); // Scenario: Multiple Occurrences // Given the input string str, From 943e88e635ae9ee1fe415d527dd35df1335f46d2 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Fri, 14 Nov 2025 23:37:09 +0000 Subject: [PATCH 2/8] I Added working countChar function --- Sprint-3/2-practice-tdd/count.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..d00962e1c 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,12 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + + for (let i = 0; i < stringOfCharacters.length; i++) { + if (stringOfCharacters[i] ===findCharacter) { + count++; + } + } + return count; } module.exports = countChar; From b8e36c43ad0fe7165ec70fde2bd30408abfdfaec Mon Sep 17 00:00:00 2001 From: khalidbih Date: Sat, 15 Nov 2025 00:40:49 +0000 Subject: [PATCH 3/8] I Covered 3 different countChar cases --- Sprint-3/2-practice-tdd/count.test.js | 29 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 76c091514..5d992b066 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -3,14 +3,6 @@ const countChar = require("./count"); // Given a string str and a single character char to search for, // When the countChar function is called with these inputs, // Then it should: -test("count how many times a character occurs a string", () => { - const stringOfCharacters = "kiwi"; - const findCharacter = "w"; - - const result = countChar(stringOfCharacters, findCharacter); - - expect(result).toBe(5); -}); // Scenario: Multiple Occurrences // Given the input string str, @@ -30,3 +22,24 @@ test("should count multiple occurrences of a character", () => { // And a character char that does not exist within the case-sensitive str, // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. + +test("returns 0 if the character is not in the string", () => { + const str = "bread"; + const char = "z"; + const count = countChar(str, char); + expect(count).toBe(0); +}); + +test("counts a character that appears once", () => { + const str = "bread"; + const char = "d"; + const count = countChar(str, char); + expect(count).toBe(1); +}); + +test("counts how many times a character appears", () => { + const str = "breadboard"; + const char = "b"; + const count = countChar(str, char); + expect(count).toBe(2); +}); \ No newline at end of file From fd6e675372f7caae8465ac7b9367b67750e60069 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Wed, 19 Nov 2025 00:35:23 +0000 Subject: [PATCH 4/8] Added getOrdinalNumber function --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db1..6bd73b7e2 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,21 @@ -function getOrdinalNumber(num) { - return "1st"; +function getOrdinalNumber(num){ + const lastTwoDigits = num % 100; + if (lastTwoDigits >= 11 && lastTwoDigits <= 13){ + return num+ "th"; + } + + const lastDigits = num %10; + + switch (lastDigit){ + case 1: + return num + "st"; + case 2: + return num + "nd"; + case 3: + return num + "rd"; + default: + return num + "th"; + } } module.exports = getOrdinalNumber; From b58f10ca869c588743e3a02d35d11d342abfeffd Mon Sep 17 00:00:00 2001 From: khalidbih Date: Wed, 19 Nov 2025 20:37:46 +0000 Subject: [PATCH 5/8] Added getOrdinalNumber function --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 2 +- .../2-practice-tdd/get-ordinal-number.test.js | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 6bd73b7e2..1b4112011 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -4,7 +4,7 @@ function getOrdinalNumber(num){ return num+ "th"; } - const lastDigits = num %10; + const lastDigit = num %10; switch (lastDigit){ case 1: 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 dfe4b6091..f7efd301a 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -11,3 +11,48 @@ const getOrdinalNumber = require("./get-ordinal-number"); 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 return '11th', '12th', '13th' for special cases", () => { + 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 return '21st', '22nd', '23rd'", () => { + 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(4)).toEqual("4th"); + expect(getOrdinalNumber(5)).toEqual("5th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(24)).toEqual("24th"); + expect(getOrdinalNumber(100)).toEqual("100th"); +}); + + + + From 66efc4793bef956ecab2b4cc96fde7240d6816ab Mon Sep 17 00:00:00 2001 From: khalidbih Date: Wed, 19 Nov 2025 21:15:04 +0000 Subject: [PATCH 6/8] Added repeat function with negative count check --- Sprint-3/2-practice-tdd/repeat.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index 00e60d7f3..cc0269860 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,5 +1,9 @@ -function repeat() { - return "hellohellohello"; +function repeat(str, count) { + if (count < 0){ + throw new Error("count cannot be negative"); + } + + return str.repeat(count); } module.exports = repeat; From 9fc5d58a7180d12d53d85b0957155dbd45496750 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Wed, 19 Nov 2025 22:58:03 +0000 Subject: [PATCH 7/8] Added repeat function and tests with jest --- Sprint-3/2-practice-tdd/repeat.test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat.test.js b/Sprint-3/2-practice-tdd/repeat.test.js index 34097b09c..3515532e1 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -21,12 +21,32 @@ test("should repeat the string count times", () => { // When the repeat function is called with these inputs, // Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. +test("should return the original string when count is 1", () => { + const str = "hello"; + const count = 1; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("hello"); +}); + // case: Handle Count of 0: // Given a target string str and a count equal to 0, // When the repeat function is called with these inputs, // Then it should return an empty string, ensuring that a count of 0 results in an empty output. +test("should return an empty string when count is 0", () => { + const str = "hello"; + const count = 0; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual(""); +}); + // case: Negative Count: // Given a target string str and a negative integer count, // When the repeat function is called with these inputs, // Then it should throw an error or return an appropriate error message, as negative counts are not valid. + +test("should throw an error for negative count", () => { + const str = "hello"; + const count = -3; + expect(() => repeat(str, count)).toThrow("count cannot be negative"); +}); \ No newline at end of file From f829a044eec67ae93fd22acc0d16fe1bccacebc3 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Fri, 21 Nov 2025 17:50:39 +0000 Subject: [PATCH 8/8] Clarified test descriptions for getOrdinalNumber --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 f7efd301a..58132e1a7 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -27,7 +27,7 @@ test("should return '4th' for 4", () => { expect(getOrdinalNumber(4)).toEqual("4th"); }); -test("should return '11th', '12th', '13th' for special cases", () => { +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"); @@ -36,7 +36,7 @@ test("should return '11th', '12th', '13th' for special cases", () => { expect(getOrdinalNumber(113)).toEqual("113th"); }); -test("should return '21st', '22nd', '23rd'", () => { +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"); @@ -46,7 +46,6 @@ test("should return '21st', '22nd', '23rd'", () => { }); test("should return correct 'th' for numbers ending in 4-9 or 0", () => { - expect(getOrdinalNumber(4)).toEqual("4th"); expect(getOrdinalNumber(5)).toEqual("5th"); expect(getOrdinalNumber(10)).toEqual("10th"); expect(getOrdinalNumber(24)).toEqual("24th");