From 6998ca15ba557f0df49b2734358fa503c3759649 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Sun, 15 Mar 2026 23:32:28 +0000 Subject: [PATCH 01/11] Add tests and handle invalid angle cases in getAngleType --- .../implement/1-get-angle-type.js | 37 ++++++++++++++++++- 1 file changed, 36 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 9e05a871e2..0d8ccb4d2f 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,9 +15,23 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (angle <= 0 || angle >= 360) { + return "Invalid angle"; + } else 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"; + } } +// TODO: Implement this function + // The line below allows us to load the getAngleType function into tests in other files. // This will be useful in the "rewrite tests with jest" step. module.exports = getAngleType; @@ -35,3 +49,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(200); +assertEquals(Reflex, "Reflex angle"); + +const invalid1 = getAngleType(0); +assertEquals(invalid1, "Invalid angle"); + +const invalid2 = getAngleType(360); +assertEquals(invalid2, "Invalid angle"); + +const invalid3 = getAngleType(-10); +assertEquals(invalid3, "Invalid angle"); From 29b6533d5e9568d1f7ae7e98ceaf54704489eb68 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Sun, 15 Mar 2026 23:46:43 +0000 Subject: [PATCH 02/11] Implement isProperFraction with full test coverage --- .../implement/2-is-proper-fraction.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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..20f7628377 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,8 +11,13 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + if (Math.abs(numerator) < Math.abs(denominator)) { + return true; + } else { + return false; + } } +// 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. @@ -31,3 +36,13 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +assertEquals(isProperFraction(3, 2), false); + +assertEquals(isProperFraction(2, 2), false); + +assertEquals(isProperFraction(-1, 2), true); + +assertEquals(isProperFraction(1, -2), true); + +assertEquals(isProperFraction(-1, -2), true); From 29da7a4795c94b807a69edccf4fb0930dd0fbb0d Mon Sep 17 00:00:00 2001 From: khalidbih Date: Sun, 15 Mar 2026 23:58:13 +0000 Subject: [PATCH 03/11] Implement getCardValue with tests for all card ranks --- .../implement/3-get-card-value.js | 17 ++++++++++++++++- 1 file changed, 16 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 c7559e787e..4ad66936fa 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,8 +22,16 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + const rank = card.slice(0, -1); + + if (rank === "A") return 11; + if (["K", "Q", "J", "10"].includes(rank)) return 10; + if (["2", "3", "4", "5", "6", "7", "8", "9"].includes(rank)) + return Number(rank); + + throw new Error("invalid card rank."); } +// 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. @@ -40,6 +48,11 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("A♣"), 11); +assertEquals(getCardValue("J♥"), 10); +assertEquals(getCardValue("Q♦"), 10); +assertEquals(getCardValue("K♠"), 10); +assertEquals(getCardValue("10♣"), 10); // Handling invalid cards try { @@ -50,3 +63,5 @@ try { } catch (e) {} // What other invalid card cases can you think of? +assertEquals(getCardValue("2♦"), 2); +assertEquals(getCardValue("5♥"), 5); From 2973a055331bf7651458635bea180510268066e8 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Mon, 16 Mar 2026 00:31:55 +0000 Subject: [PATCH 04/11] Add Jest tests for getAngleType --- .../1-get-angle-type.test.js | 23 +++++++++++++++++++ 1 file changed, 23 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 d777f348d3..8f9cd50970 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,30 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when angle is exactly 90`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { + 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 is exactly 180`, () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); // Case 5: Reflex angles +test(`should return "Reflex angle" when (180 < angle < 360)`, () => { + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(200)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test(`should return "Invalid angle" for invalid angles`, () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(-10)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(400)).toEqual("Invalid angle"); +}); From 8a0a7c334a6bf9acb0b2338cada83b88154e0698 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Mon, 16 Mar 2026 00:44:52 +0000 Subject: [PATCH 05/11] Add Jest tests for isProperFraction covering all combinations --- .../2-is-proper-fraction.test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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..185efc13b0 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 @@ -8,3 +8,21 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); +test("should return false when numerator is greater than denominator", () => { + expect(isProperFraction(5, 2)).toEqual(false); +}); +test("should return true when absolute numerator is less than absolute denominator", () => { + expect(isProperFraction(-4, 7)).toEqual(true); +}); +test("should return false when numerator equals denominator", () => { + expect(isProperFraction(3, 3)).toEqual(false); +}); +test("should return true when numerator < |denominator| and denominator is negative", () => { + expect(isProperFraction(4, -7)).toEqual(true); +}); +test("should return true when numerator and denominator are both negative and |numerator| < |denominator|", () => { + expect(isProperFraction(-4, -7)).toEqual(true); +}); +test("should return true when numerator is zero and denominator is negative", () => { + expect(isProperFraction(0, -5)).toEqual(true); +}); From f0b9120f72b8e9ddefd5c744d02ec31b5a2311d0 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Mon, 16 Mar 2026 00:48:14 +0000 Subject: [PATCH 06/11] Add Jest tests for isProperFraction covering all combinations --- .../rewrite-tests-with-jest/2-is-proper-fraction.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 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 185efc13b0..23ea627b4a 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 @@ -17,10 +17,10 @@ test("should return true when absolute numerator is less than absolute denominat test("should return false when numerator equals denominator", () => { expect(isProperFraction(3, 3)).toEqual(false); }); -test("should return true when numerator < |denominator| and denominator is negative", () => { +test("should return true when numerator < denominator and denominator is negative", () => { expect(isProperFraction(4, -7)).toEqual(true); }); -test("should return true when numerator and denominator are both negative and |numerator| < |denominator|", () => { +test("should return true when numerator and denominator are both negative and numerator < denominator", () => { expect(isProperFraction(-4, -7)).toEqual(true); }); test("should return true when numerator is zero and denominator is negative", () => { From 4483f9349af94aed7f227dd1e32af2a7580a0788 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Mon, 16 Mar 2026 00:57:56 +0000 Subject: [PATCH 07/11] Add Jest tests for getCardValue including ace, number, face, and invalid cards --- .../3-get-card-value.test.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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..9307ace429 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 @@ -13,8 +13,20 @@ test(`Should return 11 when given an ace card`, () => { // Number Cards (2-10) // Face Cards (J, Q, K) // Invalid Cards +test("should return the value of number cards", () => { + expect(getCardValue("2♣")).toEqual(2); + expect(getCardValue("5♠")).toEqual(5); + expect(getCardValue("10♦")).toEqual(10); +}); +test("should return 10 for face cards", () => { + expect(getCardValue("J♣")).toEqual(10); + expect(getCardValue("Q♥")).toEqual(10); + expect(getCardValue("K♠")).toEqual(10); +}); +test("should throw an error for invalid card", () => { + expect(() => getCardValue("1♣")).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: // https://jestjs.io/docs/expect#tothrowerror - From 05dc806057744cf3f96c9bc7d844b0574a35c8e3 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Mon, 16 Mar 2026 22:13:19 +0000 Subject: [PATCH 08/11] Validate card suit in getCardValue according to spec --- .../implement/3-get-card-value.js | 16 ++++++++++++++-- 1 file changed, 14 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 4ad66936fa..2243ec891d 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,10 +23,17 @@ function getCardValue(card) { const rank = card.slice(0, -1); + const suit = card.slice(-1); + + const validSuits = ["♠", "♥", "♦", "♣"]; + + if (!validSuits.includes(suit)) { + throw new Error("invalid card suit."); + } if (rank === "A") return 11; - if (["K", "Q", "J", "10"].includes(rank)) return 10; - if (["2", "3", "4", "5", "6", "7", "8", "9"].includes(rank)) + if (["K", "Q", "J"].includes(rank)) return 10; + if (["2", "3", "4", "5", "6", "7", "8", "9", "10"].includes(rank)) return Number(rank); throw new Error("invalid card rank."); @@ -62,6 +69,11 @@ try { console.error("Error was not thrown for invalid card"); } catch (e) {} +try { + getCardValue("A?"); + console.error("Error was not thrown for invalid suit"); +} catch (e) {} + // What other invalid card cases can you think of? assertEquals(getCardValue("2♦"), 2); assertEquals(getCardValue("5♥"), 5); From a01738fdd8c6eff6a811d72cf67add6fd9ec2c48 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Tue, 17 Mar 2026 00:49:10 +0000 Subject: [PATCH 09/11] Updated the test description --- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 2 +- 1 file changed, 1 insertion(+), 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 8f9cd50970..00a2f411e2 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 @@ -35,7 +35,7 @@ test(`should return "Reflex angle" when (180 < angle < 360)`, () => { }); // Case 6: Invalid angles -test(`should return "Invalid angle" for invalid angles`, () => { +test(`should return "Invalid angle" when angle <= 0 or angle >= 360`, () => { expect(getAngleType(0)).toEqual("Invalid angle"); expect(getAngleType(-10)).toEqual("Invalid angle"); expect(getAngleType(360)).toEqual("Invalid angle"); From d3eb33d92d76e15f0f485eb1586b07d09dbb3079 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Tue, 17 Mar 2026 01:02:37 +0000 Subject: [PATCH 10/11] Updated the test description --- .../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 23ea627b4a..e89b0ff498 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,7 +11,7 @@ test(`should return false when denominator is zero`, () => { test("should return false when numerator is greater than denominator", () => { expect(isProperFraction(5, 2)).toEqual(false); }); -test("should return true when absolute numerator is less than absolute denominator", () => { +test("should return true when |numerator| < |denominator|", () => { expect(isProperFraction(-4, 7)).toEqual(true); }); test("should return false when numerator equals denominator", () => { From 57c5bab987f29db8c756f2f611da2057b32cbac2 Mon Sep 17 00:00:00 2001 From: khalidbih Date: Tue, 17 Mar 2026 01:30:18 +0000 Subject: [PATCH 11/11] Add tests for all invalid card cases invalid suit, missing suit, empty string --- .../rewrite-tests-with-jest/3-get-card-value.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 9307ace429..cecf895e96 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 @@ -23,10 +23,12 @@ test("should return 10 for face cards", () => { expect(getCardValue("Q♥")).toEqual(10); expect(getCardValue("K♠")).toEqual(10); }); -test("should throw an error for invalid card", () => { +test("should throw an error for invalid cards", () => { expect(() => getCardValue("1♣")).toThrow("invalid card rank."); + expect(() => getCardValue("AX")).toThrow(); + expect(() => getCardValue("K")).toThrow(); + expect(() => getCardValue("")).toThrow(); }); - // 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