From 7b93eed96f308189bf986718fd544bd404b32dd5 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 16 Oct 2025 09:34:20 +0100 Subject: [PATCH 01/24] Add test case for character not found in string --- Sprint-3/2-practice-tdd/count.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 42baf4b4b..29ee53239 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,9 @@ 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("should return 0 if the character doesn't appear in the string",()=>{ + const str ="aaaaa"; + const char = "s"; + const count = countChar(str, char); + expect(count).toEqual(0); +}) \ No newline at end of file From 86a4f934f7717171fcabe7b1d647c8729ff03018 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 16 Oct 2025 09:34:38 +0100 Subject: [PATCH 02/24] Implement character counting logic in countChar function --- 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..e25f3725f 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 char=0; + for(let i=0;i Date: Thu, 16 Oct 2025 12:49:33 +0100 Subject: [PATCH 03/24] Added tests for repeat function handling various counts --- Sprint-3/2-practice-tdd/repeat.test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat.test.js b/Sprint-3/2-practice-tdd/repeat.test.js index 34097b09c..f136cb49d 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -21,12 +21,33 @@ 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 not repeat the string", ()=>{ +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", ()=>{ + 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 return error", ()=>{ + const str="hello"; + const count=-1; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("Error: negative numbers are not valid"); +}) From a59de403378b87913f4a66b33e863ee202071823 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 16 Oct 2025 12:50:01 +0100 Subject: [PATCH 04/24] Implement repeat function to handle string repetition with error handling for negative counts --- Sprint-3/2-practice-tdd/repeat.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index 00e60d7f3..f8f1451e0 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,5 +1,11 @@ -function repeat() { - return "hellohellohello"; +function repeat(str,count) { + if(count<0){ + return "Error: negative numbers are not valid"; + } + return (str.repeat(count)); } module.exports = repeat; + + + From 9af1dec2944ce6c7b49e701105a68e87c9adba69 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 16 Oct 2025 15:56:47 +0100 Subject: [PATCH 05/24] added tests for additional getordinalnumber function --- .../2-practice-tdd/get-ordinal-number.test.js | 25 +++++++++++++++++++ 1 file changed, 25 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..6bad65a46 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,28 @@ const getOrdinalNumber = require("./get-ordinal-number"); test("should return '1st' for 1", () => { expect(getOrdinalNumber(1)).toEqual("1st"); }); + +test("should return '121st' for 121", () =>{ + expect(getOrdinalNumber(121)).toEqual("121st") +}) + +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 '5th' for 5", () => { + expect(getOrdinalNumber(5)).toEqual("5th"); +}); + +test("should return '11th' for 11", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); +}); + +test("should return NaN for s", () => { + expect(getOrdinalNumber("8")).toEqual(NaN); +}); \ No newline at end of file From de7beb8567fb0eda35d58198069809aab1c1514a Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 16 Oct 2025 15:58:06 +0100 Subject: [PATCH 06/24] added code to the getordinalfunction to cover all possibilities --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 23 ++++++++++++++++++- 1 file changed, 22 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..9aa720082 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,26 @@ function getOrdinalNumber(num) { - return "1st"; + const lastDigit=Number(num.toString().slice(-1)); + const lastTwoDigits=Number(num.toString().slice(-2)); + + if(typeof num !=="number"){ + return NaN; + } + + if(lastTwoDigits>=10 && lastTwoDigits<=13){ + return `${num}th`; + } + + if (lastDigit === 1) { + return `${num}st`; + } else if (lastDigit === 2) { + return `${num}nd`; + } else if (num === 3) { + return "3rd"; + } + + return `${num}th`; + } module.exports = getOrdinalNumber; + From dd1f125a4a4b872c913f9680b2f205e453d0a2c2 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Thu, 16 Oct 2025 15:59:40 +0100 Subject: [PATCH 07/24] added test to check for negative numbers --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 4 ++++ 1 file changed, 4 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 6bad65a46..d453c9c22 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -33,6 +33,10 @@ test("should return '11th' for 11", () => { expect(getOrdinalNumber(11)).toEqual("11th"); }); +test("should return '-11th' for -11", () => { + expect(getOrdinalNumber(-11)).toEqual("-11th"); +}); + test("should return NaN for s", () => { expect(getOrdinalNumber("8")).toEqual(NaN); }); \ No newline at end of file From a2ae864f00516fe354ed30684c2676d682a5c32d Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Fri, 24 Oct 2025 11:10:26 +0100 Subject: [PATCH 08/24] refactor countChar function for improved readability --- Sprint-3/2-practice-tdd/count.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index e25f3725f..9640831dc 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,7 +1,7 @@ function countChar(stringOfCharacters, findCharacter) { - let char=0; - for(let i=0;i Date: Sun, 26 Oct 2025 17:23:07 +0000 Subject: [PATCH 09/24] fix countChar function to handle empty character cases and improve iteration logic --- Sprint-3/2-practice-tdd/count.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 9640831dc..aa42d874d 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,7 +1,10 @@ function countChar(stringOfCharacters, findCharacter) { let char = 0; - for(let i = 0;i < stringOfCharacters.length;i++){ - if(stringOfCharacters[i] === findCharacter){ + for(let i = 0;i <= stringOfCharacters.length - findCharacter.length;i++){ + if ( findCharacter.length === 0 || stringOfCharacters === 0){ + return 0; + } + if(stringOfCharacters.substring(i, i + findCharacter.length ) === findCharacter){ char++; } } @@ -9,3 +12,4 @@ function countChar(stringOfCharacters, findCharacter) { } module.exports = countChar; +console.log(countChar("aaaaa","a")); From 7f9d151acbf941c9ce791dab1640cfb99348e1d1 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 26 Oct 2025 17:23:22 +0000 Subject: [PATCH 10/24] add additional tests for countChar function to handle empty character cases and various scenarios --- Sprint-3/2-practice-tdd/count.test.js | 41 +++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 29ee53239..3c0482df3 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,9 +22,44 @@ 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("should return 0 if the character doesn't appear in the string",()=>{ - const str ="aaaaa"; +test("should return 0 if the character doesn't appear in the string", () => { + const str = "aaaaa"; const char = "s"; const count = countChar(str, char); expect(count).toEqual(0); -}) \ No newline at end of file +}); + +test("should return 0 if the character is empty", () => { + const str = "aaaaa"; + const char = ""; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + +test("should return 0 if the character doesn't appear in the string", () => { + const str = "aaca"; + const char = "ab"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + +test("should return 0 if the character doesn't appear in the string", () => { + const str = ""; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + +test("should return 0 if the character doesn't appear in the string", () => { + const str = "aaca"; + const char = "ac"; + const count = countChar(str, char); + expect(count).toEqual(1); +}); + +test("should return 0 if the character doesn't appear in the string", () => { + const str = "a"; + const char = "aa"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); From 253d984dcfc00dfd494210559caaa87bae8414f9 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 26 Oct 2025 17:57:19 +0000 Subject: [PATCH 11/24] fix getOrdinalNumber function to handle invalid inputs and improve logic for ordinal suffixes --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 9aa720082..c607be85b 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,10 +1,11 @@ function getOrdinalNumber(num) { + if (typeof num !== "number" ||!Number.isInteger(num) || num === 0 ) { + return NaN; + } + const lastDigit=Number(num.toString().slice(-1)); const lastTwoDigits=Number(num.toString().slice(-2)); - if(typeof num !=="number"){ - return NaN; - } if(lastTwoDigits>=10 && lastTwoDigits<=13){ return `${num}th`; @@ -14,13 +15,13 @@ function getOrdinalNumber(num) { return `${num}st`; } else if (lastDigit === 2) { return `${num}nd`; - } else if (num === 3) { - return "3rd"; + } else if (lastDigit === 3) { + return `${num}rd`; } return `${num}th`; } - +console.log(getOrdinalNumber(-1)) module.exports = getOrdinalNumber; From 0f7f65695feaef2228332c3520f3520ce3514369 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 26 Oct 2025 17:57:29 +0000 Subject: [PATCH 12/24] add tests for getOrdinalNumber function to handle NaN cases and additional valid inputs --- .../2-practice-tdd/get-ordinal-number.test.js | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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 d453c9c22..e18b975b4 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -8,6 +8,14 @@ const getOrdinalNumber = require("./get-ordinal-number"); // When the number is 1, // Then the function should return "1st" +test("should return NaN for 1.5", () => { + expect(getOrdinalNumber(1.5)).toEqual(NaN); +}); + +test("should return NaN for 0", () => { + expect(getOrdinalNumber(0)).toEqual(NaN); +}); + test("should return '1st' for 1", () => { expect(getOrdinalNumber(1)).toEqual("1st"); }); @@ -25,10 +33,18 @@ test("should return '3rd' for 3", () => { expect(getOrdinalNumber(3)).toEqual("3rd"); }); +test("should return '33rd' for 33", () => { + expect(getOrdinalNumber(33)).toEqual("33rd"); +}); + test("should return '5th' for 5", () => { expect(getOrdinalNumber(5)).toEqual("5th"); }); +test("should return '1114th' for 1114", () => { + expect(getOrdinalNumber(1114)).toEqual("1114th"); +}); + test("should return '11th' for 11", () => { expect(getOrdinalNumber(11)).toEqual("11th"); }); @@ -37,6 +53,18 @@ test("should return '-11th' for -11", () => { expect(getOrdinalNumber(-11)).toEqual("-11th"); }); +test("should return '112th' for 112", () => { + expect(getOrdinalNumber(112)).toEqual("112th"); +}); + +test("should return '11113th' for 11113", () => { + expect(getOrdinalNumber(11113)).toEqual("11113th"); +}); + test("should return NaN for s", () => { - expect(getOrdinalNumber("8")).toEqual(NaN); + expect(getOrdinalNumber("s")).toEqual(NaN); +}); + +test("should return NaN for '9'", () => { + expect(getOrdinalNumber("9")).toEqual(NaN); }); \ No newline at end of file From ade9346996e306423fa2351cfe6a437b7d2ace67 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 26 Oct 2025 19:52:30 +0000 Subject: [PATCH 13/24] refactor repeat function for improved formatting and readability --- Sprint-3/2-practice-tdd/repeat.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index f8f1451e0..7d6565aec 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,4 +1,5 @@ function repeat(str,count) { + if(count<0){ return "Error: negative numbers are not valid"; } @@ -7,5 +8,3 @@ function repeat(str,count) { module.exports = repeat; - - From a1e9f6058c6e8261c435443620219b0d877c5389 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 26 Oct 2025 19:52:40 +0000 Subject: [PATCH 14/24] add tests for repeat function to handle empty strings, strings with spaces, and long strings --- Sprint-3/2-practice-tdd/repeat.test.js | 60 +++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat.test.js b/Sprint-3/2-practice-tdd/repeat.test.js index f136cb49d..b0c9c7a42 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -33,12 +33,12 @@ expect(repeatedStr).toEqual("hello") // 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", ()=>{ - const str = "hello"; - const count = 0; - const repeatedStr = repeat(str, count); - expect(repeatedStr).toEqual(""); -}) +// test("should return an empty string", ()=>{ +// 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, @@ -51,3 +51,51 @@ test("should return error", ()=>{ const repeatedStr = repeat(str, count); expect(repeatedStr).toEqual("Error: negative numbers are not valid"); }) + +// case: Handle empty string: +// Given a target string str and a count equal to 2, +// When the repeat function is called with these inputs, +// Then it should return an empty string, ensuring that a count of 2 results in an empty output. + +test("should return an empty string", () => { + const str = ""; + const count = 2; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual(""); +}); + +// case: Handle string with space: +// Given a target string str and a count equal to 2, +// When the repeat function is called with these inputs, +// Then it should repeat the str count times and return a new string containing the repeated str values. + +test("should return an empty string", () => { + const str = "a b"; + const count = 2; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("a ba b"); +}); + +// case: Handle long string : +// Given a target string str and a count equal to1, +// When the repeat function is called with these inputs, +// Then it should repeat the str count times and return a new string containing the repeated str values. + +test("should return an empty string", () => { + const str = "xvg56756yrhfghe5ujdfh45657tjrtg6yrthrty"; + const count = 1; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("xvg56756yrhfghe5ujdfh45657tjrtg6yrthrty"); +}); + +// case: Handle single character string and high count : +// Given a target string str and a count equal to 18, +// When the repeat function is called with these inputs, +// Then it should repeat the str count times and return a new string containing the repeated str values. + +test("should return an empty string", () => { + const str = "x"; + const count = 18; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("xxxxxxxxxxxxxxxxxx"); +}); \ No newline at end of file From 5d5d0950c850752906e1cc2070f9d9882c3386f7 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 26 Oct 2025 19:53:21 +0000 Subject: [PATCH 15/24] removed scratch work --- Sprint-3/2-practice-tdd/count.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index aa42d874d..5fcb8efa2 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -12,4 +12,4 @@ function countChar(stringOfCharacters, findCharacter) { } module.exports = countChar; -console.log(countChar("aaaaa","a")); + From 6c0be541b462f8cc9e610e65329dc106742e8e5b Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 26 Oct 2025 20:01:39 +0000 Subject: [PATCH 16/24] updated the function to handle empty strings --- Sprint-3/2-practice-tdd/count.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 5fcb8efa2..77b77705b 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,8 @@ function countChar(stringOfCharacters, findCharacter) { let char = 0; + if (stringOfCharacters === 0){ + return 0 + } for(let i = 0;i <= stringOfCharacters.length - findCharacter.length;i++){ if ( findCharacter.length === 0 || stringOfCharacters === 0){ return 0; From 1a644586ddf19fbf87fe681227fc3ad8516473d3 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 26 Oct 2025 20:04:22 +0000 Subject: [PATCH 17/24] updated test case description --- 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 3c0482df3..0693e0545 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -50,7 +50,7 @@ test("should return 0 if the character doesn't appear in the string", () => { expect(count).toEqual(0); }); -test("should return 0 if the character doesn't appear in the string", () => { +test("should return 1 when substring appears once in the string", () => { const str = "aaca"; const char = "ac"; const count = countChar(str, char); From eee22d926dd1014023d50e68172211493708a34a Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 26 Oct 2025 20:18:33 +0000 Subject: [PATCH 18/24] update test descriptions for clarity on invalid inputs --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 e18b975b4..90cdfeeb0 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -8,12 +8,12 @@ const getOrdinalNumber = require("./get-ordinal-number"); // When the number is 1, // Then the function should return "1st" -test("should return NaN for 1.5", () => { - expect(getOrdinalNumber(1.5)).toEqual(NaN); -}); +test("should return 'not an integer number' for 1.5", () => { + expect(getOrdinalNumber(1.5)).toEqual("not an integer number"); +}); -test("should return NaN for 0", () => { - expect(getOrdinalNumber(0)).toEqual(NaN); +test("should return 'invalid number' for 0", () => { + expect(getOrdinalNumber(0)).toEqual("invalid number"); }); test("should return '1st' for 1", () => { From a4b2b74bd225b24f73c7901071beb50e7cf9faa6 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Sun, 26 Oct 2025 20:18:43 +0000 Subject: [PATCH 19/24] refactor getOrdinalNumber function to improve input validation structure --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index c607be85b..0bc41eb86 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,13 +1,18 @@ function getOrdinalNumber(num) { - if (typeof num !== "number" ||!Number.isInteger(num) || num === 0 ) { + if (typeof num !== "number") { return NaN; } - - const lastDigit=Number(num.toString().slice(-1)); - const lastTwoDigits=Number(num.toString().slice(-2)); + if(!Number.isInteger(num)){ + return "not an integer number"; + } + if(num === 0 ){ + return "invalid number"; + } + const lastDigit = Number(num.toString().slice(-1)); + const lastTwoDigits = Number(num.toString().slice(-2)); - if(lastTwoDigits>=10 && lastTwoDigits<=13){ + if (lastTwoDigits >= 10 && lastTwoDigits <= 13) { return `${num}th`; } @@ -18,10 +23,8 @@ function getOrdinalNumber(num) { } else if (lastDigit === 3) { return `${num}rd`; } - - return `${num}th`; + return `${num}th`; } -console.log(getOrdinalNumber(-1)) -module.exports = getOrdinalNumber; +module.exports = getOrdinalNumber; From 90a7852ab78c58d062dd2dd3e972bb83d332d482 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 08:17:01 +0000 Subject: [PATCH 20/24] fix formatting in getOrdinalNumber function for consistency --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 4 ++-- 1 file changed, 2 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 0bc41eb86..0982be772 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -2,10 +2,10 @@ function getOrdinalNumber(num) { if (typeof num !== "number") { return NaN; } - if(!Number.isInteger(num)){ + if (!Number.isInteger(num)) { return "not an integer number"; } - if(num === 0 ){ + if (num === 0) { return "invalid number"; } From 719883977df70425068f8ff855167c80c425b7e8 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 11:02:39 +0000 Subject: [PATCH 21/24] update tests for repeat function to handle undefined count and improve error messages --- Sprint-3/2-practice-tdd/repeat.test.js | 36 +++++++++++++++++--------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat.test.js b/Sprint-3/2-practice-tdd/repeat.test.js index b0c9c7a42..15a638af7 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -33,23 +33,35 @@ expect(repeatedStr).toEqual("hello") // 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", ()=>{ -// const str = "hello"; -// const count = 0; -// const repeatedStr = repeat(str, count); -// expect(repeatedStr).toEqual(""); -// }) +test("should return an empty string", ()=>{ + const str = "hello"; + const count = 0; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual(""); +}) + +// case: Handle Count of Undefined: +// Given a target string str and a count equal to Undefined, +// When the repeat function is called with these inputs, +// Then it should return an error message. + +test("should return an error message", ()=>{ + const str = "hello"; + const count = undefined; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("Error : count must be a positive integer"); +}) // 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 return error", ()=>{ +test("should return an error message", ()=>{ const str="hello"; const count=-1; const repeatedStr = repeat(str, count); - expect(repeatedStr).toEqual("Error: negative numbers are not valid"); + expect(repeatedStr).toEqual("Error : count must be a positive integer"); }) // case: Handle empty string: @@ -69,7 +81,7 @@ test("should return an empty string", () => { // When the repeat function is called with these inputs, // Then it should repeat the str count times and return a new string containing the repeated str values. -test("should return an empty string", () => { +test("should repeat the string count times", () => { const str = "a b"; const count = 2; const repeatedStr = repeat(str, count); @@ -77,11 +89,11 @@ test("should return an empty string", () => { }); // case: Handle long string : -// Given a target string str and a count equal to1, +// Given a target string str and a count equal to 1, // When the repeat function is called with these inputs, // Then it should repeat the str count times and return a new string containing the repeated str values. -test("should return an empty string", () => { +test("should not repeat the string", () => { const str = "xvg56756yrhfghe5ujdfh45657tjrtg6yrthrty"; const count = 1; const repeatedStr = repeat(str, count); @@ -93,7 +105,7 @@ test("should return an empty string", () => { // When the repeat function is called with these inputs, // Then it should repeat the str count times and return a new string containing the repeated str values. -test("should return an empty string", () => { +test("should repeat str 18 times", () => { const str = "x"; const count = 18; const repeatedStr = repeat(str, count); From b91f9500c26f0feffa43e9c8cdc20cd51f42f954 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 11:02:50 +0000 Subject: [PATCH 22/24] refactor repeat function to improve input validation and error handling --- Sprint-3/2-practice-tdd/repeat.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index 7d6565aec..442ca50af 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,10 +1,11 @@ -function repeat(str,count) { - - if(count<0){ - return "Error: negative numbers are not valid"; +function repeat(str, count) { + if (count < 0 || count === undefined || typeof count !== "number") { + return "Error : count must be a positive integer"; } - return (str.repeat(count)); + if (count === 0) { + return ""; + } + return str.repeat(count); } module.exports = repeat; - From 9c86871ef83dc4309552fbfb81013c118e7cb560 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 12:27:21 +0000 Subject: [PATCH 23/24] refactor repeat function to enhance input validation for string type --- Sprint-3/2-practice-tdd/repeat.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index 442ca50af..1f68fd727 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,4 +1,7 @@ function repeat(str, count) { + if (typeof str !== "string") { + return "Error: str must be a string"; + } if (count < 0 || count === undefined || typeof count !== "number") { return "Error : count must be a positive integer"; } From e28e1992af02fec71eb55d495b83f98c85f6c963 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 27 Oct 2025 12:27:29 +0000 Subject: [PATCH 24/24] update tests for repeat function to handle non-string input and array count --- Sprint-3/2-practice-tdd/repeat.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat.test.js b/Sprint-3/2-practice-tdd/repeat.test.js index 15a638af7..2f966e10e 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -40,6 +40,18 @@ test("should return an empty string", ()=>{ expect(repeatedStr).toEqual(""); }) +// case: Handle str not a string: +// Given a number and a count equal to 2, +// When the repeat function is called with these inputs, +// Then it should return an error message. + +test("should return an error message", ()=>{ + const str = 5; + const count = 5; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("Error: str must be a string"); +}) + // case: Handle Count of Undefined: // Given a target string str and a count equal to Undefined, // When the repeat function is called with these inputs, @@ -52,6 +64,18 @@ test("should return an error message", ()=>{ expect(repeatedStr).toEqual("Error : count must be a positive integer"); }) +// case: Handle Count of array: +// Given a target string str and a count equal to [], +// When the repeat function is called with these inputs, +// Then it should return an error message. + +test("should return an error message", ()=>{ + const str = "hello"; + const count = []; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("Error : count must be a positive integer"); +}) + // case: Negative Count: // Given a target string str and a negative integer count, // When the repeat function is called with these inputs,