From be25f2c036489abe2df676eb8c7b5daf43de5164 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Tue, 17 Jun 2025 19:19:59 +0100 Subject: [PATCH 01/40] Implement acute angle identification in getAngleType function and add corresponding test case --- Sprint-3/2-mandatory-rewrite/1-get-angle-type.js | 3 ++- Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js index d61254bd7..6b17f634c 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js @@ -1,7 +1,8 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; // replace with your completed function from key-implement - + if (angle < 90) + return "Acute angle"; } diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index b62827b7c..195b2fb80 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -10,6 +10,9 @@ test("should identify right angle (90°)", () => { // Case 2: Identify Acute Angles: // When the angle is less than 90 degrees, // Then the function should return "Acute angle" +test("should identify as an acute angle (less than 90 degrees)", () => { + expect(getAngleType(45)).toEqual("Acute angle"); +} // Case 3: Identify Obtuse Angles: // When the angle is greater than 90 degrees and less than 180 degrees, From 4fa86db235143f2f874468e233d9d032ceb961e9 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Tue, 17 Jun 2025 19:42:32 +0100 Subject: [PATCH 02/40] Fix syntax error in acute angle test case --- Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index 195b2fb80..f834751df 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -12,7 +12,7 @@ test("should identify right angle (90°)", () => { // Then the function should return "Acute angle" test("should identify as an acute angle (less than 90 degrees)", () => { expect(getAngleType(45)).toEqual("Acute angle"); -} +}) // Case 3: Identify Obtuse Angles: // When the angle is greater than 90 degrees and less than 180 degrees, From d317d4fbb282125f09207acf71d1e5485df94dc4 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Tue, 17 Jun 2025 19:49:08 +0100 Subject: [PATCH 03/40] Implement angle type identification for obtuse, straight, and reflex angles in getAngleType function --- Sprint-3/2-mandatory-rewrite/1-get-angle-type.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js index 6b17f634c..03b38b79f 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.js @@ -3,6 +3,12 @@ function getAngleType(angle) { // replace with your completed function from key-implement if (angle < 90) return "Acute angle"; + if ((angle > 90) && (angle < 180)) + return "Obtuse angle"; + if (angle === 180) + return "Straight angle"; + if ((angle > 180) && (angle < 360)) + return "Reflex angle"; } @@ -11,7 +17,6 @@ function getAngleType(angle) { - // Don't get bogged down in this detail // Jest uses CommonJS module syntax by default as it's quite old // We will upgrade our approach to ES6 modules in the next course module, so for now From dea34f83944112ad9cc786e8d192cb646718a4d9 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Tue, 17 Jun 2025 19:56:05 +0100 Subject: [PATCH 04/40] Add tests for identifying obtuse angles in getAngleType function --- Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index f834751df..b8cd1fb77 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -12,15 +12,23 @@ test("should identify right angle (90°)", () => { // Then the function should return "Acute angle" test("should identify as an acute angle (less than 90 degrees)", () => { expect(getAngleType(45)).toEqual("Acute angle"); -}) +}); // Case 3: Identify Obtuse Angles: // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" +test("should identify as an obtuse angle (greater then 90 degrees and less then 180 degrees)", () => { + expect(getAngleType(90.38)).toEqual("Obtuse angle"); + expect(getAngleType(179.99)).toEqual("Obtuse angle"); + expect(getAngleType(139)).toEqual("Obtuse angle"); +}); // Case 4: Identify Straight Angles: // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" +test("should identify as a straight angle (exactly 180 degrees)", () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}) // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, From 952fd145b636ee360c07ae7a7dab376733b5c621 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Tue, 17 Jun 2025 19:59:55 +0100 Subject: [PATCH 05/40] Add test cases for identifying reflex angles in getAngleType function --- Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js index b8cd1fb77..a5d7708a5 100644 --- a/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js +++ b/Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js @@ -33,3 +33,8 @@ test("should identify as a straight angle (exactly 180 degrees)", () => { // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" +test("should identify as a reflex angle (greater than 180 degrees and less than 360 degrees)", () => { + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(359.99)).toEqual("Reflex angle"); + expect(getAngleType(270)).toEqual("Reflex angle"); +}); From 8cf3f58c166673780de0dff1dfc22b8dd1835610 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Wed, 18 Jun 2025 10:06:03 +0100 Subject: [PATCH 06/40] Implement acute angle identification in getAngleType function --- Sprint-3/1-key-implement/1-get-angle-type.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/1-key-implement/1-get-angle-type.js b/Sprint-3/1-key-implement/1-get-angle-type.js index 08d1f0cba..5a0651f58 100644 --- a/Sprint-3/1-key-implement/1-get-angle-type.js +++ b/Sprint-3/1-key-implement/1-get-angle-type.js @@ -9,6 +9,7 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; + if (angle < 90) return "Acute angle"; // read to the end, complete line 36, then pass your test here } From 6da06156310958b61eb43de49cecfaab6d9ec771 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Wed, 18 Jun 2025 10:07:13 +0100 Subject: [PATCH 07/40] Implement obtuse angle identification in getAngleType function and add corresponding test case --- Sprint-3/1-key-implement/1-get-angle-type.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-3/1-key-implement/1-get-angle-type.js b/Sprint-3/1-key-implement/1-get-angle-type.js index 5a0651f58..331e7c9bc 100644 --- a/Sprint-3/1-key-implement/1-get-angle-type.js +++ b/Sprint-3/1-key-implement/1-get-angle-type.js @@ -10,6 +10,7 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; if (angle < 90) return "Acute angle"; + if ((angle > 90) && (angle < 180)) return "Obtuse angle"; // read to the end, complete line 36, then pass your test here } @@ -44,6 +45,7 @@ assertEquals(acute, "Acute angle"); // When the angle is greater than 90 degrees and less than 180 degrees, // Then the function should return "Obtuse angle" const obtuse = getAngleType(120); +assertEquals(obtuse, "Obtuse angle"); // ====> write your test here, and then add a line to pass the test in the function above // Case 4: Identify Straight Angles: From 45209eb2ea36d0ec305c0955ed9958d6401bb26e Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Wed, 18 Jun 2025 10:09:36 +0100 Subject: [PATCH 08/40] Implement straight angle identification in getAngleType function and add corresponding test case --- Sprint-3/1-key-implement/1-get-angle-type.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-3/1-key-implement/1-get-angle-type.js b/Sprint-3/1-key-implement/1-get-angle-type.js index 331e7c9bc..990ad2afa 100644 --- a/Sprint-3/1-key-implement/1-get-angle-type.js +++ b/Sprint-3/1-key-implement/1-get-angle-type.js @@ -11,6 +11,7 @@ function getAngleType(angle) { if (angle === 90) return "Right angle"; if (angle < 90) return "Acute angle"; if ((angle > 90) && (angle < 180)) return "Obtuse angle"; + if (angle === 180) return "Straight angle"; // read to the end, complete line 36, then pass your test here } @@ -52,6 +53,8 @@ assertEquals(obtuse, "Obtuse angle"); // When the angle is exactly 180 degrees, // Then the function should return "Straight angle" // ====> write your test here, and then add a line to pass the test in the function above +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, From 37f345dc4931259178a0584ef45e6d010f122203 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Wed, 18 Jun 2025 10:11:34 +0100 Subject: [PATCH 09/40] Implement reflex angle identification in getAngleType function and add corresponding test case --- Sprint-3/1-key-implement/1-get-angle-type.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-3/1-key-implement/1-get-angle-type.js b/Sprint-3/1-key-implement/1-get-angle-type.js index 990ad2afa..bcad03b92 100644 --- a/Sprint-3/1-key-implement/1-get-angle-type.js +++ b/Sprint-3/1-key-implement/1-get-angle-type.js @@ -12,6 +12,7 @@ function getAngleType(angle) { if (angle < 90) return "Acute angle"; if ((angle > 90) && (angle < 180)) return "Obtuse angle"; if (angle === 180) return "Straight angle"; + if ((angle > 180) && (angle < 360)) return "Reflex angle"; // read to the end, complete line 36, then pass your test here } @@ -59,4 +60,6 @@ assertEquals(straight, "Straight angle"); // Case 5: Identify Reflex Angles: // When the angle is greater than 180 degrees and less than 360 degrees, // Then the function should return "Reflex angle" -// ====> write your test here, and then add a line to pass the test in the function above \ No newline at end of file +// ====> write your test here, and then add a line to pass the test in the function above +const reflex = getAngleType(270); +assertEquals(reflex, "Reflex angle"); \ No newline at end of file From ed4eaf35d447124bf98afae3d3675f5a5065cee2 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 23 Jun 2025 12:44:14 +0100 Subject: [PATCH 10/40] Implement card value retrieval for face cards and number cards in getCardValue function with comments explaining function and updated tests --- Sprint-3/1-key-implement/3-get-card-value.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-key-implement/3-get-card-value.js b/Sprint-3/1-key-implement/3-get-card-value.js index aa1cc9f90..475c1345c 100644 --- a/Sprint-3/1-key-implement/3-get-card-value.js +++ b/Sprint-3/1-key-implement/3-get-card-value.js @@ -8,9 +8,14 @@ // write one test at a time, and make it pass, build your solution up methodically // just make one change at a time -- don't rush -- programmers are deep and careful thinkers function getCardValue(card) { - if (rank === "A") return 11; + var rank = card.slice(0, -1); // get the rank of the card by removing the last character. (the suit is the last character) + if (rank === "A") return 11; // this checks for Aces + if (rank === "5") return 5; // this should check for the number 5 + if (rank === "J") return 10; // this checks for Jacks + if (rank === "Q") return 10; // this checks for Queens + if (rank === "K") return 10; // this checks for Kings + if (rank === "10") return 10; // this checks for Tens } - // You need to write assertions for your function to check it works in different cases // we're going to use this helper function to make our assertions easier to read // if the actual output matches the target output, the test will pass @@ -33,15 +38,20 @@ assertEquals(aceofSpades, 11); // When the function is called with such a card, // Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). const fiveofHearts = getCardValue("5♥"); +assertEquals(fiveofHearts, 5); // ====> write your test here, and then add a line to pass the test in the function above // Handle Face Cards (J, Q, K): // Given a card with a rank of "10," "J," "Q," or "K", // When the function is called with such a card, // Then it should return the value 10, as these cards are worth 10 points each in blackjack. +const jackOfDiamonds = getCardValue("J♦"); +const queenOfClubs = getCardValue("Q♣"); +const kingOfSpades = getCardValue("K♠"); +assertEquals(jackOfDiamonds, 10); +assertEquals(queenOfClubs, 10); +assertEquals(kingOfSpades, 10); -// Handle Ace (A): -// Given a card with a rank of "A", // When the function is called with an Ace, // Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. From a0d4fcf7ec9b37c01ae8b5aee53db2deb9709f15 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 23 Jun 2025 13:47:24 +0100 Subject: [PATCH 11/40] Implement numerical value retrieval for cards 2-9 in getCardValue function and add corresponding test cases --- Sprint-3/1-key-implement/3-get-card-value.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sprint-3/1-key-implement/3-get-card-value.js b/Sprint-3/1-key-implement/3-get-card-value.js index 475c1345c..63aa58f36 100644 --- a/Sprint-3/1-key-implement/3-get-card-value.js +++ b/Sprint-3/1-key-implement/3-get-card-value.js @@ -10,7 +10,14 @@ function getCardValue(card) { var rank = card.slice(0, -1); // get the rank of the card by removing the last character. (the suit is the last character) if (rank === "A") return 11; // this checks for Aces - if (rank === "5") return 5; // this should check for the number 5 + if (rank === "2") return 2; // this checks for the twos + if (rank === "3") return 3; // this checks for the threes + if (rank === "4") return 4; // this checks for the fours + if (rank === "5") return 5; // this should check for fives + if (rank === "6") return 6; // this checks for the sixes + if (rank === "7") return 7; // this checks for the sevens + if (rank === "8") return 8; // this checks for the eights + if (rank === "9") return 9; // this checks for the nines if (rank === "J") return 10; // this checks for Jacks if (rank === "Q") return 10; // this checks for Queens if (rank === "K") return 10; // this checks for Kings @@ -38,7 +45,13 @@ assertEquals(aceofSpades, 11); // When the function is called with such a card, // Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). const fiveofHearts = getCardValue("5♥"); +const sixofDiamonds = getCardValue("6♦"); +const sevenofClubs = getCardValue("7♣"); +const eightofSpades = getCardValue("8♠"); assertEquals(fiveofHearts, 5); +assertEquals(sixofDiamonds, 6); +assertEquals(sevenofClubs, 7); +assertEquals(eightofSpades, 8); // ====> write your test here, and then add a line to pass the test in the function above // Handle Face Cards (J, Q, K): @@ -59,3 +72,4 @@ assertEquals(kingOfSpades, 10); // Given a card with an invalid rank (neither a number nor a recognized face card), // When the function is called with such a card, // Then it should throw an error indicating "Invalid card rank." + From d32c3924b2266e6866ce4653e3c6c56871b84cca Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 23 Jun 2025 16:12:03 +0100 Subject: [PATCH 12/40] Enhance getCardValue function comments and add error handling for invalid card ranks --- Sprint-3/1-key-implement/3-get-card-value.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-key-implement/3-get-card-value.js b/Sprint-3/1-key-implement/3-get-card-value.js index 63aa58f36..b588ac3be 100644 --- a/Sprint-3/1-key-implement/3-get-card-value.js +++ b/Sprint-3/1-key-implement/3-get-card-value.js @@ -10,6 +10,7 @@ function getCardValue(card) { var rank = card.slice(0, -1); // get the rank of the card by removing the last character. (the suit is the last character) if (rank === "A") return 11; // this checks for Aces + // Handle Number Cards (2-9) if (rank === "2") return 2; // this checks for the twos if (rank === "3") return 3; // this checks for the threes if (rank === "4") return 4; // this checks for the fours @@ -18,10 +19,13 @@ function getCardValue(card) { if (rank === "7") return 7; // this checks for the sevens if (rank === "8") return 8; // this checks for the eights if (rank === "9") return 9; // this checks for the nines + // Handle Face Cards (J, Q, K) And 10's if (rank === "J") return 10; // this checks for Jacks if (rank === "Q") return 10; // this checks for Queens if (rank === "K") return 10; // this checks for Kings if (rank === "10") return 10; // this checks for Tens + // if none of the above its an invalid card and throw an error + throw new Error("Invalid card rank."); // this will throw an error if the card is not a valid rank } // You need to write assertions for your function to check it works in different cases // we're going to use this helper function to make our assertions easier to read @@ -44,6 +48,7 @@ assertEquals(aceofSpades, 11); // Given a card with a rank between "2" and "9", // When the function is called with such a card, // Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). +// ====> write your test here, and then add a line to pass the test in the function above const fiveofHearts = getCardValue("5♥"); const sixofDiamonds = getCardValue("6♦"); const sevenofClubs = getCardValue("7♣"); @@ -52,7 +57,6 @@ assertEquals(fiveofHearts, 5); assertEquals(sixofDiamonds, 6); assertEquals(sevenofClubs, 7); assertEquals(eightofSpades, 8); -// ====> write your test here, and then add a line to pass the test in the function above // Handle Face Cards (J, Q, K): // Given a card with a rank of "10," "J," "Q," or "K", @@ -72,4 +76,9 @@ assertEquals(kingOfSpades, 10); // Given a card with an invalid rank (neither a number nor a recognized face card), // When the function is called with such a card, // Then it should throw an error indicating "Invalid card rank." - +try { + getCardValue("z♠"); // this should throw an error of "Invalid card rank." + console.log("Test failed: Expected an error for invalid card rank."); +} catch(error){ + assertEquals(error.meessage, "Invalid card rank."); +} \ No newline at end of file From e7f3d74285ef2d1550a788c6f2b43c6a3b6cd2e4 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 23 Jun 2025 16:14:21 +0100 Subject: [PATCH 13/40] Fix typo in error message assertion for invalid card rank in getCardValue function --- Sprint-3/1-key-implement/3-get-card-value.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/1-key-implement/3-get-card-value.js b/Sprint-3/1-key-implement/3-get-card-value.js index b588ac3be..a4dc4ede8 100644 --- a/Sprint-3/1-key-implement/3-get-card-value.js +++ b/Sprint-3/1-key-implement/3-get-card-value.js @@ -80,5 +80,5 @@ try { getCardValue("z♠"); // this should throw an error of "Invalid card rank." console.log("Test failed: Expected an error for invalid card rank."); } catch(error){ - assertEquals(error.meessage, "Invalid card rank."); + assertEquals(error.message, "Invalid card rank."); } \ No newline at end of file From 2e2d63c4e7ea73633d18748124e31a349d020739 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 23 Jun 2025 16:34:27 +0100 Subject: [PATCH 14/40] Implement card value retrieval for all ranks in getCardValue function --- .../2-mandatory-rewrite/3-get-card-value.js | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js index 0d95d3736..5eb2ebe79 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.js @@ -1,5 +1,22 @@ function getCardValue(card) { - // replace with your code from key-implement - return 11; + var rank = card.slice(0, -1); // get the rank of the card by removing the last character. (the suit is the last character) + if (rank === "A") return 11; // this checks for Aces + // Handle Number Cards (2-9) + if (rank === "2") return 2; // this checks for the twos + if (rank === "3") return 3; // this checks for the threes + if (rank === "4") return 4; // this checks for the fours + if (rank === "5") return 5; // this should check for fives + if (rank === "6") return 6; // this checks for the sixes + if (rank === "7") return 7; // this checks for the sevens + if (rank === "8") return 8; // this checks for the eights + if (rank === "9") return 9; // this checks for the nines + // Handle Face Cards (J, Q, K) And 10's + if (rank === "J") return 10; // this checks for Jacks + if (rank === "Q") return 10; // this checks for Queens + if (rank === "K") return 10; // this checks for Kings + if (rank === "10") return 10; // this checks for Tens + // if none of the above its an invalid card and throw an error + throw new Error("Invalid card rank."); // this will throw an error if the card is not a valid rank } + module.exports = getCardValue; \ No newline at end of file From 900385e7ca37584223be452429b39eb0304fcff1 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 23 Jun 2025 16:34:44 +0100 Subject: [PATCH 15/40] Add tests for number card values 2-10 in getCardValue function --- Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 03a8e2f34..75129512a 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -6,6 +6,17 @@ test("should return 11 for Ace of Spades", () => { }); // Case 2: Handle Number Cards (2-10): +test("should return the correct value for number cards between 2 and 9", () => { + expect(getCardValue("2♥")).toEqual(2); + expect(getCardValue("3♦")).toEqual(3); + expect(getCardValue("4♣")).toEqual(4); + expect(getCardValue("5♠")).toEqual(5); + expect(getCardValue("6♥")).toEqual(6); + expect(getCardValue("7♦")).toEqual(7); + expect(getCardValue("8♣")).toEqual(8); + expect(getCardValue("9♠")).toEqual(9); + expect(getCardValue("10♥")).toEqual(10); +}); // Case 3: Handle Face Cards (J, Q, K): // Case 4: Handle Ace (A): // Case 5: Handle Invalid Cards: From 67c92c265392430dec3b5090a3fccf92e3ce24c7 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 23 Jun 2025 16:39:37 +0100 Subject: [PATCH 16/40] Add tests for face cards (J, Q, K) in getCardValue function --- Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 75129512a..bd3736e68 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -18,5 +18,10 @@ test("should return the correct value for number cards between 2 and 9", () => { expect(getCardValue("10♥")).toEqual(10); }); // Case 3: Handle Face Cards (J, Q, K): +test("should return 10 for face cards (J, Q, K)", () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♦")).toEqual(10); + expect(getCardValue("K♣")).toEqual(10); +}); // Case 4: Handle Ace (A): // Case 5: Handle Invalid Cards: From 60ed74f46e0951088546c0f683fb70571456ea04 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 23 Jun 2025 16:44:08 +0100 Subject: [PATCH 17/40] add tests for handling Aces in getCardValue function --- Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index bd3736e68..4a6a06d29 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -24,4 +24,7 @@ test("should return 10 for face cards (J, Q, K)", () => { expect(getCardValue("K♣")).toEqual(10); }); // Case 4: Handle Ace (A): +test("should return 11 for Aces", () => { + expectCardValue("A♠").toEqual(11); +}) // Case 5: Handle Invalid Cards: From bcdba1c9cff4b3c81e85f6279021bab6df852928 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 23 Jun 2025 16:47:42 +0100 Subject: [PATCH 18/40] fix: correct expect statement for Ace value in getCardValue tests --- Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 4a6a06d29..6ae3195cf 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -25,6 +25,6 @@ test("should return 10 for face cards (J, Q, K)", () => { }); // Case 4: Handle Ace (A): test("should return 11 for Aces", () => { - expectCardValue("A♠").toEqual(11); -}) + expect(getCardValue("A♠")).toEqual(11); +}); // Case 5: Handle Invalid Cards: From a16c211d7fb45686536ea38eeaf1cc16ecb62de5 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 23 Jun 2025 17:01:44 +0100 Subject: [PATCH 19/40] add test for handling invalid card ranks in getCardValue function --- Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js index 6ae3195cf..1aeba3e40 100644 --- a/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js +++ b/Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js @@ -28,3 +28,7 @@ test("should return 11 for Aces", () => { expect(getCardValue("A♠")).toEqual(11); }); // Case 5: Handle Invalid Cards: +test("should throw an error for invalid card ranks", () => { + expect(() => getCardValue("X♠")).toThrow("Invalid card rank."); + expect(() => getCardValue("1♠")).toThrow("Invalid card rank."); +}) From aced4d1e4a1a9adafcafa1b771f39e442813bee5 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Wed, 25 Jun 2025 12:51:53 +0100 Subject: [PATCH 20/40] refactor: implement character counting logic in countChar function --- Sprint-3/3-mandatory-practice/implement/count.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-practice/implement/count.js b/Sprint-3/3-mandatory-practice/implement/count.js index fce249650..f18e4ebd1 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.js +++ b/Sprint-3/3-mandatory-practice/implement/count.js @@ -1,5 +1,18 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + // start a count of 0 + let count = 0; + + // check each of the characters in the string one by one. + for (let i = 0; i < stringOfCharacters.length; i++) { + // checks if the current characters matches the one were looking for in the string. + if (stringOfCharacters[i] === findCharacter) + // if it does, we increment the count by 1. + count = count + 1; +} + + return count; } +console.log(countChar("aaaaa", "a")); // 5 +console.log(countChar("hello", "l")); // 2 module.exports = countChar; \ No newline at end of file From 0a913b098480abf83be7f62509c7b25946b4db2a Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Wed, 25 Jun 2025 13:03:40 +0100 Subject: [PATCH 21/40] add test for handling no occurrences of a character in countChar function --- Sprint-3/3-mandatory-practice/implement/count.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-3/3-mandatory-practice/implement/count.test.js b/Sprint-3/3-mandatory-practice/implement/count.test.js index 42baf4b4b..9f0bf3d7d 100644 --- a/Sprint-3/3-mandatory-practice/implement/count.test.js +++ b/Sprint-3/3-mandatory-practice/implement/count.test.js @@ -22,3 +22,10 @@ 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 for no occurrences of a character", () => { + const str = "example"; + const char = "z"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); \ No newline at end of file From de7632bab2419464f35bd59ad9627e782c150c60 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Fri, 27 Jun 2025 12:06:13 +0100 Subject: [PATCH 22/40] refactor: implement getOrdinalNumber function to return correct ordinal suffixes --- .../implement/get-ordinal-number.js | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js index 24f528b0d..39bb57969 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js @@ -1,5 +1,36 @@ function getOrdinalNumber(num) { - return "1st"; + const lastTwoDigits = num % 100; // gets the last two digits of the number because some like 11, 12, 13 are special cases. + const lastDigit= num % 10; // gets the last digit to decide if its going to be "St, Nd, Rd" + + // handles special cases "11, 12 ,13" to always end in "Th". + if(lastTwoDigits === 11 || lastTwoDigits === 11 || lastTwoDigits === 13){ + return num + "TH"; + } + + // will return "St" if the number ends in 1. + if (lastDigit === 1){ + return num + "ST"; + } +// will return "Nd" if the number ends in 2. + if (lastDigit === 2){ + return num + "ND"; + } +// will return "Rd" if the number ends in 3. + if (lastDigit === 3){ + return num + "RD"; + } + +// will return all numbers that end in 4, 5, 6, 7, 8, 9 with "Th". + return num + "TH"; } -module.exports = getOrdinalNumber; \ No newline at end of file +console.log(getOrdinalNumber(1)); +console.log(getOrdinalNumber(2)); +console.log(getOrdinalNumber(3)); +console.log(getOrdinalNumber(11)); +console.log(getOrdinalNumber(12)); +console.log(getOrdinalNumber(13)); +console.log(getOrdinalNumber(21)); +console.log(getOrdinalNumber(22)); +console.log(getOrdinalNumber(23)); +console.log(getOrdinalNumber(24)); \ No newline at end of file From aa7b3ee87c87dc34627a6c40679d81a697b3c2c4 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Fri, 27 Jun 2025 12:17:41 +0100 Subject: [PATCH 23/40] reimplmented module.exports for jest tests --- Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js index 39bb57969..7ee98e315 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js @@ -33,4 +33,6 @@ console.log(getOrdinalNumber(13)); console.log(getOrdinalNumber(21)); console.log(getOrdinalNumber(22)); console.log(getOrdinalNumber(23)); -console.log(getOrdinalNumber(24)); \ No newline at end of file +console.log(getOrdinalNumber(24)); + +module.exports = getOrdinalNumber; \ No newline at end of file From d2a8646e54669e70628ef420eed868210ea20723 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Fri, 27 Jun 2025 12:19:00 +0100 Subject: [PATCH 24/40] fix: correct ordinal suffix casing in getOrdinalNumber function --- .../implement/get-ordinal-number.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js index 7ee98e315..0c177ba4c 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js @@ -4,24 +4,24 @@ function getOrdinalNumber(num) { // handles special cases "11, 12 ,13" to always end in "Th". if(lastTwoDigits === 11 || lastTwoDigits === 11 || lastTwoDigits === 13){ - return num + "TH"; + return num + "th"; } // will return "St" if the number ends in 1. if (lastDigit === 1){ - return num + "ST"; + return num + "st"; } // will return "Nd" if the number ends in 2. if (lastDigit === 2){ - return num + "ND"; + return num + "nd"; } // will return "Rd" if the number ends in 3. if (lastDigit === 3){ - return num + "RD"; + return num + "rd"; } // will return all numbers that end in 4, 5, 6, 7, 8, 9 with "Th". - return num + "TH"; + return num + "th"; } console.log(getOrdinalNumber(1)); From 9798ed9f06524f2b09f523d8e8f32fe42e9712b8 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Fri, 27 Jun 2025 12:32:24 +0100 Subject: [PATCH 25/40] refactor: remove console.log statements from getOrdinalNumber function --- .../implement/get-ordinal-number.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js index 0c177ba4c..7a78c8bd0 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js @@ -24,15 +24,4 @@ function getOrdinalNumber(num) { return num + "th"; } -console.log(getOrdinalNumber(1)); -console.log(getOrdinalNumber(2)); -console.log(getOrdinalNumber(3)); -console.log(getOrdinalNumber(11)); -console.log(getOrdinalNumber(12)); -console.log(getOrdinalNumber(13)); -console.log(getOrdinalNumber(21)); -console.log(getOrdinalNumber(22)); -console.log(getOrdinalNumber(23)); -console.log(getOrdinalNumber(24)); - module.exports = getOrdinalNumber; \ No newline at end of file From 63a66e28401ecd4424b5965414a72dfbb7a1c0e3 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Fri, 27 Jun 2025 12:34:52 +0100 Subject: [PATCH 26/40] test: add test cases for ordinal numbers 2 and 3 in getOrdinalNumber function --- .../implement/get-ordinal-number.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index 6d55dfbb4..b9b0de08a 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -11,3 +11,19 @@ const getOrdinalNumber = require("./get-ordinal-number"); test("should return '1st' for 1", () => { expect(getOrdinalNumber(1)).toEqual("1st"); }); + +// Case 2: Identify the ordinal number for 2 +// When the number is 2, +// The function should then return "2nd". + +test("Should return `2nd` for 2", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); +}); + +// Case 3: Identify the ordinal number for 3 +// When the number is 3, +// The Function should the return "3rd" + +test("Should return `3rd` for 3", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); +}); \ No newline at end of file From c89c3b8af533afa3977719ea0024d64310f981bd Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Fri, 27 Jun 2025 12:59:48 +0100 Subject: [PATCH 27/40] test: enhance test cases for ordinal numbers 1, 2, and 3 in getOrdinalNumber function --- .../implement/get-ordinal-number.test.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index b9b0de08a..fb131e6fe 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -8,16 +8,20 @@ const getOrdinalNumber = require("./get-ordinal-number"); // When the number is 1, // Then the function should return "1st" -test("should return '1st' for 1", () => { +test("should return 'st' for ordinal numbers ending in 1 like (1, 21, 31..)", () => { expect(getOrdinalNumber(1)).toEqual("1st"); + expect(getOrdinalNumber(21)).toEqual("21st"); + expect(getOrdinalNumber(31)).toEqual("31st") }); // Case 2: Identify the ordinal number for 2 // When the number is 2, // The function should then return "2nd". -test("Should return `2nd` for 2", () => { +test("Should return `nd` for ordinal numbers ending in 2 like (2, 22, 32)", () => { expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(22)).toEqual("22nd"); + expect(getOrdinalNumber(32)).toEqual("32nd"); }); // Case 3: Identify the ordinal number for 3 @@ -26,4 +30,6 @@ test("Should return `2nd` for 2", () => { test("Should return `3rd` for 3", () => { expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(33)).toEqual("33rd"); }); \ No newline at end of file From 2b44bf730edf4bf6870dddc5617a877e7663a9f6 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Fri, 27 Jun 2025 13:37:58 +0100 Subject: [PATCH 28/40] fix: correct conditional check for special cases in getOrdinalNumber function --- Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js index 7a78c8bd0..c9b9946a9 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js @@ -3,7 +3,7 @@ function getOrdinalNumber(num) { const lastDigit= num % 10; // gets the last digit to decide if its going to be "St, Nd, Rd" // handles special cases "11, 12 ,13" to always end in "Th". - if(lastTwoDigits === 11 || lastTwoDigits === 11 || lastTwoDigits === 13){ + if(lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13){ return num + "th"; } From df5287dba56f9eb06643bb161c70c2daaa16b85a Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Fri, 27 Jun 2025 13:40:22 +0100 Subject: [PATCH 29/40] test: update test descriptions for ordinal numbers and implemented a test for special ordinal numbers --- .../implement/get-ordinal-number.test.js | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js index fb131e6fe..b116fdd3a 100644 --- a/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js +++ b/Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js @@ -6,9 +6,9 @@ const getOrdinalNumber = require("./get-ordinal-number"); // Case 1: Identify the ordinal number for 1 // When the number is 1, -// Then the function should return "1st" +// Then the function should return ordinal numbers what end with the "1st" -test("should return 'st' for ordinal numbers ending in 1 like (1, 21, 31..)", () => { +test("should return '1st' for ordinal numbers ending in 1 like (1, 21, 31..)", () => { expect(getOrdinalNumber(1)).toEqual("1st"); expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(31)).toEqual("31st") @@ -16,9 +16,9 @@ test("should return 'st' for ordinal numbers ending in 1 like (1, 21, 31..)", () // Case 2: Identify the ordinal number for 2 // When the number is 2, -// The function should then return "2nd". +// The function should then return ordinal numbers what end with the "2nd". -test("Should return `nd` for ordinal numbers ending in 2 like (2, 22, 32)", () => { +test("Should return `2nd` for ordinal numbers ending in 2 like (2, 22, 32...)", () => { expect(getOrdinalNumber(2)).toEqual("2nd"); expect(getOrdinalNumber(22)).toEqual("22nd"); expect(getOrdinalNumber(32)).toEqual("32nd"); @@ -26,10 +26,23 @@ test("Should return `nd` for ordinal numbers ending in 2 like (2, 22, 32)", () = // Case 3: Identify the ordinal number for 3 // When the number is 3, -// The Function should the return "3rd" +// The Function should return the ordinal numbers what finish with the "3rd" -test("Should return `3rd` for 3", () => { +test("Should return `3rd` for ordinal numbers ending in 3 like (3, 23, 33...", () => { expect(getOrdinalNumber(3)).toEqual("3rd"); expect(getOrdinalNumber(23)).toEqual("23rd"); expect(getOrdinalNumber(33)).toEqual("33rd"); +}); + +// Case 4: identify the special ordinal numbers for 11, 12, 13 +// When the number is 11, 12, 13, +// The function should return "11th, 12th, 13th" + +test ("should return `11th, 12th, 13th` for special ordinal numbers ending on these", () => { + 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"); }); \ No newline at end of file From 1f02ed65ec8e1697d76b113f39c92f72f76fa192 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sat, 28 Jun 2025 11:01:21 +0100 Subject: [PATCH 30/40] implemented repeat function with error handling and edge cases with comments detailing. --- .../3-mandatory-practice/implement/repeat.js | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index 621f9bd35..c23f1e63c 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -1,5 +1,24 @@ -function repeat() { - return "hellohellohello"; -} +function repeat(str, count) { + // Check if "count" is a negative number. + if (count < 0) { + // Will throw error if "count" is negative. + throw new Error("Count must be a positve number"); + } + // Check if the count equals 0 + if (count === 0) { + // Returns empty string if count is equal to 0. + return ""; + } + //check if the count is equals 1. + if (count === 1) { + //returns just the string as its not needed to be repeated + return str; + } + return str.repeat(count); // if the count is above two it repeat "count" number of times. +} +console.log(repeat("hello", 0)); // expect "" +console.log(repeat("hello", 1)); // expect string to be called +console.log(repeat("hello", 3));// expect string to be repeated 3 times. +console.log(repeat("hello", -1)); // expect string to throw error for being a negative number module.exports = repeat; \ No newline at end of file From 900db997e5fe8d9a329c0643696c426b974782ee Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sat, 28 Jun 2025 12:01:23 +0100 Subject: [PATCH 31/40] fix: correct typo in error message for negative count in repeat function --- Sprint-3/3-mandatory-practice/implement/repeat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index c23f1e63c..88f854079 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -2,7 +2,7 @@ function repeat(str, count) { // Check if "count" is a negative number. if (count < 0) { // Will throw error if "count" is negative. - throw new Error("Count must be a positve number"); + throw new Error("Count must be a positive number"); } // Check if the count equals 0 From 5d2265b22fe08577a466bb7cb2e89315b5939aa1 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sat, 28 Jun 2025 12:31:34 +0100 Subject: [PATCH 32/40] refactor: comment out console log examples in repeat function --- Sprint-3/3-mandatory-practice/implement/repeat.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.js b/Sprint-3/3-mandatory-practice/implement/repeat.js index 88f854079..4ee8bc605 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.js @@ -17,8 +17,9 @@ function repeat(str, count) { } return str.repeat(count); // if the count is above two it repeat "count" number of times. } -console.log(repeat("hello", 0)); // expect "" +/* console.log(repeat("hello", 0)); // expect "" console.log(repeat("hello", 1)); // expect string to be called console.log(repeat("hello", 3));// expect string to be repeated 3 times. console.log(repeat("hello", -1)); // expect string to throw error for being a negative number +*/ module.exports = repeat; \ No newline at end of file From 525641a0da94bcf0d7ea2797de1e0c9b69f195a8 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sat, 28 Jun 2025 12:35:16 +0100 Subject: [PATCH 33/40] test: add test case for returning original string when count is 1 --- Sprint-3/3-mandatory-practice/implement/repeat.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.test.js b/Sprint-3/3-mandatory-practice/implement/repeat.test.js index 8a4ab42ef..136e4de74 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.test.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.test.js @@ -21,6 +21,13 @@ 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 return the original string when count is 1", () => { + 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, From 4f81c7d3a8bcd13a97b8e0d45bf7a1bb19ea77dc Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sat, 28 Jun 2025 12:38:30 +0100 Subject: [PATCH 34/40] test: add test case for handling count of 0 in repeat function --- Sprint-3/3-mandatory-practice/implement/repeat.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.test.js b/Sprint-3/3-mandatory-practice/implement/repeat.test.js index 136e4de74..e3e0b6a1e 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.test.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.test.js @@ -33,6 +33,13 @@ test("should return the original string when count is 1", () => { // 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 give a empty string when count is 0", () => { + 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, From d34ba1996d8a921505b3c0d1d3c36dc295a57820 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sat, 28 Jun 2025 12:45:16 +0100 Subject: [PATCH 35/40] test: add test case for handling negative count in repeat function --- Sprint-3/3-mandatory-practice/implement/repeat.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-3/3-mandatory-practice/implement/repeat.test.js b/Sprint-3/3-mandatory-practice/implement/repeat.test.js index e3e0b6a1e..bd21f0223 100644 --- a/Sprint-3/3-mandatory-practice/implement/repeat.test.js +++ b/Sprint-3/3-mandatory-practice/implement/repeat.test.js @@ -44,3 +44,9 @@ test("should give a empty string when count is 0", () => { // 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 throw an error when count is negative", () => { + const str = "hello" + const count = -1; + expect(() => repeat(str,count)).toThrow("Count must be a positive number"); +}); \ No newline at end of file From dd38ca51619cb4ba2d97427196dccc4b425bd50d Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sat, 28 Jun 2025 14:25:43 +0100 Subject: [PATCH 36/40] fix: add missing assertions for negative and equal fraction checks --- Sprint-3/1-key-implement/2-is-proper-fraction.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-3/1-key-implement/2-is-proper-fraction.js b/Sprint-3/1-key-implement/2-is-proper-fraction.js index 91583e941..7df83dfb4 100644 --- a/Sprint-3/1-key-implement/2-is-proper-fraction.js +++ b/Sprint-3/1-key-implement/2-is-proper-fraction.js @@ -9,6 +9,7 @@ function isProperFraction(numerator, denominator) { if (numerator < denominator) return true; + else return false; } // here's our helper again @@ -41,6 +42,7 @@ assertEquals(improperFraction, false); // Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. const negativeFraction = isProperFraction(-4, 7); // ====> complete with your assertion +assertEquals(properFraction, true); // Equal Numerator and Denominator check: // Input: numerator = 3, denominator = 3 @@ -48,6 +50,7 @@ const negativeFraction = isProperFraction(-4, 7); // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. const equalFraction = isProperFraction(3, 3); // ====> complete with your assertion +assertEquals(equalFraction, false) // Stretch: // What other scenarios could you test for? From 579816390b3a83427bd62a6dcccbb24dbfb6fd61 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sat, 28 Jun 2025 14:41:18 +0100 Subject: [PATCH 37/40] fix: clarify return statement in isProperFraction function --- Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js index 9836fe398..175849a78 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js @@ -1,6 +1,6 @@ function isProperFraction(numerator, denominator) { if (numerator < denominator) return true; - // add your completed function from key-implement here + else return false; // returns false if numerator is not less than denominator } module.exports = isProperFraction; \ No newline at end of file From a8d9ac36f3986ee5bc10453b5f1e2c4661e85927 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sat, 28 Jun 2025 14:41:54 +0100 Subject: [PATCH 38/40] test: add missing test case for improper fraction --- Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js index ff1cc8173..f0c23a9af 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js @@ -5,6 +5,9 @@ test("should return true for a proper fraction", () => { }); // Case 2: Identify Improper Fractions: +test("should return false for a improper faction", () => { + expect(isProperFraction(5, 2)).toEqual(false); +}); // Case 3: Identify Negative Fractions: From 1a34fcfd437ca006c6495d717e54d9354bae8df9 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sat, 28 Jun 2025 14:48:39 +0100 Subject: [PATCH 39/40] test: add missing test case for negative fraction --- Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js index f0c23a9af..d9e58d216 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js @@ -10,5 +10,8 @@ test("should return false for a improper faction", () => { }); // Case 3: Identify Negative Fractions: +test("should return true for a negative fraction", () => { + expect(isProperFraction(-4, 7)).toEqual(true); +}); // Case 4: Identify Equal Numerator and Denominator: From c5d43427adf3f0d8f216e1d955ab233e5ea8dd31 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sat, 28 Jun 2025 14:51:34 +0100 Subject: [PATCH 40/40] test: add missing test case for equal fraction --- Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js index d9e58d216..979f0f904 100644 --- a/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js +++ b/Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js @@ -15,3 +15,6 @@ test("should return true for a negative fraction", () => { }); // Case 4: Identify Equal Numerator and Denominator: +test("should return false for a equal fraction", () => { + expect(isProperFraction(3, 3)).toEqual(false); +})