From e3465734b0a5309a2c0718712a85896870133430 Mon Sep 17 00:00:00 2001 From: KK Tech Date: Fri, 13 Mar 2026 12:45:23 +0000 Subject: [PATCH 1/5] Completed Practice-tdd tasks --- Sprint-3/2-practice-tdd/count.js | 10 +++++++++- Sprint-3/2-practice-tdd/count.test.js | 18 ++++++++++++++++++ Sprint-3/2-practice-tdd/get-ordinal-number.js | 18 +++++++++++++++++- .../2-practice-tdd/get-ordinal-number.test.js | 1 + Sprint-3/2-practice-tdd/repeat-str.js | 2 ++ Sprint-3/2-practice-tdd/repeat-str.test.js | 2 ++ 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..79977793e5 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,13 @@ 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; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..0b0f9845df 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,21 @@ 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 the character does not occur in the string", () => { + const str = "hello world"; + const char = "x"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + +// Scenario: Case Sensitivity +// Given the input string `str`, +// And a character `char` that occurs in `str` but with different cases (e.g., 'a' and 'A'), +// When the function is called with these inputs, +// Then it should count only the occurrences of `char` that match the case provided in the input. +test("should count only occurrences of the character that match the case", () => { + const str = "AaAaA"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(2); +}); diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..23cfa2773f 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"; + const lastDigit = num % 10; + const lastTwoDigits = num % 100; + + if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { + return `${num}th`; + } + + switch (lastDigit) { + case 1: + return `${num}st`; + case 2: + return `${num}nd`; + case 3: + return `${num}rd`; + default: + return `${num}th`; + } } module.exports = getOrdinalNumber; 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 adfa58560f..2cb0a481df 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,4 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b003..027a466f7a 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -3,3 +3,5 @@ function repeatStr() { } 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 a3fc1196c4..5f27003be0 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -30,3 +30,5 @@ test("should repeat the string count times", () => { // 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. + + From cb22d60b21420884d1fefc811c9f653225767535 Mon Sep 17 00:00:00 2001 From: KK Tech Date: Fri, 13 Mar 2026 13:07:35 +0000 Subject: [PATCH 2/5] fixxed task error --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 23cfa2773f..d3fd07c153 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -19,3 +19,4 @@ function getOrdinalNumber(num) { } module.exports = getOrdinalNumber; + From a5cdf9202cf35f4782b64802fd68d63d77f75a54 Mon Sep 17 00:00:00 2001 From: KK Tech Date: Sat, 14 Mar 2026 12:12:20 +0000 Subject: [PATCH 3/5] Improved Practice tdd tasks following the feedback instructions --- .../2-practice-tdd/get-ordinal-number.test.js | 29 +++++++++++-- Sprint-3/2-practice-tdd/repeat-str.js | 6 +-- Sprint-3/2-practice-tdd/repeat-str.test.js | 43 ++++++++++++++++++- 3 files changed, 69 insertions(+), 9 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 2cb0a481df..472d7099fe 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -8,14 +8,37 @@ const getOrdinalNumber = require("./get-ordinal-number"); // Listing individual values, however, can quickly lead to an unmanageable number of test cases. // Instead of writing tests for individual numbers, consider grouping all possible input values // into meaningful categories. Then, select representative samples from each category to test. -// This approach improves coverage and makes our tests easier to maintain. +// This approach improves coverage and makes our tests easier to maintain // 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 (except 12) +test(" should append 'rd' for numberss ending witth 3 except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); +}); + +// Case 3: numbers ending with 3 (except 13) +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); +}); + +// Case 4: numbers ending with th +test("should append 'th' for numbers ending with 4-9 or 0", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(10)).toEqual("10th"); +}); + +// Case 5: special cases 11,12,13 +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"); +}); + diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 027a466f7a..7850fb691a 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,7 +1,5 @@ -function repeatStr() { - return "hellohellohello"; +function repeatStr(str, count) { + return str.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 5f27003be0..84bdd2e803 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -1,5 +1,46 @@ // Implement a function repeatStr const repeatStr = require("./repeat-str"); + +// Given a target string `str` and a positive integer `count`, +// When the repeatStr function is called with these inputs, +// Then it should: + +// Case: handle multiple repetitions: +// Given a target string `str` and a positive integer `count` greater than 1, +// When the repeatStr function is called with these inputs, +// Then it should return a string that contains the original `str` repeated `count` times. +test("should repeat the string count times", () => { + const str = "hello"; + const count = 3; + const repeatedStr = repeatStr(str, count); + + expect(repeatedStr).toEqual("hellohellohello"); +}); + +// Case: handle count of 1: +// 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", () => { + const str = "hello"; + const count = 1; + const repeatedStr = repeatStr(str, count); + + expect(repeatedStr).toEqual("hello"); +}); + +// 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 an empty string when count is 0", () => { + const str = "hello"; + const count = 0; + const repeatedStr = repeatStr(str, count); + + expect(repeatedStr).toEqual(""); +}); // Implement a function repeatStr + // Given a target string `str` and a positive integer `count`, // When the repeatStr function is called with these inputs, // Then it should: @@ -30,5 +71,3 @@ test("should repeat the string count times", () => { // 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. - - From 99e55d0e9171bf397117b999a1ca3faa0fcee7cc Mon Sep 17 00:00:00 2001 From: KK Tech Date: Sat, 14 Mar 2026 12:30:11 +0000 Subject: [PATCH 4/5] fixed a error --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 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 472d7099fe..95055c3b09 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -23,19 +23,13 @@ test(" should append 'rd' for numberss ending witth 3 except those ending with 1 expect(getOrdinalNumber(23)).toEqual("23rd"); }); -// Case 3: numbers ending with 3 (except 13) -test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { - expect(getOrdinalNumber(3)).toEqual("3rd"); - expect(getOrdinalNumber(23)).toEqual("23rd"); -}); - -// Case 4: numbers ending with th +// Case 3 numbers ending with th test("should append 'th' for numbers ending with 4-9 or 0", () => { expect(getOrdinalNumber(4)).toEqual("4th"); expect(getOrdinalNumber(10)).toEqual("10th"); }); -// Case 5: special cases 11,12,13 +// Case 4: special cases 11,12,13 test("should append 'th' for numbers ending with 11, 12, 13", () => { expect(getOrdinalNumber(11)).toEqual("11th"); expect(getOrdinalNumber(12)).toEqual("12th"); From ad430613c9c4057db68f63bf225e3d195ef2bdc2 Mon Sep 17 00:00:00 2001 From: KK Tech Date: Sat, 14 Mar 2026 13:36:27 +0000 Subject: [PATCH 5/5] fixed a little mistake --- .../2-practice-tdd/get-ordinal-number.test.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 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 95055c3b09..98d6bb7a13 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -10,7 +10,7 @@ const getOrdinalNumber = require("./get-ordinal-number"); // into meaningful categories. Then, select representative samples from each category to test. // This approach improves coverage and makes our tests easier to maintain -// Case 1: Numbers ending with 1 (but not 11) +// Case 1: numbers ending with 1 (but not 11) test("should append 'st' for numbers ending with 1, except those ending with 11", () => { expect(getOrdinalNumber(1)).toEqual("1st"); expect(getOrdinalNumber(21)).toEqual("21st"); @@ -18,21 +18,26 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" }); // Case 2: numbers ending with 2 (except 12) -test(" should append 'rd' for numberss ending witth 3 except those ending with 13", () => { +test("should append 'nd' for numbers ending with 2 except those ending with 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); +}); + +// Case 3: numbers ending with 3 (except 13) +test("should append 'rd' for numbers ending with 3 except those ending with 13", () => { expect(getOrdinalNumber(3)).toEqual("3rd"); expect(getOrdinalNumber(23)).toEqual("23rd"); }); -// Case 3 numbers ending with th +// Case 4: numbers ending with th test("should append 'th' for numbers ending with 4-9 or 0", () => { expect(getOrdinalNumber(4)).toEqual("4th"); expect(getOrdinalNumber(10)).toEqual("10th"); }); -// Case 4: special cases 11,12,13 +// Case 5: special cases 11, 12, 13 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"); -}); - +}); \ No newline at end of file