From 9eed6df5bc2a2057bc1d5412a33185f383ae32c6 Mon Sep 17 00:00:00 2001 From: Ebrahim_Moqbel Date: Fri, 6 Mar 2026 16:27:26 +0000 Subject: [PATCH 1/7] completed the implement exercise --- .../implement/1-get-angle-type.js | 34 +++++++++ .../implement/2-is-proper-fraction.js | 21 ++++++ .../implement/3-get-card-value.js | 70 ++++++++++++++++++- 3 files changed, 123 insertions(+), 2 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 9e05a871e2..33cbb886eb 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,19 @@ function getAngleType(angle) { // TODO: Implement this function + if (angle > 0 && angle < 90) { + return "Acute angle"; + } else if (angle === 90) { + return "Right angle"; + } else if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } else if (angle === 180) { + return "Straight angle"; + } else if (angle > 180 && angle < 360) { + return "Reflex angle"; + } else { + return "Invalid angle"; + } } // The line below allows us to load the getAngleType function into tests in other files. @@ -35,3 +48,24 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +const Acute = getAngleType(45); +assertEquals(Acute, "Acute angle") + +const Obtuse = getAngleType(120); +assertEquals(Obtuse, "Obtuse angle") + +const Straight = getAngleType(180); +assertEquals(Straight, "Straight angle") + +const Reflex = getAngleType(270); +assertEquals(Reflex, "Reflex angle") + +const InvalidNegative= getAngleType(-10); +assertEquals(InvalidNegative, "Invalid angle") + +const InvalidOver= getAngleType(400); +assertEquals(InvalidOver, "Invalid angle") + +const InvalidZero= getAngleType(0); +assertEquals(InvalidZero, "Invalid angle") \ No newline at end of file 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 970cb9b641..43b767d29f 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,14 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { + if (denominator >numerator && denominator !==0) { + return ture ; + + } + else{ + return false; + } + return Math.abs(numerator) < Math.abs(denominator); // TODO: Implement this function } @@ -31,3 +39,16 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +//2/1 is not a proper fraction +assertEquals(isProperFraction(2,1), false); +//0/1 is a proper fraction +assertEquals(isProperFraction(0,1), true); +//negative fraction -1/2 is a proper fraction +assertEquals(isProperFraction(-1,2), true); +//negative fraction -1/-2 is not a proper fraction +assertEquals(isProperFraction(-1,-2), false); +//fraction with zero denominator is not a proper fraction +assertEquals(isProperFraction(1,0), false); +//fraction with zero numerator is a proper fraction +assertEquals(isProperFraction(0,5), true); 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 c7559e787e..09997555ab 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 @@ -23,8 +23,27 @@ function getCardValue(card) { // TODO: Implement this function + let rank = card.slice(0,-1); + let cardFace = card[card.length - 1]; + + if (!["♠", "♥", "♦", "♣"].includes(cardFace)) { + throw new Error(`Invalid card face: ${cardFace}`); + } + if (rank === "A") { + return 11; + } + if (+rank >= 2 && +rank <= 9) { + return +rank; + } + if (["K", "10", "Q", "J"].includes(rank)) { + return 10; + } + if (!["♠", "♥", "♦", "♣"].includes(cardFace)) { + } + throw new Error(`Invalid card rank: ${rank}`); } + // The line below allows us to load the getCardValue function into tests in other files. // This will be useful in the "rewrite tests with jest" step. module.exports = getCardValue; @@ -39,14 +58,61 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: -assertEquals(getCardValue("9♠"), 9); +// (Ace All suits) +const aceOfSpades = getCardValue("A♠"); +assertEquals(aceOfSpades, 11); + +const aceOfHearts = getCardValue("A♥"); +assertEquals(aceOfHearts, 11); + +const aceOfDiamonds = getCardValue("A♦"); +assertEquals(aceOfDiamonds, 11); + +const aceOfClubs = getCardValue("A♣"); +assertEquals(aceOfClubs, 11); + +// (Face cards) +const jackOfHearts = getCardValue("J♥"); +assertEquals(jackOfHearts, 10); + +const queenOfClubs = getCardValue("Q♣"); +assertEquals(queenOfClubs, 10); + +const kingOfSpades = getCardValue("K♠"); +assertEquals(kingOfSpades, 10); + +// (Number cards) +const threeOfDiamonds = getCardValue("3♦"); +assertEquals(threeOfDiamonds, 3); + +const sevenOfClubs = getCardValue("7♣"); +assertEquals(sevenOfClubs, 7); + + // Handling invalid cards +// giving an invalid rank (a number or an recognized face card) +// When the function is called with such a card, +// Then it should throw an error indicating "Invalid card rank." try { getCardValue("invalid"); // This line will not be reached if an error is thrown as expected console.error("Error was not thrown for invalid card"); -} catch (e) {} +} catch (error) {} // What other invalid card cases can you think of? + +try { + getCardValue("1♠"); + console.error("Error was not thrown for invalid card rank"); +} catch (error) { + assertEquals(error.message, "Invalid card rank"); +} + +try { + getCardValue("5X"); + console.error("Error was not thrown for invalid card suit"); +} catch (error) { + assertEquals(error.message, "Invalid card suit"); +} \ No newline at end of file From 49b88ad97972a7bca874e3de906226ed2396bce4 Mon Sep 17 00:00:00 2001 From: Ebrahim_Moqbel Date: Fri, 6 Mar 2026 16:55:37 +0000 Subject: [PATCH 2/7] rewrote test with jest --- .../1-get-angle-type.test.js | 29 +++++++++++++++++++ .../2-is-proper-fraction.test.js | 24 +++++++++++++++ .../3-get-card-value.test.js | 21 +++++++++++++- 3 files changed, 73 insertions(+), 1 deletion(-) 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 d777f348d3..81be9e8c62 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 @@ -14,7 +14,36 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when (angle === 90)`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { + // Test various obtuse angles, including boundary cases + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(120)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); + // Case 4: Straight angle +test(`should return "Straight angle" when (angle === 180)`, () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); + // Case 5: Reflex angles +test(`should return "Reflex angle" when (180 < angle < 360)`, () => { + // Test various reflex angles, including boundary cases + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(270)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test(`should throw an error when (angle < 0 or angle >= 360)`, () => { + expect(() => getAngleType(-1)).toThrow("Invalid angle"); + expect(() => getAngleType(360)).toThrow("Invalid angle"); +}); +test(`should throw an error when (angle === 0)`, () => { + expect(() => getAngleType(0)).toThrow("Invalid angle"); +}); \ No newline at end of file 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 7f087b2ba1..ae8ee1b197 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,4 +7,28 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); // Special case: numerator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); + expect(isProperFraction(-5, 0)).toEqual(false); }); + +test(`should return true for positive proper fractions`, () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(2, 5)).toEqual(true); +}); + +test(`should return false for positive improper fractions or equal values`, () => { + expect(isProperFraction(3, 2)).toEqual(false); + expect(isProperFraction(5, 5)).toEqual(false); +}); + +test(`should return true when numerator is zero`, () => { + expect(isProperFraction(0, 5)).toEqual(true); + expect(isProperFraction(0, -5)).toEqual(true); +}); + +test(`should evaluate correctly with various negative number combinations`, () => { + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(1, -2)).toEqual(true); + expect(isProperFraction(-1, -2)).toEqual(true); + expect(isProperFraction(-5, 2)).toEqual(false); + expect(isProperFraction(5, -2)).toEqual(false); +}); \ No newline at end of file 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 cf7f9dae2e..1d2c7736fc 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 @@ -11,8 +11,27 @@ test(`Should return 11 when given an ace card`, () => { // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) +test(`Should return the correct value for number cards (2-10)`), () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("5♠")).toEqual(5); + expect(getCardValue("10♠")).toEqual(10); +} // Face Cards (J, Q, K) -// Invalid Cards +test(`Should return 10 when given a face card (J, Q, K)`), () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♠")).toEqual(10); + expect(getCardValue("K♠")).toEqual(10); +} +// Invalid Card suits +test(`Should throw an error when given an invalid card suit`), () => { + expect(() => getCardValue("3-")).toThrow("Invalid card rank"); + expect(() => getCardValue("5X")).toThrow("Invalid card suit"); + +// Invalid Card ranks +test(`Should throw an error when given an invalid card rank`), () => { + expect(() => getCardValue("1♠")).toThrow("Invalid card rank"); + expect(() => getCardValue("11♠")).toThrow("Invalid card rank"); +} // To learn how to test whether a function throws an error as expected in Jest, // please refer to the Jest documentation: From 3c92b4849340980016feb4bb6f06a57b9af2981c Mon Sep 17 00:00:00 2001 From: Ebrahim_Moqbel Date: Sat, 14 Mar 2026 00:49:49 +0000 Subject: [PATCH 3/7] fixed the logic error or the two return value in the finction a --- .../implement/2-is-proper-fraction.js | 9 +-------- 1 file changed, 1 insertion(+), 8 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 43b767d29f..a82f5b1fa6 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,15 +11,8 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - if (denominator >numerator && denominator !==0) { - return ture ; - - } - else{ - return false; - } + if (denominator === 0) return false; // matches your test expectation return Math.abs(numerator) < Math.abs(denominator); - // TODO: Implement this function } // The line below allows us to load the isProperFraction function into tests in other files. From bfb2769e17174ec6aac07ab7c35787f0436f8d48 Mon Sep 17 00:00:00 2001 From: Ebrahim_Moqbel Date: Sat, 14 Mar 2026 12:18:50 +0000 Subject: [PATCH 4/7] I met the expectation of the error behaviour outcome which is Error instead of invalid angle. --- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 81be9e8c62..56f054360a 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 @@ -41,9 +41,9 @@ test(`should return "Reflex angle" when (180 < angle < 360)`, () => { // Case 6: Invalid angles test(`should throw an error when (angle < 0 or angle >= 360)`, () => { - expect(() => getAngleType(-1)).toThrow("Invalid angle"); - expect(() => getAngleType(360)).toThrow("Invalid angle"); + expect(() => getAngleType(-1)).toThrow("Error"); + expect(() => getAngleType(360)).toThrow("Error"); }); test(`should throw an error when (angle === 0)`, () => { - expect(() => getAngleType(0)).toThrow("Invalid angle"); + expect(() => getAngleType(0)).toThrow("Error"); }); \ No newline at end of file From 34ae0f23f4ee883b47d5133f30a2a8c4e2a6a673 Mon Sep 17 00:00:00 2001 From: Ebrahim_Moqbel Date: Sat, 14 Mar 2026 12:34:45 +0000 Subject: [PATCH 5/7] Fixed the logic bug( a misplced parenthesis --- .../3-get-card-value.test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 1d2c7736fc..6aab2d2ddd 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 @@ -11,27 +11,27 @@ test(`Should return 11 when given an ace card`, () => { // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) -test(`Should return the correct value for number cards (2-10)`), () => { +test(`Should return the correct value for number cards (2-10)`, () => { expect(getCardValue("2♠")).toEqual(2); expect(getCardValue("5♠")).toEqual(5); expect(getCardValue("10♠")).toEqual(10); -} +}) // Face Cards (J, Q, K) -test(`Should return 10 when given a face card (J, Q, K)`), () => { +test(`Should return 10 when given a face card (J, Q, K)`, () => { expect(getCardValue("J♠")).toEqual(10); expect(getCardValue("Q♠")).toEqual(10); expect(getCardValue("K♠")).toEqual(10); -} +}) // Invalid Card suits -test(`Should throw an error when given an invalid card suit`), () => { +test(`Should throw an error when given an invalid card suit`, () => { expect(() => getCardValue("3-")).toThrow("Invalid card rank"); - expect(() => getCardValue("5X")).toThrow("Invalid card suit"); + expect(() => getCardValue("5X")).toThrow("Invalid card suit")}); // Invalid Card ranks -test(`Should throw an error when given an invalid card rank`), () => { +test(`Should throw an error when given an invalid card rank`, () => { expect(() => getCardValue("1♠")).toThrow("Invalid card rank"); expect(() => getCardValue("11♠")).toThrow("Invalid card rank"); -} +}) // To learn how to test whether a function throws an error as expected in Jest, // please refer to the Jest documentation: From 5237b54d96983e3e9f797684adb61e7a0c47f118 Mon Sep 17 00:00:00 2001 From: Ebrahim_Moqbel Date: Sat, 14 Mar 2026 13:13:18 +0000 Subject: [PATCH 6/7] I catagrised the error messages and made them consistent --- .../3-get-card-value.test.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) 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 6aab2d2ddd..6e653c6025 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 @@ -22,15 +22,11 @@ test(`Should return 10 when given a face card (J, Q, K)`, () => { expect(getCardValue("Q♠")).toEqual(10); expect(getCardValue("K♠")).toEqual(10); }) -// Invalid Card suits -test(`Should throw an error when given an invalid card suit`, () => { - expect(() => getCardValue("3-")).toThrow("Invalid card rank"); - expect(() => getCardValue("5X")).toThrow("Invalid card suit")}); - -// Invalid Card ranks -test(`Should throw an error when given an invalid card rank`, () => { - expect(() => getCardValue("1♠")).toThrow("Invalid card rank"); - expect(() => getCardValue("11♠")).toThrow("Invalid card rank"); +// Invalid Cards +test(`Should throw an error when given an invalid card`, () => { + expect(() => getCardValue("5X")).toThrow("Invalid card ")}); //invalid suit + expect(() => getCardValue("1♠")).toThrow("Invalid card "); //invalid rank + expect(() => getCardValue("3")).toThrow("Invalid card "); //missing suit }) // To learn how to test whether a function throws an error as expected in Jest, From e75c8ba78909a5742da801af122de3b4bc7efb85 Mon Sep 17 00:00:00 2001 From: Ebrahim_Moqbel Date: Sat, 14 Mar 2026 13:24:58 +0000 Subject: [PATCH 7/7] matched the Error messages in the test cases with the function error message --- .../1-implement-and-rewrite-tests/implement/3-get-card-value.js | 2 +- 1 file changed, 1 insertion(+), 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 09997555ab..71638593dc 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 @@ -40,7 +40,7 @@ function getCardValue(card) { } if (!["♠", "♥", "♦", "♣"].includes(cardFace)) { } - throw new Error(`Invalid card rank: ${rank}`); + throw new Error(`Invalid card`); }