From 97d02c704739bd355a8a4009fd6dd77145a3ca27 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 13 Oct 2025 21:02:06 +0100 Subject: [PATCH 01/25] get angle case2 --- .../implement/1-get-angle-type.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index ca1dfe7f2..e5b0d2fb5 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -12,6 +12,9 @@ function getAngleType(angle) { return "Right angle"; } // Run the tests, work out what Case 2 is testing, and implement the required code here. + if (angle < 90) { + return "Acute angle"; + } // Then keep going for the other cases, one at a time. } From bf6c370cd37885ea4867e5978eb86d28dde6fefc Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 13 Oct 2025 21:05:01 +0100 Subject: [PATCH 02/25] case3 update --- .../1-implement-and-rewrite-tests/implement/1-get-angle-type.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index e5b0d2fb5..2bcafa2bd 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -53,6 +53,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 1a47995e26a2c6b560e299e63a9a3e8377ee910a Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 13 Oct 2025 21:09:03 +0100 Subject: [PATCH 03/25] update case 4 --- .../implement/1-get-angle-type.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 2bcafa2bd..95f23ff1a 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -16,6 +16,12 @@ function getAngleType(angle) { return "Acute angle"; } // Then keep going for the other cases, one at a time. + if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } + if (angle === 180) { + return "Straight angle"; + } } // The line below allows us to load the getAngleType function into tests in other files. @@ -60,6 +66,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 3be3bfbe09201dcbb57b1ea036d7e1136e9e1b0a Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 13 Oct 2025 21:11:23 +0100 Subject: [PATCH 04/25] update case 5 --- .../implement/1-get-angle-type.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 95f23ff1a..873354d93 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -22,6 +22,9 @@ function getAngleType(angle) { if (angle === 180) { return "Straight angle"; } + if (angle > 180 && angle < 360) { + return "Reflex angle"; + } } // The line below allows us to load the getAngleType function into tests in other files. @@ -60,16 +63,15 @@ assertEquals(acute, "Acute angle"); // 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: // 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, // 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 +const reflex = getAngleType(250); +assertEquals(reflex, "Reflex angle"); \ No newline at end of file From a7b7c2fcd876edad663a14aa84c1d0d33ce9b5b5 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 13 Oct 2025 21:44:27 +0100 Subject: [PATCH 05/25] 2-fraction/case2 --- .../implement/2-is-proper-fraction.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index a4739af77..2b8cacab8 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -11,6 +11,9 @@ function isProperFraction(numerator, denominator) { if (numerator < denominator) { return true; } + if (numerator >= denominator) { + return false; + } } // The line below allows us to load the isProperFraction function into tests in other files. From e110722de34fb8e7d0ade62c7ec8e6b62c0d2751 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 13 Oct 2025 21:50:37 +0100 Subject: [PATCH 06/25] 2-is-proper-fraction update case --- .../implement/2-is-proper-fraction.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 2b8cacab8..fd2934bd3 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -14,6 +14,12 @@ function isProperFraction(numerator, denominator) { if (numerator >= denominator) { return false; } + if (Math.abs(numerator) < Math.abs(denominator)) { + return true; + } + if (Math.abs(numerator) >= Math.abs(denominator)) { + return false; + } } // The line below allows us to load the isProperFraction function into tests in other files. @@ -49,6 +55,7 @@ assertEquals(improperFraction, false); // target output: true // 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); +assertEquals(negativeFraction, true); // ====> complete with your assertion // Equal Numerator and Denominator check: @@ -56,7 +63,15 @@ const negativeFraction = isProperFraction(-4, 7); // target output: false // 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); +assertEquals(equalFraction, false); // ====> complete with your assertion // Stretch: // What other scenarios could you test for? +// Zero Numerator check: +// Input: numerator = 0, denominator = 5 +// target output: true +// Explanation: The fraction 0/5 is a proper fraction because the numerator (0) is less than the denominator (5). The function should return true. +const zeroNumerator = isProperFraction(0, 5); +assertEquals(zeroNumerator, true); + From 716f04775de10b6fe268012ad0404a925982c860 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 13 Oct 2025 22:17:15 +0100 Subject: [PATCH 07/25] 10 card case --- .../implement/3-get-card-value.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index 266525d1b..2dcd52346 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -8,9 +8,17 @@ // 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) { + // Extract the rank (all characters except the last one which is the suit) + const rank = card.slice(0, -1); + if (rank === "A") { return 11; } + + const numValue = parseInt(rank, 10); + if (numValue >= 2 && numValue <= 10) { + return numValue; + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -39,6 +47,7 @@ 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): From 138843bd11088f83f1135c47c4286877ccbfc06e Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 13 Oct 2025 22:17:34 +0100 Subject: [PATCH 08/25] 10 card case --- .../implement/3-get-card-value.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index 2dcd52346..2c324839c 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -16,9 +16,12 @@ function getCardValue(card) { } const numValue = parseInt(rank, 10); - if (numValue >= 2 && numValue <= 10) { + if (numValue >= 2 && numValue < 10) { return numValue; } + if (rank === "10" || rank === "J" || rank === "Q" || rank === "K") { + return 10; + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -54,6 +57,8 @@ assertEquals(fiveofHearts, 5); // 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 kingofDiamonds = getCardValue("K♦"); +assertEquals(kingofDiamonds, 10); // Handle Ace (A): // Given a card with a rank of "A", From 4879aaa4f9c3e510dd5d347ad9ce5519dedf1698 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 13 Oct 2025 22:20:41 +0100 Subject: [PATCH 09/25] Ace card --- .../1-implement-and-rewrite-tests/implement/3-get-card-value.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index 2c324839c..4e51d41c3 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -64,6 +64,8 @@ assertEquals(kingofDiamonds, 10); // 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. +const aceofClubs = getCardValue("A♣"); +assertEquals(aceofClubs, 11); // Handle Invalid Cards: // Given a card with an invalid rank (neither a number nor a recognized face card), From d34d343c2a52e052799eb6425f85bf463c916081 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 13 Oct 2025 22:30:35 +0100 Subject: [PATCH 10/25] undefined case --- .../implement/3-get-card-value.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index 4e51d41c3..306bab98b 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -16,12 +16,16 @@ function getCardValue(card) { } const numValue = parseInt(rank, 10); - if (numValue >= 2 && numValue < 10) { + if (numValue >= 2 && numValue <= 10) { return numValue; } - if (rank === "10" || rank === "J" || rank === "Q" || rank === "K") { + + if (rank === "J" || rank === "Q" || rank === "K") { return 10; } + + // If we get here, it's an invalid card - return undefined + return undefined; } // The line below allows us to load the getCardValue function into tests in other files. @@ -71,3 +75,6 @@ assertEquals(aceofClubs, 11); // 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." +const invalidCard = getCardValue("1♣"); +assertEquals(invalidCard, undefined); + From 4d61885eab7a82edef5a03e68cc9b4b08d5246dc Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 13 Oct 2025 22:53:36 +0100 Subject: [PATCH 11/25] 1 rewrite test with jest --- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index 4a92a3e82..bd32a61f9 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -12,15 +12,27 @@ 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 acute angle (<90°)", () => { + 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 obtuse angle (>90° and <180°)", () => { + expect(getAngleType(135)).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 straight angle (180°)", () => { + expect(getAngleType(180)).toEqual("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" +test("should identify reflex angle (>180° and <360°)", () => { + expect(getAngleType(270)).toEqual("Reflex angle"); +}); From 989855e7e4d85a631462990531e5588ee7837392 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 13 Oct 2025 22:59:09 +0100 Subject: [PATCH 12/25] 2-is proper-fraction test with jest --- .../implement/2-is-proper-fraction.js | 13 ++++++------- .../2-is-proper-fraction.test.js | 9 +++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index fd2934bd3..116241463 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -8,16 +8,15 @@ // write one test at a time, and make it pass, build your solution up methodically function isProperFraction(numerator, denominator) { - if (numerator < denominator) { - return true; - } - if (numerator >= denominator) { + // First check: both numerator and denominator should be positive + if (numerator < 0 || denominator < 0) { return false; } - if (Math.abs(numerator) < Math.abs(denominator)) { + + // Second check: numerator should be less than denominator + if (numerator < denominator) { return true; - } - if (Math.abs(numerator) >= Math.abs(denominator)) { + } else { return false; } } diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index caf08d15b..ee3279a8c 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -7,7 +7,16 @@ test("should return true for a proper fraction", () => { }); // Case 2: Identify Improper Fractions: +test("should return false for an improper fraction", () => { + expect(isProperFraction(5, 3)).toEqual(false); +}); // Case 3: Identify Negative Fractions: +test("should return false for a negative fraction", () => { + expect(isProperFraction(-2, 3)).toEqual(false); +}); // Case 4: Identify Equal Numerator and Denominator: +test("should return false for equal numerator and denominator", () => { + expect(isProperFraction(3, 3)).toEqual(false); +}); From 56625ec8ce659db6f29207d3771a315e1f135859 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Mon, 13 Oct 2025 23:02:54 +0100 Subject: [PATCH 13/25] 3-get card value test with jest --- .../3-get-card-value.test.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index 04418ff72..b77fc48bb 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -8,6 +8,28 @@ test("should return 11 for Ace of Spades", () => { }); // Case 2: Handle Number Cards (2-10): +test("should return numeric value for number cards (2-10)", () => { + const fiveofHearts = getCardValue("5♥"); + expect(fiveofHearts).toEqual(5); +}); // Case 3: Handle Face Cards (J, Q, K): +test("should return 10 for face cards (J, Q, K)", () => { + const jackOfDiamonds = getCardValue("J♦"); + const queenOfClubs = getCardValue("Q♣"); + const kingOfHearts = getCardValue("K♥"); + expect(jackOfDiamonds).toEqual(10); + expect(queenOfClubs).toEqual(10); + expect(kingOfHearts).toEqual(10); +}); + // Case 4: Handle Ace (A): +test("should return 11 for Ace (A)", () => { + const aceOfSpades = getCardValue("A♠"); + expect(aceOfSpades).toEqual(11); +}); + // Case 5: Handle Invalid Cards: +test("should return undefined for invalid cards", () => { + const invalidCard = getCardValue("1♠"); + expect(invalidCard).toEqual(undefined); +}); From 47e385f48cc7854c2df427a54c09cef9d9f05bdd Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Tue, 14 Oct 2025 12:17:02 +0100 Subject: [PATCH 14/25] 2-practice-tdd/count test --- Sprint-3/2-practice-tdd/count.js | 12 +++++++++++- Sprint-3/2-practice-tdd/count.test.js | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..8236f4f0b 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,15 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + + // Loop through each character in the string + for (let i = 0; i < stringOfCharacters.length; i++) { + // If the current character matches the character we're looking for + if (stringOfCharacters[i] === findCharacter) { + count++; + } + } + + return count; } module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 42baf4b4b..79091d1cd 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 for no occurrences", () => { + const str = "hello"; + const char = "x"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); \ No newline at end of file From 45dc7646b8a57d57306a073046bf96cbfeea4d55 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Tue, 14 Oct 2025 13:10:34 +0100 Subject: [PATCH 15/25] 2-practice-tdd/repeat test --- Sprint-3/2-practice-tdd/repeat.js | 19 +++++++++++++++++-- Sprint-3/2-practice-tdd/repeat.test.js | 19 ++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index 00e60d7f3..cf4b2325d 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,5 +1,20 @@ -function repeat() { - return "hellohellohello"; +function repeat(str, count) { + // Handle edge cases + if (count < 0) { + throw new Error("Count cannot be negative"); + } + + if (count === 0) { + return ""; + } + + // Build the repeated string + let result = ""; + for (let i = 0; i < count; i++) { + result += str; + } + + return result; } 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..45cb41134 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -19,14 +19,31 @@ test("should repeat the string count times", () => { // case: handle Count of 1: // 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. +// 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 for count of 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, // Then it should return an empty string, ensuring that a count of 0 results in an empty output. +test("should return an empty string for count of 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, // Then it should throw an error or return an appropriate error message, as negative counts are not valid. +test("should throw an error for negative count", () => { + const str = "hello"; + const count = -2; + expect(() => repeat(str, count)).toThrow("Count cannot be negative"); +}); \ No newline at end of file From 00e6c6d2ce24c59c23e4e9d61316be4d7676539c Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Tue, 14 Oct 2025 13:17:56 +0100 Subject: [PATCH 16/25] 2-practice-tdd/get ordinal number test --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 18 +++- .../2-practice-tdd/get-ordinal-number.test.js | 97 +++++++++++++++++++ 2 files changed, 114 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..689999a21 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,21 @@ function getOrdinalNumber(num) { - return "1st"; + // Handle special cases for teens (11th, 12th, 13th) + if (num % 100 >= 11 && num % 100 <= 13) { + return num + "th"; + } + + // Handle based on last digit + const lastDigit = num % 10; + + if (lastDigit === 1) { + return num + "st"; + } else if (lastDigit === 2) { + return num + "nd"; + } else if (lastDigit === 3) { + return num + "rd"; + } else { + return num + "th"; + } } module.exports = getOrdinalNumber; diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index dfe4b6091..f2b0402b9 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,100 @@ 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, +// Then the function should 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, +// Then the function should return "3rd" + +test("should return '3rd' for 3", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); +}); + +// Case 4: Identify the ordinal number for 4 +// When the number is 4, +// Then the function should return "4th" + +test("should return '4th' for 4", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); +}); + +// Case 5: Identify the ordinal number for 11 +// When the number is 11, +// Then the function should return "11th" + +test("should return '11th' for 11", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); +}); + +// Case 6: Identify the ordinal number for 12 +// When the number is 12, +// Then the function should return "12th" + +test("should return '12th' for 12", () => { + expect(getOrdinalNumber(12)).toEqual("12th"); +}); + +// Case 7: Identify the ordinal number for 13 +// When the number is 13, +// Then the function should return "13th" + +test("should return '13th' for 13", () => { + expect(getOrdinalNumber(13)).toEqual("13th"); +}); + +// Case 8: Identify the ordinal number for 21 +// When the number is 21, +// Then the function should return "21st" + +test("should return '21st' for 21", () => { + expect(getOrdinalNumber(21)).toEqual("21st"); +}); + +// Case 9: Identify the ordinal number for 22 +// When the number is 22, +// Then the function should return "22nd" + +test("should return '22nd' for 22", () => { + expect(getOrdinalNumber(22)).toEqual("22nd"); +}); + +// Case 10: Identify the ordinal number for 23 +// When the number is 23, +// Then the function should return "23rd" + +test("should return '23rd' for 23", () => { + expect(getOrdinalNumber(23)).toEqual("23rd"); +}); + +// Case 11: Identify the ordinal number for 101 +// When the number is 101, +// Then the function should return "101st" + +test("should return '101st' for 101", () => { + expect(getOrdinalNumber(101)).toEqual("101st"); +}); + +// Case 12: Identify the ordinal number for 111 +// When the number is 111, +// Then the function should return "111th" + +test("should return '111th' for 111", () => { + expect(getOrdinalNumber(111)).toEqual("111th"); +}); + +// Case 13: Identify the ordinal number for 0 +// When the number is 0, +// Then the function should return "0th" + +test("should return '0th' for 0", () => { + expect(getOrdinalNumber(0)).toEqual("0th"); +}); + From eb1d90f58f9107486597d5aeabddf44cd6e473b7 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Sat, 25 Oct 2025 20:11:46 +0100 Subject: [PATCH 17/25] Remove checking for angle > 90 --- .../1-implement-and-rewrite-tests/implement/1-get-angle-type.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 873354d93..51e77d001 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -16,7 +16,7 @@ function getAngleType(angle) { return "Acute angle"; } // Then keep going for the other cases, one at a time. - if (angle > 90 && angle < 180) { + if (angle < 180) { return "Obtuse angle"; } if (angle === 180) { From 2f42a852f1f2846282f119df8081dec3d2b2175f Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Sat, 25 Oct 2025 20:25:57 +0100 Subject: [PATCH 18/25] convert negative numbers to positive before comparing --- .../implement/2-is-proper-fraction.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 116241463..d754393cc 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -8,11 +8,9 @@ // write one test at a time, and make it pass, build your solution up methodically function isProperFraction(numerator, denominator) { - // First check: both numerator and denominator should be positive - if (numerator < 0 || denominator < 0) { - return false; - } - + // First check: convert negative numbers to positive before comparing + numerator = Math.abs(numerator); + denominator = Math.abs(denominator); // Second check: numerator should be less than denominator if (numerator < denominator) { return true; From 6db1bca58afd0dafab7028cc4a755d2d7180e130 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Sat, 25 Oct 2025 21:07:04 +0100 Subject: [PATCH 19/25] Change test result to true for -2/3 --- .../rewrite-tests-with-jest/2-is-proper-fraction.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index ee3279a8c..3ab85f095 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -13,7 +13,7 @@ test("should return false for an improper fraction", () => { // Case 3: Identify Negative Fractions: test("should return false for a negative fraction", () => { - expect(isProperFraction(-2, 3)).toEqual(false); + expect(isProperFraction(-2, 3)).toEqual(true); }); // Case 4: Identify Equal Numerator and Denominator: From 8f61c0f6e73182019bfe7b95dfc58c9ef67e7701 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Sat, 25 Oct 2025 21:26:40 +0100 Subject: [PATCH 20/25] Change function getCardValue to use Number instead --- .../implement/3-get-card-value.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index 306bab98b..af54b0b3c 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -15,10 +15,10 @@ function getCardValue(card) { return 11; } - const numValue = parseInt(rank, 10); - if (numValue >= 2 && numValue <= 10) { - return numValue; - } +const numeric = Number(rank); +if (Number.isInteger(numeric) && numeric >= 2 && numeric <= 10) { + return numeric; +} if (rank === "J" || rank === "Q" || rank === "K") { return 10; From 0e834a6de7329edf0df1568c0c3b44babe56c2a0 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Sat, 25 Oct 2025 21:33:03 +0100 Subject: [PATCH 21/25] Add more tests --- .../3-get-card-value.test.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index b77fc48bb..d334f72d0 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -33,3 +33,34 @@ test("should return undefined for invalid cards", () => { const invalidCard = getCardValue("1♠"); expect(invalidCard).toEqual(undefined); }); + +test("should return correct value for all number cards 2-10", () => { + 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); +}); + +test("should handle numeric-literal edge cases", () => { + expect(getCardValue("0x02♠")).toEqual(2); + expect(getCardValue("2.1♠")).toBeUndefined(); + expect(getCardValue("0002♠")).toEqual(2); +}); + +test("should return 10 for all face cards", () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♥")).toEqual(10); + expect(getCardValue("K♣")).toEqual(10); +}); + +test("should return 11 for all Aces", () => { + expect(getCardValue("A♠")).toEqual(11); + expect(getCardValue("A♥")).toEqual(11); + expect(getCardValue("A♦")).toEqual(11); + expect(getCardValue("A♣")).toEqual(11); +}); \ No newline at end of file From f14ec509aebd005a3637765e52e58e05b0903584 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Sat, 25 Oct 2025 21:42:27 +0100 Subject: [PATCH 22/25] Group tests together --- .../2-practice-tdd/get-ordinal-number.test.js | 113 ++++-------------- 1 file changed, 24 insertions(+), 89 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 f2b0402b9..451932871 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -1,110 +1,45 @@ -const getOrdinalNumber = require("./get-ordinal-number"); -// In this week's prep, we started implementing getOrdinalNumber -// continue testing and implementing getOrdinalNumber for additional cases -// Write your tests using Jest - remember to run your tests often for continual feedback +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" +// To ensure thorough testing, we need broad scenario coverage. Listing individual values, however, can quickly lead to an unmanageable number of test cases. +// Instead of writing tests for individual numbers, we group all possible input values into meaningful categories and select representative samples from each category to test. This approach improves coverage and makes our tests easier to maintain. -test("should return '1st' for 1", () => { +// Numbers ending in 1 (except those ending in 11): should append 'st' +test("append 'st' to numbers ending in 1, except those ending in 11", () => { expect(getOrdinalNumber(1)).toEqual("1st"); + expect(getOrdinalNumber(21)).toEqual("21st"); + expect(getOrdinalNumber(101)).toEqual("101st"); }); -// Case 2: Identify the ordinal number for 2 -// When the number is 2, -// Then the function should return "2nd" - -test("should return '2nd' for 2", () => { +// Numbers ending in 2 (except those ending in 12): should append 'nd' +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 number for 3 -// When the number is 3, -// Then the function should return "3rd" - -test("should return '3rd' for 3", () => { +// Numbers ending in 3 (except those ending in 13): should append 'rd' +test("append 'rd' to numbers ending in 3, except those ending in 13", () => { expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(103)).toEqual("103rd"); }); -// Case 4: Identify the ordinal number for 4 -// When the number is 4, -// Then the function should return "4th" - -test("should return '4th' for 4", () => { - expect(getOrdinalNumber(4)).toEqual("4th"); -}); - -// Case 5: Identify the ordinal number for 11 -// When the number is 11, -// Then the function should return "11th" - -test("should return '11th' for 11", () => { +// Numbers ending in 11, 12, 13: should append 'th' +test("append 'th' to numbers ending in 11, 12, 13", () => { expect(getOrdinalNumber(11)).toEqual("11th"); -}); - -// Case 6: Identify the ordinal number for 12 -// When the number is 12, -// Then the function should return "12th" - -test("should return '12th' for 12", () => { expect(getOrdinalNumber(12)).toEqual("12th"); -}); - -// Case 7: Identify the ordinal number for 13 -// When the number is 13, -// Then the function should return "13th" - -test("should return '13th' for 13", () => { expect(getOrdinalNumber(13)).toEqual("13th"); -}); - -// Case 8: Identify the ordinal number for 21 -// When the number is 21, -// Then the function should return "21st" - -test("should return '21st' for 21", () => { - expect(getOrdinalNumber(21)).toEqual("21st"); -}); - -// Case 9: Identify the ordinal number for 22 -// When the number is 22, -// Then the function should return "22nd" - -test("should return '22nd' for 22", () => { - expect(getOrdinalNumber(22)).toEqual("22nd"); -}); - -// Case 10: Identify the ordinal number for 23 -// When the number is 23, -// Then the function should return "23rd" - -test("should return '23rd' for 23", () => { - expect(getOrdinalNumber(23)).toEqual("23rd"); -}); - -// Case 11: Identify the ordinal number for 101 -// When the number is 101, -// Then the function should return "101st" - -test("should return '101st' for 101", () => { - expect(getOrdinalNumber(101)).toEqual("101st"); -}); - -// Case 12: Identify the ordinal number for 111 -// When the number is 111, -// Then the function should return "111th" - -test("should return '111th' for 111", () => { expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(112)).toEqual("112th"); + expect(getOrdinalNumber(113)).toEqual("113th"); }); -// Case 13: Identify the ordinal number for 0 -// When the number is 0, -// Then the function should return "0th" - -test("should return '0th' for 0", () => { +// All other numbers: should append 'th' +test("append 'th' to all other numbers", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(14)).toEqual("14th"); expect(getOrdinalNumber(0)).toEqual("0th"); }); From 24bc0d7c525240dfed8416d83037fcc777e72147 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Sun, 26 Oct 2025 04:07:49 +0000 Subject: [PATCH 23/25] Update comment ".. to numbers ending in 0, 4-9." --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 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 451932871..7313637d9 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -35,11 +35,10 @@ test("append 'th' to numbers ending in 11, 12, 13", () => { expect(getOrdinalNumber(113)).toEqual("113th"); }); -// All other numbers: should append 'th' +// ... to numbers ending in 0, 4-9. test("append 'th' to all other numbers", () => { expect(getOrdinalNumber(4)).toEqual("4th"); expect(getOrdinalNumber(10)).toEqual("10th"); - expect(getOrdinalNumber(14)).toEqual("14th"); expect(getOrdinalNumber(0)).toEqual("0th"); }); From 338eadccb68a2b31fb8e7eac5e2c783f5789a6c8 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Sun, 26 Oct 2025 04:14:47 +0000 Subject: [PATCH 24/25] Amend Function call with negative parameters --- .../2-is-proper-fraction.test.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index 3ab85f095..22cb98606 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -11,9 +11,20 @@ test("should return false for an improper fraction", () => { expect(isProperFraction(5, 3)).toEqual(false); }); -// Case 3: Identify Negative Fractions: -test("should return false for a negative fraction", () => { - expect(isProperFraction(-2, 3)).toEqual(true); + +// Case 3: Function call with negative parameters +// Negative proper fraction: numerator absolute value less than denominator +test("should return true for negative proper fraction", () => { + expect(isProperFraction(-2, 3)).toEqual(true); // -2/3 is proper + expect(isProperFraction(2, -3)).toEqual(true); // 2/-3 is proper + expect(isProperFraction(-2, -3)).toEqual(true); // -2/-3 is proper +}); + +// Negative improper fraction: numerator absolute value greater than or equal to denominator +test("should return false for negative improper fraction", () => { + expect(isProperFraction(-5, 3)).toEqual(false); // -5/3 is improper + expect(isProperFraction(5, -3)).toEqual(false); // 5/-3 is improper + expect(isProperFraction(-5, -3)).toEqual(false); // -5/-3 is improper }); // Case 4: Identify Equal Numerator and Denominator: From 36e1138e95eadea1352f9bf0887270dcd1b81da0 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Sun, 26 Oct 2025 04:39:31 +0000 Subject: [PATCH 25/25] validate string value before converting its value --- .../implement/3-get-card-value.js | 9 +++++---- .../rewrite-tests-with-jest/3-get-card-value.test.js | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index af54b0b3c..1ad16e118 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -15,10 +15,11 @@ function getCardValue(card) { return 11; } -const numeric = Number(rank); -if (Number.isInteger(numeric) && numeric >= 2 && numeric <= 10) { - return numeric; -} + // Strictly validate rank for number cards (2-10) + const validRanks = ["2", "3", "4", "5", "6", "7", "8", "9", "10"]; + if (validRanks.includes(rank)) { + return Number(rank); + } if (rank === "J" || rank === "Q" || rank === "K") { return 10; diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index d334f72d0..d92aece50 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -47,9 +47,9 @@ test("should return correct value for all number cards 2-10", () => { }); test("should handle numeric-literal edge cases", () => { - expect(getCardValue("0x02♠")).toEqual(2); + expect(getCardValue("0x02♠")).toBeUndefined(); expect(getCardValue("2.1♠")).toBeUndefined(); - expect(getCardValue("0002♠")).toEqual(2); + expect(getCardValue("0002♠")).toBeUndefined(); }); test("should return 10 for all face cards", () => {