From e827d26c5b4a6344f61866b283a039f67d6d09bd Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Fri, 20 Feb 2026 23:02:22 +0000 Subject: [PATCH 1/7] TDD: wrote count.test.js with scenarios before implementating countChar --- Sprint-3/2-practice-tdd/count.test.js | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf..f0ba0e1b5 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,62 @@ test("should count multiple occurrences of a character", () => { // And a character `char` that does not exist within `str`. // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of `char` were found. +test("should return 0 when character does not appear in string", () => { + expect(countChar("hello", "x")).toEqual(0); + expect(countChar("banana", "z")).toEqual(0); + // empty string + expect(countChar("", "a")).toEqual(0); +}); + +// Scenario: Single Occurence +// Given a string where `char` appears exactly once, +// When countChar is called, +// Then it should return 1. +test("should return 1 when character appears exactly once", () => { + expect(countChar("hello", "h")).toEqual(1); + expect(countChar("banana", "n")).toEqual(1); + expect(countChar("xyz", "y")).toEqual(1); +}); + +// Scenario: Case Sensitivity +// Given a string with mixed case letters, +// When countChar is called with a specific case, +// Then it should count only exact matches (case-sensitive). +test("should be case-sensitive when counting characters", () => { + expect(countChar("Hello", "H")).toEqual(1); + expect(countChar("Hello", "h")).toEqual(0); + expect(countChar("AAAaaa", "A")).toEqual(3); + expect(countChar("AAAaaa", "a")).toEqual(3); +}); + +// Scenario: Special Characters/Symbols +// Given a string containing punctuation or emojis, +// When counting a special character, +// Then it should correctly identify and count it. +test("should count special characters and emojis", () => { + expect(countChar("hello!!!", "!")).toEqual(3); + expect(countChar("smile 😊😊😊", "😊")).toEqual(3); +}); + +// Scenario: Longer Mixed String +// Given a longer string with various characters and spaces, +// When counting different characters, +// Then it should return the correct count for each. +test("should count correctly in longer mixed string", () => { + const str = "i am writing some jest tests right now"; + // some, now + expect(countChar(str, "o")).toEqual(2); + // some, jest, tests + expect(countChar(str, "e")).toEqual(3); + // spaces + expect(countChar(str, " ")).toEqual(7); +}); + +// Scenario: Single Character String +// Given a string containing only one character, +// When countChar is called, +// Then it should correctly handle matching or non-matching cases. +test("should handle single character strings", () => { + expect(countChar("a", "a")).toEqual(1); + expect(countChar("b", "a")).toEqual(0); +}); From fae571e4487c7f5f7456423bccc78411d49111c6 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Fri, 20 Feb 2026 23:48:21 +0000 Subject: [PATCH 2/7] TDD: Completed get-ordinal-number.test.js with 5 grouped test cases --- .../2-practice-tdd/get-ordinal-number.test.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) 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..a105bdc61 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,47 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + +// Case 2: Numbers ending with 2 (except 12) +// Given the number ends with 2 but not 12, +// When getOrdinalNumber is called, +// Then it should append "nd". +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("102nd"); +}); + +// Case 3: Numbers ending with 3 (except 13) +// Given the number ends with 3 but not 13, +// When getOrdinalNumber is called, +// Then it should append "rd". +test("should append 'rd' for numbers ending with 3 except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(103)).toEqual("103rd"); +}); + +// Case 4: Numbers ending with 4-9, 0, or 11-19 +// Given the number ends with 4-9, 0, ot 11-19, +// When getOrdinalNumber is called, +// Then it should append "th". +test("should append 'th' for numbers ending with 4-9, 0, or 11-19", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(5)).toEqual("5th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(20)).toEqual("20th"); +}); + +// Case 5: Large numbers +// Give a very large positive number, +// When getOrdinalNumber is called, +// Then it should still append the correct suffix based on the last digits. +test("should handle large numbers correctly", () => { + expect(getOrdinalNumber(101)).toEqual("101st"); + expect(getOrdinalNumber(112)).toEqual("112th"); + expect(getOrdinalNumber(1000)).toEqual("1000th"); +}); From 29320b5d07056771c4a2000c2f93372995b10b48 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sat, 21 Feb 2026 00:16:50 +0000 Subject: [PATCH 3/7] TDD: Completed repeat-str.test.js with jest test cases --- Sprint-3/2-practice-tdd/repeat-str.test.js | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c..0ed7403c9 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -20,13 +20,37 @@ test("should repeat the string count times", () => { // 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. +test("should return the original string when count is 1", () => { + expect(repeatStr("hello", 1)).toEqual("hello"); + expect(repeatStr("a", 1)).toEqual("a"); + expect(repeatStr("", 1)).toEqual(""); +}); // Case: Handle count of 0: // 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. +test("should return empty string when count is 0", () => { + expect(repeatStr("hello", 0)).toEqual(""); + expect(repeatStr("anything", 0)).toEqual(""); + expect(repeatStr("", 0)).toEqual(""); +}); // Case: Handle negative count: // 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. +test("should throw error when count is negative", () => { + expect(() => repeatStr("hello", -1)).toThrow(); + expect(() => repeatStr("test", -5)).toThrow(); + expect(() => repeatStr("", -3)).toThrow(); +}); + +// Case: Handle positive count: +// Given an empty string `str`and a positive integer `count`, +// When the repeatStr function is called, +// Then it should return an empty string +test("should return empty string when input string is empty", () => { + expect(repeatStr("", 5)).toEqual(""); + expect(repeatStr("", 1)).toEqual(""); +}); From 3266bbca902d44024d0ba3fe0bd08c08455af213 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sat, 21 Feb 2026 00:32:07 +0000 Subject: [PATCH 4/7] TDD: Fixed single occurence test sample in count.test.js (changed banana to test) --- Sprint-3/2-practice-tdd/count.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index f0ba0e1b5..3e43a62ca 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -35,7 +35,7 @@ test("should return 0 when character does not appear in string", () => { // Then it should return 1. test("should return 1 when character appears exactly once", () => { expect(countChar("hello", "h")).toEqual(1); - expect(countChar("banana", "n")).toEqual(1); + expect(countChar("test", "e")).toEqual(1); expect(countChar("xyz", "y")).toEqual(1); }); From a4eb4d349505dd1b8373e2c3218b56e66e2a2527 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sat, 21 Feb 2026 00:38:02 +0000 Subject: [PATCH 5/7] Completed countChar implementation - passes all 7 Jest test cases --- Sprint-3/2-practice-tdd/count.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..2c2142f32 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,11 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + for (const character of stringOfCharacters) { + if(character === findCharacter) { + count++; + } + } + return count; } module.exports = countChar; From 0b8375e415077d1ff782e6c5031fa25d210cd1c9 Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sat, 21 Feb 2026 01:22:48 +0000 Subject: [PATCH 6/7] Completed getOrdinalNumber implementation - passes all 5 Jest test cases --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 20 ++++++++++++++++++- 1 file changed, 19 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 f95d71db1..f3402518f 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,23 @@ function getOrdinalNumber(num) { - return "1st"; + // Last digit determines st/nd/rd for most numbers + const lastDigit = num % 10; + // Last two digits needed to handle special, + // teen cases (11th, 12th, 13th) + const lastTwo = num % 100; + + // Special rule: numbers ending in 11, 12 or 13 always use "th" + if (lastTwo === 11 || lastTwo === 12 || lastTwo === 13) { + return num + "th"; + } + + // Ending in 1 → "st" + if (lastDigit === 1) return num + "st"; + // Ending in 2 → "nd" + if (lastDigit === 2) return num + "nd"; + // Ending in 3 → "rd" + if (lastDigit === 3) return num + "rd"; + // All other endings (0, 4-9 and anything after teen check) → "th" + return num + "th"; } module.exports = getOrdinalNumber; From 3876e7f958086a89a5634d1d16abcf87e14ab99d Mon Sep 17 00:00:00 2001 From: Eugenie Ahangama Date: Sat, 21 Feb 2026 01:41:17 +0000 Subject: [PATCH 7/7] Completed repeatStr implementation - passes all 5 Jest test cases --- Sprint-3/2-practice-tdd/repeat-str.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b00..3f8200722 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,26 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(str, count) { + // Reject negative counts - not valid for repetition + if (count < 0) { + throw new Error("Count cannot be negative"); + } + + // If count is 0, return empty string immediately + if (count === 0) { + return ""; + } + + // For count = 1, just return the original string + if (count === 1) { + return str; + } + + // For count > 1: build the repeated string using a loop + let result = ""; + for (let i = 0; i < count; i++) { + result += str; + } + + return result; } module.exports = repeatStr;