From f8c8ca14780bf3ebf1f5bd0fe873ec0eedfcd9ac Mon Sep 17 00:00:00 2001 From: Gideon Defar Date: Fri, 31 Jul 2026 16:28:09 +0100 Subject: [PATCH 1/3] Implement angle type function and tests --- .../implement/1-get-angle-type.js | 55 +++++++++++++++++-- 1 file changed, 51 insertions(+), 4 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..fb7645b2ee 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,28 @@ // 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. // This will be useful in the "rewrite tests with jest" step. module.exports = getAngleType; @@ -33,5 +52,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"); + + +// Acute angles +assertEquals(getAngleType(1), "Acute angle"); +assertEquals(getAngleType(45), "Acute angle"); +assertEquals(getAngleType(89), "Acute angle"); + +// Right angle +assertEquals(getAngleType(90), "Right angle"); + +// Obtuse angles +assertEquals(getAngleType(91), "Obtuse angle"); +assertEquals(getAngleType(135), "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(-1), "Invalid angle"); +assertEquals(getAngleType(360), "Invalid angle"); +assertEquals(getAngleType(400), "Invalid angle"); \ No newline at end of file From 4b8bce64f967754b4228dc7301f977fd4fda1b7f Mon Sep 17 00:00:00 2001 From: Gideon Defar Date: Fri, 31 Jul 2026 16:38:07 +0100 Subject: [PATCH 2/3] Implement proper fraction function and tests --- .../implement/2-is-proper-fraction.js | 19 ++++++++++++++++++- 1 file changed, 18 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..d516817a04 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,7 +11,7 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + return Math.abs(numerator) < Math.abs(denominator); } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +31,20 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +assertEquals(isProperFraction(3, 4), true); +assertEquals(isProperFraction(-1, 2), true); + +// Equal numerator and denominator +assertEquals(isProperFraction(2, 2), false); + +// Improper fractions +assertEquals(isProperFraction(3, 2), false); +assertEquals(isProperFraction(5, 3), false); +assertEquals(isProperFraction(-3, 2), false); + +// Zero numerator +assertEquals(isProperFraction(0, 2), true); + +// Negative denominator +assertEquals(isProperFraction(1, -2), true); \ No newline at end of file From 165158f9b4f5365963cfe451eeadb7e754e2f0b5 Mon Sep 17 00:00:00 2001 From: Gideon Defar Date: Fri, 31 Jul 2026 16:46:04 +0100 Subject: [PATCH 3/3] Implement card value function and tests --- .../implement/3-get-card-value.js | 85 ++++++++++++++++++- 1 file changed, 84 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 ff5c532e1d..66647c2597 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,7 +22,39 @@ // 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", + ]; + + 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 (["J", "Q", "K"].includes(rank)) { + return 10; + } + + return Number(rank); } // The line below allows us to load the getCardValue function into tests in other files. @@ -39,7 +71,21 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: +// assertEquals(getCardValue("9♠"), 9); +// Number cards +assertEquals(getCardValue("2♠"), 2); +assertEquals(getCardValue("5♥"), 5); assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("10♦"), 10); + +// Ace +assertEquals(getCardValue("A♠"), 11); +assertEquals(getCardValue("A♥"), 11); + +// Face cards +assertEquals(getCardValue("J♣"), 10); +assertEquals(getCardValue("Q♦"), 10); +assertEquals(getCardValue("K♠"), 10); // Handling invalid cards try { @@ -52,3 +98,40 @@ try { } // What other invalid card cases can you think of? + + +// Invalid cards +try { + getCardValue("invalid"); + console.error("Error was not thrown for invalid card"); +} catch (e) { + console.log("Error thrown for invalid card"); +} + +try { + getCardValue("1♠"); + console.error("Error was not thrown for invalid rank"); +} catch (e) { + console.log("Error thrown for invalid rank"); +} + +try { + getCardValue("A"); + console.error("Error was not thrown for missing suit"); +} catch (e) { + console.log("Error thrown for missing suit"); +} + +try { + getCardValue("A♥♥"); + console.error("Error was not thrown for invalid card format"); +} catch (e) { + console.log("Error thrown for invalid card format"); +} + +try { + getCardValue("11♠"); + console.error("Error was not thrown for invalid number card"); +} catch (e) { + console.log("Error thrown for invalid number card"); +} \ No newline at end of file