From 646d6a5ea9524aed0c0af8bd962cd6b27c66f141 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 28 Mar 2026 13:00:23 +0000 Subject: [PATCH 1/9] I implemented the function and the different test cases. --- .../implement/1-get-angle-type.js | 49 ++++++++++++++++++- 1 file changed, 47 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 9e05a871e..72435f851 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 @@ -15,6 +15,23 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { + 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 'Stright angle'; + } + else if (angle > 180 && angle < 360) { + return 'Reflex angle'; + } + else {return 'Invalid angle';} + // TODO: Implement this function } @@ -33,5 +50,33 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles -const right = getAngleType(90); -assertEquals(right, "Right angle"); +// const right = getAngleType(90); +// assertEquals(right, "Right angle"); +assertEquals (getAngleType(90), "Right angle"); + +// const acute = getAngleType(45); +// assertEquals(acute, "Acute angle"); +assertEquals (getAngleType(45),"Acute angle"); + +// const obtuse = getAngleType(120); +// assertEquals(obtuse, "Obtuse angle"); +assertEquals (getAngleType(120),"Obtuse angle"); + +// const stright = getAngleType(180); +// assertEquals(stright, "Stright angle"); +assertEquals (getAngleType(180),"Stright angle"); +// const reflex = getAngleType(270); +// assertEquals(reflex, "Reflex angle"); +assertEquals (getAngleType(270),"Reflex angle"); + +// const invalid = getAngleType(360); +// assertEquals(invalid, "Invalid angle"); +assertEquals (getAngleType(360),"Invalid angle"); +//Boundary cases +// const invalid = getAngleType(0); +// assertEquals(invalid, "Invalid angle"); +assertEquals (getAngleType(0),"Invalid angle"); +//Outside range +// const invalid = getAngleType(-10 , 400); +// assertEquals(invalid, "Invalid angle"); +assertEquals (getAngleType(-10 , 400),"Invalid angle"); \ No newline at end of file From bc93560fe61440e01c7d6c4bc3bb38a8bff544a4 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 28 Mar 2026 13:01:53 +0000 Subject: [PATCH 2/9] I implemented the isProperFunction and wrote different test cases for it. --- .../implement/2-is-proper-fraction.js | 20 +++++++++++++++++++ 1 file changed, 20 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 970cb9b64..59cb9dbcb 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,11 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { + if( numerator < denominator) { + return true; + } + else {return false; } + // TODO: Implement this function } @@ -31,3 +36,18 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +// inproper fraction: +assertEquals (isProperFraction(5, 3), false ); + +// equal numbers +assertEquals (isProperFraction(4, 4), false ); + +// negative numbers +assertEquals (isProperFraction(-2, 4), true ); +assertEquals (isProperFraction(5, -4), false ); +assertEquals (isProperFraction (-3,-5), false); + +// special case +assertEquals(isProperFraction(1,0) , false); + +assertEquals (isProperFraction (0,5), true); From 9f2ebc39bad7116ab8bfe1b6b884e1a83db121d0 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 28 Mar 2026 13:02:41 +0000 Subject: [PATCH 3/9] Implemented the function and wrote different test cases. --- .../implement/3-get-card-value.js | 45 ++++++++++++++++++- 1 file changed, 44 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 c7559e787..3ff425d0b 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 @@ -22,9 +22,31 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + const suit = card.slice(-1); + const rank = card.slice(0, -1); + + if (suit !== "♠" && suit !== "♥" && suit !== "♦" && suit !== "♣") { + throw new Error("Invalid card"); + } + + if (rank === "A") { + return 11; + } + + if (rank === "J" || rank === "Q" || rank === "K") { + return 10; + } + + if (rank >= "2" && rank <= "10") { + return Number(rank); + } + + throw new Error("Invalid card"); } + // TODO: Implement this function + + // 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; @@ -40,6 +62,16 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("2♠"), 2); +assertEquals(getCardValue("10♦"), 10); + +// Face cards +assertEquals(getCardValue("J♣"), 10); +assertEquals(getCardValue("Q♥"), 10); +assertEquals(getCardValue("K♦"), 10); + +// Ace +assertEquals(getCardValue("A♠"), 11); // Handling invalid cards try { @@ -49,4 +81,15 @@ try { console.error("Error was not thrown for invalid card"); } catch (e) {} + // What other invalid card cases can you think of? + +const invalidCards = ["invalid", "1♠", "B♣", "10?", "Z♠"]; +for (const card of invalidCards) { + try { + getCardValue(card); + console.error(`Error was not thrown for invalid card: ${card}`); + } catch (e) { + // Expected error, do nothing + } +} \ No newline at end of file From 8f148b8035c80a9aa6fbff1ce313f52924a0a17a Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 28 Mar 2026 13:04:43 +0000 Subject: [PATCH 4/9] I wrote different test cases for the three functions. --- .../1-get-angle-type.test.js | 28 +++++++++++++ .../2-is-proper-fraction.test.js | 41 +++++++++++++++++-- .../3-get-card-value.test.js | 27 +++++++++++- 3 files changed, 91 insertions(+), 5 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 d777f348d..d934e54d9 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,35 @@ 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)` ,() =>{ + + expect(getAngleType(95)).toEqual("Obtuse angle"); + expect(getAngleType(120)).toEqual("Obtuse angle"); + expect(getAngleType(100)).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)` ,() =>{ + + expect(getAngleType(190)).toEqual("Reflex angle"); + expect(getAngleType(300)).toEqual("Reflex angle"); + expect(getAngleType(200)).toEqual("Reflex angle"); +}); // Case 6: Invalid angles +test (`should return "Invalid angle" when (angle <= 0 or angle > 360)` ,() => { + + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(400)).toEqual("Invalid angle"); + expect(getAngleType(-10)).toEqual("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 7f087b2ba..a60b213d9 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 @@ -2,9 +2,42 @@ // We will use the same function, but write tests for it using Jest in this file. const isProperFraction = require("../implement/2-is-proper-fraction"); -// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. - -// Special case: numerator is zero -test(`should return false when denominator is zero`, () => { +// denominator is zero +test("should return false when denominator is zero", () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +// proper fraction (numerator < denominator) +test("should return true when numerator < denominator", () => { + expect(isProperFraction(1, 2)).toEqual(true); +}); + +// improper fraction (numerator > denominator) +test("should return false when numerator > denominator", () => { + expect(isProperFraction(5, 3)).toEqual(false); +}); + +// equal numbers +test("should return false when numerator === denominator", () => { + expect(isProperFraction(4, 4)).toEqual(false); +}); + +// numerator is zero +test("should return true when numerator is zero and denominator is positive", () => { + expect(isProperFraction(0, 5)).toEqual(true); +}); + +// negative numerator +test("should return false when numerator is negative", () => { + expect(isProperFraction(-2, 4)).toEqual(false); +}); + +// negative denominator +test("should return false when denominator is negative", () => { + expect(isProperFraction(5, -4)).toEqual(false); +}); + +// both negative +test("should return false when both numerator and denominator are negative", () => { + expect(isProperFraction(-3, -5)).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 cf7f9dae2..184e29fbd 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 @@ -9,6 +9,32 @@ test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); + +// Case 2: Number Cards (2–10) +test("Should return the numeric value for number cards", () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("5♥")).toEqual(5); + expect(getCardValue("9♦")).toEqual(9); + expect(getCardValue("10♣")).toEqual(10); +}); + +// Case 3: Face Cards (J, Q, K) +test("Should return 10 for face cards", () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♥")).toEqual(10); + expect(getCardValue("K♦")).toEqual(10); +}); + +// Case 4: Invalid Cards +test("Should throw an error for invalid cards", () => { + expect(() => getCardValue("1♠")).toThrowError(); + expect(() => getCardValue("B♣")).toThrowError(); + expect(() => getCardValue("10?")).toThrowError(); + expect(() => getCardValue("invalid")).toThrowError(); +}); + + + // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) // Face Cards (J, Q, K) @@ -17,4 +43,3 @@ test(`Should return 11 when given an ace card`, () => { // To learn how to test whether a function throws an error as expected in Jest, // please refer to the Jest documentation: // https://jestjs.io/docs/expect#tothrowerror - From e7d00028dc6d78980402dd7b753d6126eb0d880f Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 18 Apr 2026 11:59:02 +0100 Subject: [PATCH 5/9] I added changes to the implemented functions --- .../implement/1-get-angle-type.js | 43 +++++++++---------- .../implement/2-is-proper-fraction.js | 25 +++++------ .../implement/3-get-card-value.js | 8 ++-- 3 files changed, 36 insertions(+), 40 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 72435f851..2fd8e133e 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,21 +16,18 @@ function getAngleType(angle) { if (angle > 0 && angle < 90) { - return 'Acute angle'; + return "Acute angle"; + } else if (angle === 90) { + return "Right angle"; + } else if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } else if (angle === 180) { + return "Stright angle"; + } else if (angle > 180 && angle < 360) { + return "Reflex angle"; + } else { + return "Invalid angle"; } - else if (angle===90) { - return 'Right angle'; - } - else if ( angle > 90 && angle < 180){ - return 'Obtuse angle'; - } - else if( angle === 180) { - return 'Stright angle'; - } - else if (angle > 180 && angle < 360) { - return 'Reflex angle'; - } - else {return 'Invalid angle';} // TODO: Implement this function } @@ -52,31 +49,31 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles // const right = getAngleType(90); // assertEquals(right, "Right angle"); -assertEquals (getAngleType(90), "Right angle"); +assertEquals(getAngleType(90), "Right angle"); // const acute = getAngleType(45); // assertEquals(acute, "Acute angle"); -assertEquals (getAngleType(45),"Acute angle"); +assertEquals(getAngleType(45), "Acute angle"); // const obtuse = getAngleType(120); // assertEquals(obtuse, "Obtuse angle"); -assertEquals (getAngleType(120),"Obtuse angle"); +assertEquals(getAngleType(120), "Obtuse angle"); // const stright = getAngleType(180); // assertEquals(stright, "Stright angle"); -assertEquals (getAngleType(180),"Stright angle"); +assertEquals(getAngleType(180), "Stright angle"); // const reflex = getAngleType(270); // assertEquals(reflex, "Reflex angle"); -assertEquals (getAngleType(270),"Reflex angle"); +assertEquals(getAngleType(270), "Reflex angle"); // const invalid = getAngleType(360); // assertEquals(invalid, "Invalid angle"); -assertEquals (getAngleType(360),"Invalid angle"); +assertEquals(getAngleType(360), "Invalid angle"); //Boundary cases // const invalid = getAngleType(0); // assertEquals(invalid, "Invalid angle"); -assertEquals (getAngleType(0),"Invalid angle"); -//Outside range +assertEquals(getAngleType(0), "Invalid angle"); +//Outside range // const invalid = getAngleType(-10 , 400); // assertEquals(invalid, "Invalid angle"); -assertEquals (getAngleType(-10 , 400),"Invalid angle"); \ No newline at end of file +assertEquals(getAngleType(-10, 400), "Invalid angle"); 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 59cb9dbcb..7ec60f35c 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,14 +11,13 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - if( numerator < denominator) { - return true; - } - else {return false; } + if (denominator === 0) return false; - // TODO: Implement this function + 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. // This will be useful in the "rewrite tests with jest" step. module.exports = isProperFraction; @@ -37,17 +36,19 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); // inproper fraction: -assertEquals (isProperFraction(5, 3), false ); +assertEquals(isProperFraction(5, 3), false); // equal numbers -assertEquals (isProperFraction(4, 4), false ); +assertEquals(isProperFraction(4, 4), false); // negative numbers -assertEquals (isProperFraction(-2, 4), true ); -assertEquals (isProperFraction(5, -4), false ); -assertEquals (isProperFraction (-3,-5), false); +assertEquals(isProperFraction(-2, 4), true); +assertEquals(isProperFraction(5, -4), false); +assertEquals(isProperFraction(-3, -5), false); +assertEquals(isProperFraction(-1, 2), true); +assertEquals(isProperFraction(-1, 2), true); // special case -assertEquals(isProperFraction(1,0) , false); +assertEquals(isProperFraction(1, 0), false); -assertEquals (isProperFraction (0,5), true); +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 3ff425d0b..149f87dc4 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 @@ -37,15 +37,14 @@ function getCardValue(card) { return 10; } - if (rank >= "2" && rank <= "10") { + if (Number(rank) >= 2 && Number(rank) <= 10) { return Number(rank); } throw new Error("Invalid card"); } - // TODO: Implement this function - +// TODO: Implement this function // 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. @@ -81,7 +80,6 @@ try { console.error("Error was not thrown for invalid card"); } catch (e) {} - // What other invalid card cases can you think of? const invalidCards = ["invalid", "1♠", "B♣", "10?", "Z♠"]; @@ -92,4 +90,4 @@ for (const card of invalidCards) { } catch (e) { // Expected error, do nothing } -} \ No newline at end of file +} From bbf99ca1d387791f8ad36a36982c19d0478ea524 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 18 Apr 2026 12:03:21 +0100 Subject: [PATCH 6/9] test changes added changes to the test files --- .../1-get-angle-type.test.js | 65 +++++++++++-------- .../2-is-proper-fraction.test.js | 2 +- .../3-get-card-value.test.js | 62 +++++++++--------- 3 files changed, 69 insertions(+), 60 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 d934e54d9..a9603008c 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 @@ -6,43 +6,54 @@ const getAngleType = require("../implement/1-get-angle-type"); // including boundary and invalid cases. // Case 1: Acute angles -test(`should return "Acute angle" when (0 < angle < 90)`, () => { - // Test various acute angles, including boundary cases - expect(getAngleType(1)).toEqual("Acute angle"); - expect(getAngleType(45)).toEqual("Acute angle"); - expect(getAngleType(89)).toEqual("Acute angle"); +describe("Acute angle", () => { + test("valid acute angles", () => { + expect(getAngleType(1)).toBe("Acute angle"); + expect(getAngleType(45)).toBe("Acute angle"); + expect(getAngleType(89)).toBe("Acute angle"); + }); + + test("boundary cases are NOT acute", () => { + expect(getAngleType(0)).not.toBe("Acute angle"); + expect(getAngleType(90)).not.toBe("Acute angle"); + }); }); // Case 2: Right angle -test(`should return "Right angle" when (angle=== 90)`, () => { - expect(getAngleType(90)).toEqual("Right angle"); +describe("Right angle", () => { + test("should return 'Right angle' when angle is 90", () => { + expect(getAngleType(90)).toBe("Right angle"); + }); }); // Case 3: Obtuse angles -test (`should return "Obtuse angle" when (90 < angle < 180)` ,() =>{ - - expect(getAngleType(95)).toEqual("Obtuse angle"); - expect(getAngleType(120)).toEqual("Obtuse angle"); - expect(getAngleType(100)).toEqual("Obtuse angle"); +describe("Obtuse angle", () => { + test("should return 'Obtuse angle' when (90 < angle < 180)", () => { + expect(getAngleType(95)).toBe("Obtuse angle"); + expect(getAngleType(120)).toBe("Obtuse angle"); + expect(getAngleType(100)).toBe("Obtuse angle"); + }); }); // Case 4: Straight angle -test (`should return "Straight angle" when ( angle === 180)` ,() =>{ - - expect(getAngleType(180)).toEqual("Straight angle"); - +describe("Straight angle", () => { + test("should return 'Straight angle' when angle is 180", () => { + expect(getAngleType(180)).toBe("Straight angle"); + }); }); // Case 5: Reflex angles -test (`should return "Reflex angle" when (180 < angle < 360)` ,() =>{ - - expect(getAngleType(190)).toEqual("Reflex angle"); - expect(getAngleType(300)).toEqual("Reflex angle"); - expect(getAngleType(200)).toEqual("Reflex angle"); +describe("Reflex angle", () => { + test("should return 'Reflex angle' when (180 < angle < 360)", () => { + expect(getAngleType(190)).toBe("Reflex angle"); + expect(getAngleType(300)).toBe("Reflex angle"); + expect(getAngleType(200)).toBe("Reflex angle"); + }); }); // Case 6: Invalid angles -test (`should return "Invalid angle" when (angle <= 0 or angle > 360)` ,() => { - - expect(getAngleType(0)).toEqual("Invalid angle"); - expect(getAngleType(400)).toEqual("Invalid angle"); - expect(getAngleType(-10)).toEqual("Invalid angle"); -}); \ No newline at end of file +describe("Invalid angle", () => { + test("should return 'Invalid angle' when (angle <= 0 or angle > 360)", () => { + expect(getAngleType(0)).toBe("Invalid angle"); + expect(getAngleType(400)).toBe("Invalid angle"); + expect(getAngleType(-10)).toBe("Invalid angle"); + }); +}); 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 a60b213d9..06621497e 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 @@ -40,4 +40,4 @@ test("should return false when denominator is negative", () => { // both negative test("should return false when both numerator and denominator are negative", () => { expect(isProperFraction(-3, -5)).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 184e29fbd..06621497e 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 @@ -1,45 +1,43 @@ -// This statement loads the getCardValue function you wrote in the implement directory. +// This statement loads the isProperFraction function you wrote in the implement directory. // We will use the same function, but write tests for it using Jest in this file. -const getCardValue = require("../implement/3-get-card-value"); +const isProperFraction = require("../implement/2-is-proper-fraction"); -// TODO: Write tests in Jest syntax to cover all possible outcomes. - -// Case 1: Ace (A) -test(`Should return 11 when given an ace card`, () => { - expect(getCardValue("A♠")).toEqual(11); +// denominator is zero +test("should return false when denominator is zero", () => { + expect(isProperFraction(1, 0)).toEqual(false); }); - -// Case 2: Number Cards (2–10) -test("Should return the numeric value for number cards", () => { - expect(getCardValue("2♠")).toEqual(2); - expect(getCardValue("5♥")).toEqual(5); - expect(getCardValue("9♦")).toEqual(9); - expect(getCardValue("10♣")).toEqual(10); +// proper fraction (numerator < denominator) +test("should return true when numerator < denominator", () => { + expect(isProperFraction(1, 2)).toEqual(true); }); -// Case 3: Face Cards (J, Q, K) -test("Should return 10 for face cards", () => { - expect(getCardValue("J♠")).toEqual(10); - expect(getCardValue("Q♥")).toEqual(10); - expect(getCardValue("K♦")).toEqual(10); +// improper fraction (numerator > denominator) +test("should return false when numerator > denominator", () => { + expect(isProperFraction(5, 3)).toEqual(false); }); -// Case 4: Invalid Cards -test("Should throw an error for invalid cards", () => { - expect(() => getCardValue("1♠")).toThrowError(); - expect(() => getCardValue("B♣")).toThrowError(); - expect(() => getCardValue("10?")).toThrowError(); - expect(() => getCardValue("invalid")).toThrowError(); +// equal numbers +test("should return false when numerator === denominator", () => { + expect(isProperFraction(4, 4)).toEqual(false); }); +// numerator is zero +test("should return true when numerator is zero and denominator is positive", () => { + expect(isProperFraction(0, 5)).toEqual(true); +}); +// negative numerator +test("should return false when numerator is negative", () => { + expect(isProperFraction(-2, 4)).toEqual(false); +}); -// Suggestion: Group the remaining test data into these categories: -// Number Cards (2-10) -// Face Cards (J, Q, K) -// Invalid Cards +// negative denominator +test("should return false when denominator is negative", () => { + expect(isProperFraction(5, -4)).toEqual(false); +}); -// To learn how to test whether a function throws an error as expected in Jest, -// please refer to the Jest documentation: -// https://jestjs.io/docs/expect#tothrowerror +// both negative +test("should return false when both numerator and denominator are negative", () => { + expect(isProperFraction(-3, -5)).toEqual(false); +}); From 7b922da8a9c44e8da8318911c2ec1808cbca4af8 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 18 Apr 2026 14:00:55 +0100 Subject: [PATCH 7/9] I changed the function and the test cases --- .../implement/3-get-card-value.js | 35 ++++++---- .../3-get-card-value.test.js | 65 ++++++++++--------- 2 files changed, 57 insertions(+), 43 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 149f87dc4..b90389595 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 @@ -25,25 +25,36 @@ function getCardValue(card) { const suit = card.slice(-1); const rank = card.slice(0, -1); - if (suit !== "♠" && suit !== "♥" && suit !== "♦" && suit !== "♣") { + const validSuits = ["♠", "♥", "♦", "♣"]; + if (!validSuits.includes(suit)) { throw new Error("Invalid card"); } - if (rank === "A") { - return 11; + const validRanks = [ + "A", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "J", + "Q", + "K", + ]; + + if (!validRanks.includes(rank)) { + throw new Error("Invalid card"); } - if (rank === "J" || rank === "Q" || rank === "K") { - return 10; - } + if (rank === "A") return 11; + if (rank === "J" || rank === "Q" || rank === "K") return 10; - if (Number(rank) >= 2 && Number(rank) <= 10) { - return Number(rank); - } - - throw new Error("Invalid card"); + return Number(rank); } - // TODO: Implement this function // The line below allows us to load the getCardValue function into tests in other files. 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 06621497e..c32eca2bb 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 @@ -1,43 +1,46 @@ -// This statement loads the isProperFraction function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. -const isProperFraction = require("../implement/2-is-proper-fraction"); +const getCardValue = require("../implement/3-get-card-value"); -// denominator is zero -test("should return false when denominator is zero", () => { - expect(isProperFraction(1, 0)).toEqual(false); +// Ace +test("Should return 11 when given an ace card", () => { + expect(getCardValue("A♠")).toBe(11); }); -// proper fraction (numerator < denominator) -test("should return true when numerator < denominator", () => { - expect(isProperFraction(1, 2)).toEqual(true); +// Number cards +test("Should return the numeric value for number cards", () => { + expect(getCardValue("2♠")).toBe(2); + expect(getCardValue("5♥")).toBe(5); + expect(getCardValue("9♦")).toBe(9); + expect(getCardValue("10♣")).toBe(10); }); -// improper fraction (numerator > denominator) -test("should return false when numerator > denominator", () => { - expect(isProperFraction(5, 3)).toEqual(false); +// Face cards +test("Should return 10 for face cards", () => { + expect(getCardValue("J♠")).toBe(10); + expect(getCardValue("Q♥")).toBe(10); + expect(getCardValue("K♦")).toBe(10); }); -// equal numbers -test("should return false when numerator === denominator", () => { - expect(isProperFraction(4, 4)).toEqual(false); +// Invalid cards (basic) +test("Should throw error for invalid cards", () => { + expect(() => getCardValue("1♠")).toThrow(); + expect(() => getCardValue("B♣")).toThrow(); + expect(() => getCardValue("10?")).toThrow(); + expect(() => getCardValue("invalid")).toThrow(); }); -// numerator is zero -test("should return true when numerator is zero and denominator is positive", () => { - expect(isProperFraction(0, 5)).toEqual(true); +// Invalid numeric formats (IMPORTANT for your strict function) +test("Should throw error for malformed numeric ranks", () => { + expect(() => getCardValue("0x02♠")).toThrow(); + expect(() => getCardValue("2.1♠")).toThrow(); + expect(() => getCardValue("0002♠")).toThrow(); }); -// negative numerator -test("should return false when numerator is negative", () => { - expect(isProperFraction(-2, 4)).toEqual(false); -}); - -// negative denominator -test("should return false when denominator is negative", () => { - expect(isProperFraction(5, -4)).toEqual(false); -}); - -// both negative -test("should return false when both numerator and denominator are negative", () => { - expect(isProperFraction(-3, -5)).toEqual(false); +// Invalid structure cases +test("Should throw error for malformed card structure", () => { + expect(() => getCardValue("")).toThrow(); + expect(() => getCardValue("♠")).toThrow(); + expect(() => getCardValue("10")).toThrow(); + expect(() => getCardValue("A♠♠")).toThrow(); + expect(() => getCardValue(" 2♠")).toThrow(); + expect(() => getCardValue("2♠ ")).toThrow(); }); From 7adde95212bc02403f9ff08aad1d2e35c8863f7e Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 18 Apr 2026 14:06:52 +0100 Subject: [PATCH 8/9] I added a test for 0 and 360 angles --- .../1-implement-and-rewrite-tests/implement/1-get-angle-type.js | 2 +- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 1 + 2 files changed, 2 insertions(+), 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 2fd8e133e..f539aaca4 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,7 +22,7 @@ function getAngleType(angle) { } else if (angle > 90 && angle < 180) { return "Obtuse angle"; } else if (angle === 180) { - return "Stright angle"; + return "Straight angle"; } else if (angle > 180 && angle < 360) { return "Reflex angle"; } else { 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 a9603008c..73eccc238 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 @@ -55,5 +55,6 @@ describe("Invalid angle", () => { expect(getAngleType(0)).toBe("Invalid angle"); expect(getAngleType(400)).toBe("Invalid angle"); expect(getAngleType(-10)).toBe("Invalid angle"); + expect(getAngleType(360)).toBe("Invalid angle"); }); }); From 9d68b4e6cb71bb275f0f9df21d389f2138833170 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 18 Apr 2026 14:23:59 +0100 Subject: [PATCH 9/9] I re-edited the finction and tests to match and run the test on node and it passed --- .../implement/2-is-proper-fraction.js | 8 +++---- .../2-is-proper-fraction.test.js | 22 +++++++++---------- 2 files changed, 14 insertions(+), 16 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 7ec60f35c..22ac6ba15 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,11 +11,11 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - if (denominator === 0) return false; + if (denominator <= 0) return false; + if (numerator < 0) return false; - return Math.abs(numerator) < Math.abs(denominator); + return numerator < denominator; } - // TODO: Implement this function // The line below allows us to load the isProperFraction function into tests in other files. @@ -26,7 +26,7 @@ module.exports = isProperFraction; function assertEquals(actualOutput, targetOutput) { console.assert( actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` + `Expected ${actualOutput} toBe ${targetOutput}` ); } 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 06621497e..f044a5b94 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 @@ -1,43 +1,41 @@ -// This statement loads the isProperFraction function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. const isProperFraction = require("../implement/2-is-proper-fraction"); // denominator is zero test("should return false when denominator is zero", () => { - expect(isProperFraction(1, 0)).toEqual(false); + expect(isProperFraction(1, 0)).toBe(false); }); -// proper fraction (numerator < denominator) +// proper fraction test("should return true when numerator < denominator", () => { - expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(1, 2)).toBe(true); }); -// improper fraction (numerator > denominator) +// improper fraction test("should return false when numerator > denominator", () => { - expect(isProperFraction(5, 3)).toEqual(false); + expect(isProperFraction(5, 3)).toBe(false); }); // equal numbers test("should return false when numerator === denominator", () => { - expect(isProperFraction(4, 4)).toEqual(false); + expect(isProperFraction(4, 4)).toBe(false); }); // numerator is zero test("should return true when numerator is zero and denominator is positive", () => { - expect(isProperFraction(0, 5)).toEqual(true); + expect(isProperFraction(0, 5)).toBe(true); }); // negative numerator test("should return false when numerator is negative", () => { - expect(isProperFraction(-2, 4)).toEqual(false); + expect(isProperFraction(-2, 4)).toBe(false); }); // negative denominator test("should return false when denominator is negative", () => { - expect(isProperFraction(5, -4)).toEqual(false); + expect(isProperFraction(5, -4)).toBe(false); }); // both negative test("should return false when both numerator and denominator are negative", () => { - expect(isProperFraction(-3, -5)).toEqual(false); + expect(isProperFraction(-3, -5)).toBe(false); });