From 31f50ad84d12460cd87a1ac20948e02b686390f3 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 15:54:22 +0000 Subject: [PATCH 1/7] count.js updated --- Sprint-3/2-practice-tdd/count.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..d22559ff9 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -3,3 +3,19 @@ function countChar(stringOfCharacters, findCharacter) { } module.exports = countChar; + +const countChar = require('../countChar'); + +describe('countChar()', () => { + test('always returns 5', () => { + expect(countChar('anything', 'a')).toBe(5); + }); + + test('still returns 5 with empty string', () => { + expect(countChar('', 'z')).toBe(5); + }); + + test('still returns 5 with special characters', () => { + expect(countChar('!!!', '!')).toBe(5); + }); +}); From a61f9b1abe9dea5aac3ac4507f95948c6116465a Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 16:45:34 +0000 Subject: [PATCH 2/7] updated pr template --- Sprint-3/2-practice-tdd/count.test.js | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 42baf4b4b..a94c93701 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -16,6 +16,36 @@ test("should count multiple occurrences of a character", () => { const count = countChar(str, char); expect(count).toEqual(5); }); +test("should return 0 when the character is not found", () => { + const str = "hello"; + const char = "z"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + +// Scenario: Case Sensitivity +// It should be case-sensitive, meaning 'A' != 'a'. +test("should be case-sensitive when counting characters", () => { + const str = "Banana"; + expect(countChar(str, "a")).toEqual(3); + expect(countChar(str, "A")).toEqual(0); +}); + +// Scenario: Empty String +// It should return 0 when the input string is empty. +test("should return 0 when the input string is empty", () => { + const str = ""; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + +// Scenario: Special Characters +// It should correctly count spaces and punctuation. +test("should count special characters like spaces or punctuation", () => { + expect(countChar("a b a b", " ")).toEqual(2); + expect(countChar("wow!!!", "!")).toEqual(3); +}); // Scenario: No Occurrences // Given the input string str, From 2a422f5a25e64669d2d89d65cb0402fb758df15a Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 16:47:59 +0000 Subject: [PATCH 3/7] updated PR template --- Sprint-3/2-practice-tdd/count.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index a94c93701..1bf611fc3 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -1,5 +1,16 @@ // implement a function countChar that counts the number of times a character occurs in a string const countChar = require("./count"); + +function countChar(stringOfCharacters, findCharacter) { + let count = 0; + for (let char of stringOfCharacters) { + if (char === findCharacter) count++; + } + return count; +} + +module.exports = countChar; + // Given a string str and a single character char to search for, // When the countChar function is called with these inputs, // Then it should: From 04f5a7f8ee56748a989b8717d1bbc2c55f362c3b Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 16:53:18 +0000 Subject: [PATCH 4/7] get ordinal numbers updated template --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 58 ++++++++++++++++++- 1 file changed, 57 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..318f08619 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,61 @@ + function getOrdinalNumber(num) { - return "1st"; + const remainder10 = num % 10; + const remainder100 = num % 100; + + if (remainder100 >= 11 && remainder100 <= 13) { + return `${num}th`; + } + + switch (remainder10) { + case 1: + return `${num}st`; + case 2: + return `${num}nd`; + case 3: + return `${num}rd`; + default: + return `${num}th`; + } } module.exports = getOrdinalNumber; + + +const getOrdinalNumber = require("./getOrdinalNumber"); + +describe("getOrdinalNumber()", () => { + test("should return '1st' for 1", () => { + expect(getOrdinalNumber(1)).toBe("1st"); + }); + + test("should return '2nd' for 2", () => { + expect(getOrdinalNumber(2)).toBe("2nd"); + }); + + test("should return '3rd' for 3", () => { + expect(getOrdinalNumber(3)).toBe("3rd"); + }); + + test("should return '4th' for 4", () => { + expect(getOrdinalNumber(4)).toBe("4th"); + }); + + test("should return '11th', '12th', '13th' for special cases", () => { + expect(getOrdinalNumber(11)).toBe("11th"); + expect(getOrdinalNumber(12)).toBe("12th"); + expect(getOrdinalNumber(13)).toBe("13th"); + }); + + test("should return correct suffixes for 21, 22, 23", () => { + expect(getOrdinalNumber(21)).toBe("21st"); + expect(getOrdinalNumber(22)).toBe("22nd"); + expect(getOrdinalNumber(23)).toBe("23rd"); + }); + + test("should return '111th' for numbers ending with 11, 12, 13 even if larger", () => { + expect(getOrdinalNumber(111)).toBe("111th"); + expect(getOrdinalNumber(112)).toBe("112th"); + expect(getOrdinalNumber(113)).toBe("113th"); + }); +}); From 7e9160de067f75480b16378d9e1e7294d945079b Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 17:01:07 +0000 Subject: [PATCH 5/7] ordinal numbers updated PR template --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 7 +++++++ 1 file changed, 7 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 dfe4b6091..b3d6419f7 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -1,4 +1,11 @@ const getOrdinalNumber = require("./get-ordinal-number"); + +function getOrdinalNumber(num) { + return "1st"; +} + +module.exports = getOrdinalNumber; + // In this week's prep, we started implementing getOrdinalNumber // continue testing and implementing getOrdinalNumber for additional cases From 6c17f89d394e39dc8b106af75a2a7dbbec8b92c8 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 17:05:54 +0000 Subject: [PATCH 6/7] repeat.js updated template --- Sprint-3/2-practice-tdd/repeat.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index 00e60d7f3..125840b92 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -3,3 +3,7 @@ function repeat() { } module.exports = repeat; + +test("should repeat the given word three times", () => { + expect(repeat("hi", 3)).toBe("hihihi"); +}); From 94de70c2ac1de336a9cc76864e944dbe7ce19f48 Mon Sep 17 00:00:00 2001 From: Fithi Teklom Date: Thu, 6 Nov 2025 17:10:16 +0000 Subject: [PATCH 7/7] repeat.test.js updated template --- Sprint-3/2-practice-tdd/repeat.js | 2 ++ Sprint-3/2-practice-tdd/repeat.test.js | 40 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index 125840b92..6aea34899 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,3 +1,5 @@ +const repeat = require("./repeat"); + function repeat() { return "hellohellohello"; } diff --git a/Sprint-3/2-practice-tdd/repeat.test.js b/Sprint-3/2-practice-tdd/repeat.test.js index 34097b09c..6bf18ed73 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -3,6 +3,14 @@ const repeat = require("./repeat"); // Given a target string str and a positive integer count, // When the repeat function is called with these inputs, // Then it should: +function repeat(str, count) { + if (count < 0) { + throw new Error("Count must be a non-negative integer"); + } + return str.repeat(count); +} + +module.exports = repeat; // case: repeat String: // Given a target string str and a positive integer count, @@ -30,3 +38,35 @@ test("should repeat the string count times", () => { // 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. +const repeat = require("./repeat"); + +// Case 1: Repeat string multiple times +test("should repeat the string count times", () => { + const str = "hello"; + const count = 3; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("hellohellohello"); +}); + +// Case 2: Handle count of 1 +test("should return the original string when count is 1", () => { + const str = "world"; + const count = 1; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("world"); +}); + +// Case 3: Handle count of 0 +test("should return an empty string when count is 0", () => { + const str = "test"; + const count = 0; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual(""); +}); + +// Case 4: Negative count +test("should throw an error when count is negative", () => { + const str = "oops"; + const count = -2; + expect(() => repeat(str, count)).toThrow("Count must be a non-negative integer"); +});