From 1e5cad726baaf87ac1d5b3f8d4013fef70bb4ac1 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Fri, 10 Oct 2025 17:12:00 +0100 Subject: [PATCH 01/13] count.js and count.test.js completed --- Sprint-3/2-practice-tdd/count.js | 7 ++++++- Sprint-3/2-practice-tdd/count.test.js | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..f8d2898f7 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,10 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let output = 0; + for( let i=0; i <= stringOfCharacters.length; i++ ) { + if(stringOfCharacters[i] === findCharacter) + output++; + } + return output; } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 42baf4b4b..ce08b2345 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 there are no occurrences at all", () => { + const str = "Hello World!"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); \ No newline at end of file From a42937df0c6489d1973af849bea149ae7c7854d2 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Fri, 10 Oct 2025 17:15:15 +0100 Subject: [PATCH 02/13] get-ordinal-numbers.js completed --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 4 +++- 1 file changed, 3 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..4c256b033 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,7 @@ function getOrdinalNumber(num) { - return "1st"; + if(num === 1) + return "1st"; + return 0; } module.exports = getOrdinalNumber; From 96004439640dd6afc8323766ebf634b961dca5a0 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Fri, 10 Oct 2025 17:16:08 +0100 Subject: [PATCH 03/13] repeat.js and repeat.test.js completed --- Sprint-3/2-practice-tdd/repeat.js | 7 +++++-- Sprint-3/2-practice-tdd/repeat.test.js | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index 00e60d7f3..bbd0baa93 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,5 +1,8 @@ -function repeat() { - return "hellohellohello"; +function repeat(str, count) { + if(count < 0) { + return "Error: Negative counts are not valid."; + } + return str.repeat(count); } module.exports = repeat; diff --git a/Sprint-3/2-practice-tdd/repeat.test.js b/Sprint-3/2-practice-tdd/repeat.test.js index 34097b09c..0ffd3e80e 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -20,13 +20,31 @@ test("should repeat the string count times", () => { // Given a target string str and a count equal to 1, // 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 repeat the string only 1 time (no repetition)", () => { + 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 repeat the string 0 times ( means the output will be 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 repeat the string 0 times ( means the output will be an empty string)", () => { + const str = "hello"; + const count = -3; + const repeatedStr = repeat(str, count); + expect(repeatedStr).toEqual("Error: Negative counts are not valid."); +}); \ No newline at end of file From c0d9240d1e01404ca4a6b9dd218558966a144603 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Sun, 19 Oct 2025 12:07:18 +0100 Subject: [PATCH 04/13] Updated the funciton so it handels other tests, and added more tests too --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 27 ++++++++-- .../2-practice-tdd/get-ordinal-number.test.js | 50 +++++++++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 4c256b033..6c83a305f 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,7 +1,28 @@ function getOrdinalNumber(num) { - if(num === 1) - return "1st"; - return 0; + // + if (typeof num !== "number" || !Number.isInteger(num) || num <= 0) { + return "Input must be a positive integer."; + } + + const lastTwoDigits = num % 100; + const lastDigit = num % 10; + + 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`; + } + return num; } +console.log(getOrdinalNumber(21)); // "1st" 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 dfe4b6091..17e6b085e 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -10,4 +10,54 @@ const getOrdinalNumber = require("./get-ordinal-number"); test("should return '1st' for 1", () => { expect(getOrdinalNumber(1)).toEqual("1st"); + expect(getOrdinalNumber(21)).toEqual("21st"); + expect(getOrdinalNumber(101)).toEqual("101st"); }); + +// Case 2: Identify the ordinal number for 1 +// except those ending in 12 +test("append 'nd' to numbers ending in 2, except those ending in 12", () => { + expect( getOrdinalNumber(2) ).toEqual("2nd"); + expect( getOrdinalNumber(22) ).toEqual("22nd"); + expect( getOrdinalNumber(132) ).toEqual("132nd"); +}); + +// Case 3: Identify the ordinal numbers for 3 to 12 +test("should return correct ordinal suffixes for numbers 3 to 12", () => { + expect( getOrdinalNumber(3) ).toEqual("3rd"); + expect( getOrdinalNumber(4) ).toEqual("4th"); + expect( getOrdinalNumber(5) ).toEqual("5th"); + expect( getOrdinalNumber(6) ).toEqual("6th"); + expect( getOrdinalNumber(7) ).toEqual("7th"); + expect( getOrdinalNumber(8) ).toEqual("8th"); + expect( getOrdinalNumber(9) ).toEqual("9th"); + expect( getOrdinalNumber(10) ).toEqual("10th"); + expect( getOrdinalNumber(11) ).toEqual("11th"); + expect( getOrdinalNumber(12) ).toEqual("12th"); +}); +// Case 4: Identify the ordinal numbers for numbers above 12 +test("should return correct ordinal suffixes for numbers above 12", () => { + expect( getOrdinalNumber(13) ).toEqual("13th"); + expect( getOrdinalNumber(19) ).toEqual("19th"); + expect( getOrdinalNumber(23) ).toEqual("23rd"); + expect( getOrdinalNumber(34) ).toEqual("34th"); + expect( getOrdinalNumber(45) ).toEqual("45th"); + expect( getOrdinalNumber(56) ).toEqual("56th"); + expect( getOrdinalNumber(67) ).toEqual("67th"); +}); + +// Case 5: Identify the ordinal numbers for numbers like 20 30 40 etc +test("should return correct ordinal suffixes for multiples of ten", () => { + expect( getOrdinalNumber(20) ).toEqual("20th"); + expect( getOrdinalNumber(30) ).toEqual("30th"); + expect( getOrdinalNumber(70) ).toEqual("70th"); + expect( getOrdinalNumber(50) ).toEqual("50th"); +}); + +// Case 6: dealing with big numbers +test("should return correct ordinal suffixes for big numbers", () => { + expect( getOrdinalNumber(111) ).toEqual("111th"); + expect( getOrdinalNumber(4712) ).toEqual("4712th"); + expect( getOrdinalNumber(10003) ).toEqual("10003rd"); + expect( getOrdinalNumber(10012) ).toEqual("10012th"); +}); \ No newline at end of file From f6314c3cc2bc7cadf9df15c4b0bdbe7cfc4ab771 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Sun, 19 Oct 2025 12:27:40 +0100 Subject: [PATCH 05/13] function repeat() should return false when negative number passed --- Sprint-3/2-practice-tdd/repeat.js | 2 +- Sprint-3/2-practice-tdd/repeat.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index bbd0baa93..fe4947697 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,6 +1,6 @@ function repeat(str, count) { if(count < 0) { - return "Error: Negative counts are not valid."; + return false; } return str.repeat(count); } diff --git a/Sprint-3/2-practice-tdd/repeat.test.js b/Sprint-3/2-practice-tdd/repeat.test.js index 0ffd3e80e..e8ec14812 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -46,5 +46,5 @@ test("should repeat the string 0 times ( means the output will be an empty strin const str = "hello"; const count = -3; const repeatedStr = repeat(str, count); - expect(repeatedStr).toEqual("Error: Negative counts are not valid."); + expect(repeatedStr).toEqual(false); }); \ No newline at end of file From ad2180d9276d1341a3b0fc0f2dc428aa793459a3 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Sun, 19 Oct 2025 13:25:07 +0100 Subject: [PATCH 06/13] updated function repeat() and its tests --- Sprint-3/2-practice-tdd/repeat.js | 4 ++-- Sprint-3/2-practice-tdd/repeat.test.js | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index fe4947697..bcab83738 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,6 +1,6 @@ function repeat(str, count) { - if(count < 0) { - return false; + if (typeof count !== "number" || isNaN(count) || count < 0) { + throw new Error("Count must be a valid number"); } return str.repeat(count); } diff --git a/Sprint-3/2-practice-tdd/repeat.test.js b/Sprint-3/2-practice-tdd/repeat.test.js index e8ec14812..6045f245b 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -42,9 +42,17 @@ test("should repeat the string 0 times ( means the output will be an empty strin // 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 repeat the string 0 times ( means the output will be an empty string)", () => { +test("should throw an error if count is not a valid number", () => { const str = "hello"; - const count = -3; - const repeatedStr = repeat(str, count); - expect(repeatedStr).toEqual(false); -}); \ No newline at end of file + const count = -8; + expect(() => repeat(str, count)).toThrow("Count must be a valid number"); +}); + +test("should throw an error if count is not a valid number", () => { + const str = "hello"; + const count = "abc"; + expect(() => repeat(str, count)).toThrow("Count must be a valid number"); +}); + + + From 94348cb5ff4cd4cd71c76cb9cdd3c721d0a3b00f Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Mon, 20 Oct 2025 14:05:39 +0100 Subject: [PATCH 07/13] is shortened inside the function getOrdinalNumber() --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 3 +-- 1 file changed, 1 insertion(+), 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 6c83a305f..1acc74d6f 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,6 +1,5 @@ function getOrdinalNumber(num) { - // - if (typeof num !== "number" || !Number.isInteger(num) || num <= 0) { + if (typeof num !== "number") { return "Input must be a positive integer."; } From b46e59db6f9663b0596c47c8ba501c544904523d Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Mon, 20 Oct 2025 14:07:00 +0100 Subject: [PATCH 08/13] is shortened inside the function getOrdinalNumber() --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 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 1acc74d6f..7c6883c17 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,5 @@ function getOrdinalNumber(num) { - if (typeof num !== "number") { + if (typeof num !== "number" && num <= 0) { return "Input must be a positive integer."; } From f55b3a2dc2ebd4d1669a22e5672b87b885769efc Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Mon, 20 Oct 2025 14:07:20 +0100 Subject: [PATCH 09/13] is shortened inside the function getOrdinalNumber() --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 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 7c6883c17..11c7ad3d5 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,5 @@ function getOrdinalNumber(num) { - if (typeof num !== "number" && num <= 0) { + if (typeof num !== "number" || num <= 0) { return "Input must be a positive integer."; } From f06c4f9528f0c73409bc8afb43f82ba934d54031 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Mon, 20 Oct 2025 23:31:21 +0100 Subject: [PATCH 10/13] changed condition rule in function getOrdinalNumber() and added new test cases and added throw error --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 6 +++--- .../2-practice-tdd/get-ordinal-number.test.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index 11c7ad3d5..5af6dceb9 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,6 +1,6 @@ function getOrdinalNumber(num) { - if (typeof num !== "number" || num <= 0) { - return "Input must be a positive integer."; + if (!Number.isInteger(num) || num <= 0) { + throw new Error("Input must be a positive integer."); } const lastTwoDigits = num % 100; @@ -23,5 +23,5 @@ function getOrdinalNumber(num) { return num; } -console.log(getOrdinalNumber(21)); // "1st" +//console.log(getOrdinalNumber(21)); // "1st" 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 17e6b085e..44878eca6 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -60,4 +60,20 @@ test("should return correct ordinal suffixes for big numbers", () => { expect( getOrdinalNumber(4712) ).toEqual("4712th"); expect( getOrdinalNumber(10003) ).toEqual("10003rd"); expect( getOrdinalNumber(10012) ).toEqual("10012th"); +}); + + +// Case 6: dealing with invalid inputs +// test("should return error message", () => { +// expect( getOrdinalNumber(NaN) ).toEqual("Input must be a positive integer."); +// expect( getOrdinalNumber(Infinity) ).toEqual("Input must be a positive integer."); +// expect( getOrdinalNumber("hello") ).toEqual("Input must be a positive integer."); +// expect( getOrdinalNumber([0, 3]) ).toEqual("Input must be a positive integer."); +// }); + +test("should throw an error stating that input must be a positive integer", () => { + expect(() => getOrdinalNumber(NaN)).toThrow("Input must be a positive integer."); + expect(() => getOrdinalNumber(Infinity)).toThrow("Input must be a positive integer."); + expect(() => getOrdinalNumber("hello")).toThrow("Input must be a positive integer."); + expect(() => getOrdinalNumber([0, 1, 2])).toThrow("Input must be a positive integer."); }); \ No newline at end of file From 25b186803fe5004231754ba3ccacef6e021dcbd8 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Mon, 20 Oct 2025 23:43:53 +0100 Subject: [PATCH 11/13] test cases recategorising --- .../2-practice-tdd/get-ordinal-number.test.js | 85 ++++++++----------- 1 file changed, 34 insertions(+), 51 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 44878eca6..12fdfc384 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -8,68 +8,51 @@ const getOrdinalNumber = require("./get-ordinal-number"); // When the number is 1, // Then the function should return "1st" -test("should return '1st' for 1", () => { +test("Numbers that end with `st`", () => { expect(getOrdinalNumber(1)).toEqual("1st"); expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(101)).toEqual("101st"); + expect(getOrdinalNumber(28491)).toEqual("28491st"); }); -// Case 2: Identify the ordinal number for 1 -// except those ending in 12 -test("append 'nd' to numbers ending in 2, except those ending in 12", () => { - expect( getOrdinalNumber(2) ).toEqual("2nd"); - expect( getOrdinalNumber(22) ).toEqual("22nd"); - expect( getOrdinalNumber(132) ).toEqual("132nd"); +// Case 2: "Numbers that end with `nd` +test("Numbers that end with `nd`", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(32)).toEqual("32nd"); + expect(getOrdinalNumber(202)).toEqual("202nd"); + expect(getOrdinalNumber(4502)).toEqual("4502nd"); +} + +// Case 3:: "Numbers that end with `rd` +); + +test("Numbers that end with `rd`", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(43)).toEqual("43rd"); + expect(getOrdinalNumber(123)).toEqual("123rd"); + expect(getOrdinalNumber(6703)).toEqual("6703rd"); }); -// Case 3: Identify the ordinal numbers for 3 to 12 -test("should return correct ordinal suffixes for numbers 3 to 12", () => { - expect( getOrdinalNumber(3) ).toEqual("3rd"); - expect( getOrdinalNumber(4) ).toEqual("4th"); - expect( getOrdinalNumber(5) ).toEqual("5th"); - expect( getOrdinalNumber(6) ).toEqual("6th"); - expect( getOrdinalNumber(7) ).toEqual("7th"); - expect( getOrdinalNumber(8) ).toEqual("8th"); - expect( getOrdinalNumber(9) ).toEqual("9th"); - expect( getOrdinalNumber(10) ).toEqual("10th"); - expect( getOrdinalNumber(11) ).toEqual("11th"); - expect( getOrdinalNumber(12) ).toEqual("12th"); -}); -// Case 4: Identify the ordinal numbers for numbers above 12 -test("should return correct ordinal suffixes for numbers above 12", () => { - expect( getOrdinalNumber(13) ).toEqual("13th"); - expect( getOrdinalNumber(19) ).toEqual("19th"); - expect( getOrdinalNumber(23) ).toEqual("23rd"); - expect( getOrdinalNumber(34) ).toEqual("34th"); - expect( getOrdinalNumber(45) ).toEqual("45th"); - expect( getOrdinalNumber(56) ).toEqual("56th"); - expect( getOrdinalNumber(67) ).toEqual("67th"); -}); - -// Case 5: Identify the ordinal numbers for numbers like 20 30 40 etc -test("should return correct ordinal suffixes for multiples of ten", () => { - expect( getOrdinalNumber(20) ).toEqual("20th"); - expect( getOrdinalNumber(30) ).toEqual("30th"); - expect( getOrdinalNumber(70) ).toEqual("70th"); - expect( getOrdinalNumber(50) ).toEqual("50th"); +// Case 4: "Numbers that end with `th` +test("Numbers that end with `th`", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(25)).toEqual("25th"); + expect(getOrdinalNumber(1124)).toEqual("1124th"); + expect(getOrdinalNumber(9999)).toEqual("9999th"); }); -// Case 6: dealing with big numbers -test("should return correct ordinal suffixes for big numbers", () => { - expect( getOrdinalNumber(111) ).toEqual("111th"); - expect( getOrdinalNumber(4712) ).toEqual("4712th"); - expect( getOrdinalNumber(10003) ).toEqual("10003rd"); - expect( getOrdinalNumber(10012) ).toEqual("10012th"); +// Case 5: "Numbers that are exceptions (11, 12, 13) +test("Numbers that are exceptions (11, 12, 13)", () => { + 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"); }); - -// Case 6: dealing with invalid inputs -// test("should return error message", () => { -// expect( getOrdinalNumber(NaN) ).toEqual("Input must be a positive integer."); -// expect( getOrdinalNumber(Infinity) ).toEqual("Input must be a positive integer."); -// expect( getOrdinalNumber("hello") ).toEqual("Input must be a positive integer."); -// expect( getOrdinalNumber([0, 3]) ).toEqual("Input must be a positive integer."); -// }); +// Case 6: "Non-positive integers (NaN, Infinity, non-integers) test("should throw an error stating that input must be a positive integer", () => { expect(() => getOrdinalNumber(NaN)).toThrow("Input must be a positive integer."); From 06a987e1136ec7ebbbd8ebd665d52dfdc6c52b38 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Mon, 20 Oct 2025 23:46:23 +0100 Subject: [PATCH 12/13] test cases recategorising -- styling --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 5 +---- 1 file changed, 1 insertion(+), 4 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 12fdfc384..9f46f37a2 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -21,11 +21,9 @@ test("Numbers that end with `nd`", () => { expect(getOrdinalNumber(32)).toEqual("32nd"); expect(getOrdinalNumber(202)).toEqual("202nd"); expect(getOrdinalNumber(4502)).toEqual("4502nd"); -} +}); // Case 3:: "Numbers that end with `rd` -); - test("Numbers that end with `rd`", () => { expect(getOrdinalNumber(3)).toEqual("3rd"); expect(getOrdinalNumber(43)).toEqual("43rd"); @@ -53,7 +51,6 @@ test("Numbers that are exceptions (11, 12, 13)", () => { }); // Case 6: "Non-positive integers (NaN, Infinity, non-integers) - test("should throw an error stating that input must be a positive integer", () => { expect(() => getOrdinalNumber(NaN)).toThrow("Input must be a positive integer."); expect(() => getOrdinalNumber(Infinity)).toThrow("Input must be a positive integer."); From 4b42131f53aad28a37b5f749f05fc5aa81ddd897 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Mon, 20 Oct 2025 23:50:33 +0100 Subject: [PATCH 13/13] corrected condition rule to include NaN and Infinity numbers --- Sprint-3/2-practice-tdd/repeat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index bcab83738..40d7455b0 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,5 +1,5 @@ function repeat(str, count) { - if (typeof count !== "number" || isNaN(count) || count < 0) { + if (!Number.isInteger(count) || count < 0) { throw new Error("Count must be a valid number"); } return str.repeat(count);