From 6613b6f2b96af20a36a79ed140bfec5fbbd816ba Mon Sep 17 00:00:00 2001 From: Laura C Date: Fri, 20 Feb 2026 15:58:09 +0000 Subject: [PATCH 1/6] Implement getAngleType and add console.assert tests --- .../implement/1-get-angle-type.js | 47 ++++++++++++++++++- 1 file changed, 46 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 9e05a871e..9aa335c33 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,7 +15,27 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (angle > 0 && angle < 90) { + return "Acute angle"; + } + + if (angle === 90) { + return "Right angle"; + } + + if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } + + if (angle === 180) { + return "Straight angle"; + } + + if (angle > 180 && angle < 360) { + return "Reflex angle"; + } + + return "Invalid angle"; } // The line below allows us to load the getAngleType function into tests in other files. @@ -35,3 +55,28 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +// Acute angles +assertEquals(getAngleType(1), "Acute angle"); +assertEquals(getAngleType(45), "Acute angle"); +assertEquals(getAngleType(89), "Acute angle"); + +// Obtuse angles +assertEquals(getAngleType(91), "Obtuse angle"); +assertEquals(getAngleType(120), "Obtuse angle"); +assertEquals(getAngleType(179), "Obtuse angle"); + +// Straight angle +assertEquals(getAngleType(180), "Straight angle"); + +// Reflex angles +assertEquals(getAngleType(181), "Reflex angle"); +assertEquals(getAngleType(270), "Reflex angle"); +assertEquals(getAngleType(359), "Reflex angle"); + +// Invalid angles +assertEquals(getAngleType(0), "Invalid angle"); +assertEquals(getAngleType(-10), "Invalid angle"); +assertEquals(getAngleType(360), "Invalid angle"); +assertEquals(getAngleType(999), "Invalid angle"); + From e2d06784220db3caa70688131c9f6e47fc6e64d2 Mon Sep 17 00:00:00 2001 From: Laura C Date: Fri, 20 Feb 2026 16:03:29 +0000 Subject: [PATCH 2/6] Implement isProperFraction and add console.assert tests --- .../implement/2-is-proper-fraction.js | 27 ++++++++++++++++++- 1 file changed, 26 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 970cb9b64..9c16a0015 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,9 +11,14 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + if (denominator === 0) { + return false; + } + + return Math.abs(numerator) < Math.abs(denominator); } + // 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; @@ -31,3 +36,23 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +// Equal numbers → will not be proper +assertEquals(isProperFraction(2, 2), false); + +// Improper fractions +assertEquals(isProperFraction(5, 4), false); +assertEquals(isProperFraction(10, 3), false); + +// Zero numerator → will be proper +assertEquals(isProperFraction(0, 5), true); + +// Negative numbers +assertEquals(isProperFraction(-1, 2), true); +assertEquals(isProperFraction(1, -2), true); +assertEquals(isProperFraction(-3, -2), false); + +// Denominator zero +assertEquals(isProperFraction(1, 0), false); +assertEquals(isProperFraction(0, 0), false); + From 63d362f17413f38400e0194ec8992baacf6440bd Mon Sep 17 00:00:00 2001 From: Laura C Date: Fri, 20 Feb 2026 16:07:27 +0000 Subject: [PATCH 3/6] Implement getCardValue and add console.assert tests --- .../implement/3-get-card-value.js | 41 ++++++++++++++++++- 1 file changed, 40 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..3209e3456 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,27 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + const validSuits = ["♠", "♥", "♦", "♣"]; + const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; + + if (typeof card !== "string" || card.length < 2) { + throw new Error("Invalid card"); + } + + const suit = card.slice(-1); + const rank = card.slice(0, -1); + + if (!validSuits.includes(suit) || !validRanks.includes(rank)) { + throw new Error("Invalid card"); + } + + if (rank === "A") return 11; + if (rank === "J" || rank === "Q" || rank === "K") return 10; + + return Number(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; @@ -50,3 +68,24 @@ try { } catch (e) {} // What other invalid card cases can you think of? +// Number cards +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); + +// More invalid cases +const invalidCards = ["", "A", "11♠", "1♠", "B♠", "10X", "♠A"]; + +for (const bad of invalidCards) { + try { + getCardValue(bad); + console.error("Error was not thrown for invalid card:", bad); + } catch (e) {} +} From 94950b805d4d321ec3b7e9d64d9c75720e6f4521 Mon Sep 17 00:00:00 2001 From: Laura C Date: Fri, 20 Feb 2026 16:16:54 +0000 Subject: [PATCH 4/6] Rewrite getAngleType tests using Jest --- .../1-get-angle-type.test.js | 27 +++++++++++++++++++ 1 file changed, 27 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 d777f348d..f94c63333 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,34 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when angle is 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 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(270)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test(`should return "Invalid angle" when angle is outside valid range`, () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(-10)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(999)).toEqual("Invalid angle"); +}); + From f08aec2f6a3bde37a777349772bbb2c792eda997 Mon Sep 17 00:00:00 2001 From: Laura C Date: Fri, 20 Feb 2026 16:22:46 +0000 Subject: [PATCH 5/6] Rewrite isProperFraction tests using Jest --- .../2-is-proper-fraction.test.js | 33 +++++++++++++++++++ 1 file changed, 33 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 7f087b2ba..4fbbdd799 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,36 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); +// Proper fractions (positive numbers +test(`should return true when numerator is smaller than denominator`, () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(3, 4)).toEqual(true); +}); + +// Equal numbers → not proper +test(`should return false when numerator equals denominator`, () => { + expect(isProperFraction(2, 2)).toEqual(false); +}); + +// Improper fractions +test(`should return false when numerator is greater than denominator`, () => { + expect(isProperFraction(5, 4)).toEqual(false); + expect(isProperFraction(10, 3)).toEqual(false); +}); + +// Zero numerator +test(`should return true when numerator is zero and denominator is non-zero`, () => { + expect(isProperFraction(0, 5)).toEqual(true); +}); + +// Negative numbers +test(`should handle negative numbers correctly`, () => { + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(1, -2)).toEqual(true); + expect(isProperFraction(-3, -2)).toEqual(false); +}); + +// Both zero +test(`should return false when both numerator and denominator are zero`, () => { + expect(isProperFraction(0, 0)).toEqual(false); +}); \ No newline at end of file From f39d27a13ef059f858e3c69fd3ae344350413283 Mon Sep 17 00:00:00 2001 From: Laura C Date: Fri, 20 Feb 2026 16:29:05 +0000 Subject: [PATCH 6/6] Rewrite getCardValue tests using Jest --- .../3-get-card-value.test.js | 24 +++++++++++++++++++ 1 file changed, 24 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 cf7f9dae2..2b5808fd3 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,30 @@ test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); +// Number Cards (2-10) +test(`Should return the correct number for number cards`, () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("9♥")).toEqual(9); + expect(getCardValue("10♦")).toEqual(10); +}); + +// 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); +}); + +// Invalid Cards +test(`Should throw an error for invalid card strings`, () => { + const invalidCards = ["", "A", "11♠", "1♠", "B♠", "10X", "♠A", "invalid"]; + + for (const badCard of invalidCards) { + expect(() => getCardValue(badCard)).toThrowError(); + } +}); + + // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) // Face Cards (J, Q, K)