From d321c48a26597d6447a8a65cc0b76990851b07b2 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Tue, 4 Aug 2026 09:12:00 +0100 Subject: [PATCH 1/2] Implement Sprint 3 angle, fraction and card functions --- .../implement/1-get-angle-type.js | 66 ++++++++++++++++++- .../implement/2-is-proper-fraction.js | 14 +++- .../implement/3-get-card-value.js | 58 +++++++++++++++- 3 files changed, 133 insertions(+), 5 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..d6b848ab43 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,24 @@ 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. @@ -32,6 +50,48 @@ 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"); + +// Right angle +const rightAngle = getAngleType(90); +assertEquals(rightAngle, "Right angle"); + +// Acute angles +const acuteAngle = getAngleType(75); +assertEquals(acuteAngle, "Acute angle"); + +const acuteAngleBoundary = getAngleType(89); +assertEquals(acuteAngleBoundary, "Acute angle"); + +// Obtuse angles +const obtuseAngle = getAngleType(120); +assertEquals(obtuseAngle, "Obtuse angle"); + +const obtuseAngleBoundaryStart = getAngleType(91); +assertEquals(obtuseAngleBoundaryStart, "Obtuse angle"); + +const obtuseAngleBoundaryEnd = getAngleType(179); +assertEquals(obtuseAngleBoundaryEnd, "Obtuse angle"); + +// Straight angle +const straightAngle = getAngleType(180); +assertEquals(straightAngle, "Straight angle"); + +// Reflex angles +const reflexAngle = getAngleType(270); +assertEquals(reflexAngle, "Reflex angle"); + +const reflexAngleBoundary = getAngleType(359); +assertEquals(reflexAngleBoundary, "Reflex angle"); + +// Invalid angles +const invalidAngleAboveRange = getAngleType(370); +assertEquals(invalidAngleAboveRange, "Invalid angle"); + +const invalidAngleBelowRange = getAngleType(-10); +assertEquals(invalidAngleBelowRange, "Invalid angle"); + +const invalidAngleZero = getAngleType(0); +assertEquals(invalidAngleZero, "Invalid angle"); + +const invalidAngleUpperBoundary = getAngleType(360); +assertEquals(invalidAngleUpperBoundary, "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..25d70f4705 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 @@ -12,6 +12,12 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function + if(numerator < denominator){ + return true; + } + else{ + return false; + } } // The line below allows us to load the isProperFraction function into tests in other files. @@ -25,9 +31,15 @@ function assertEquals(actualOutput, targetOutput) { `Expected ${actualOutput} to equal ${targetOutput}` ); } - // TODO: Write tests to cover all cases. // What combinations of numerators and denominators should you test? // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(5, 5), false); +assertEquals(isProperFraction(2, 4), true); +assertEquals(isProperFraction(0, 9), true); +assertEquals(isProperFraction(6, 3), false); +assertEquals(isProperFraction(10,4), false); +assertEquals(isProperFraction(7,0), false); +assertEquals(isProperFraction(15,30), true); \ No newline at end of file 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..3b2cc809c1 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,6 +23,25 @@ function getCardValue(card) { // TODO: Implement this function + if(card=="A♠" || card=="A♥" || card=="A♦" || card == "A♣"){ + return 11; + } + if(card=="J♠" || card=="J♥" || card=="J♦" || card == "J♣" ){ + return 10; + } + if(card=="Q♠" || card=="Q♥" || card=="Q♦" || card == "Q♣" ){ + return 10; + } + if(card=="K♠" || card=="K♥" || card=="K♦" || card == "K♣" ){ + return 10; + } + const rank = Number(card.slice(0,-1)); + const suit = card.slice(-1); + if(rank >= 2 && rank <=10 && ["♠","♥", "♦", "♣"].includes(suit)){ + return rank; + } + throw new Error("Invalid card"); + } // The line below allows us to load the getCardValue function into tests in other files. @@ -40,6 +59,12 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("K♥"), 10); +assertEquals(getCardValue("J♣"), 10); +assertEquals(getCardValue("A♦"), 11); +assertEquals(getCardValue("Q♦"), 10); +assertEquals(getCardValue("10♠"), 10); +assertEquals(getCardValue("4♠"), 4); // Handling invalid cards try { @@ -50,5 +75,36 @@ try { } catch (e) { console.log("Error thrown for invalid card 🎉"); } - // What other invalid card cases can you think of? +try { + getCardValue("11♠"); + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} +try { + getCardValue("0"); + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} +try { + getCardValue("-8♦"); + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} +try { + getCardValue("a♣"); + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} From d077e73b6c1c7dc5480b2e8691d7eb30bdd97ec5 Mon Sep 17 00:00:00 2001 From: Maryam Janjua Date: Tue, 4 Aug 2026 09:12:31 +0100 Subject: [PATCH 2/2] Rewrite Sprint 3 tests using Jest --- .../1-get-angle-type.test.js | 33 ++++++++++++++++++- .../2-is-proper-fraction.test.js | 27 +++++++++++++-- .../3-get-card-value.test.js | 27 +++++++++++---- 3 files changed, 77 insertions(+), 10 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 d777f348d3..ad732ee00a 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 @@ -11,10 +11,41 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { expect(getAngleType(1)).toEqual("Acute angle"); expect(getAngleType(45)).toEqual("Acute angle"); expect(getAngleType(89)).toEqual("Acute angle"); + expect(getAngleType(75)).toEqual("Acute angle"); }); // Case 2: Right angle -// Case 3: Obtuse angles +test(`should return "Right angle" when (angle==90)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(90)).toEqual("Right angle"); +}); + +// Case 3: Obtuse angles +test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(120)).toEqual("Obtuse angle"); + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); + expect(getAngleType(145)).toEqual("Obtuse angle"); +}); + // Case 4: Straight angle +test(`should return "Straight angle" when (angle==180)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(180)).toEqual("Straight angle"); +}); // Case 5: Reflex angles +test(`should return "Reflex angle" when (180 < angle < 360)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(270)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); + expect(getAngleType(181)).toEqual("Reflex angle"); +}); // Case 6: Invalid angles +test("should return 'Invalid angle' for invalid angles", () => { + // Test various acute angles, including boundary cases + expect(getAngleType(-10)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(370)).toEqual("Invalid angle"); + expect(getAngleType(0)).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 7f087b2ba1..42f5f363e4 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 @@ -4,7 +4,30 @@ 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 fractions +test("should return true when numerator is less than denominator", () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(2, 4)).toEqual(true); + expect(isProperFraction(15, 30)).toEqual(true); +}); + +// Numerator is zero +test("should return true when numerator is zero", () => { + expect(isProperFraction(0, 9)).toEqual(true); +}); + +// Equal numerator and denominator +test("should return false when numerator is equal to denominator", () => { + expect(isProperFraction(5, 5)).toEqual(false); +}); + +// Numerator is greater than denominator +test("should return false when numerator is greater than denominator", () => { + expect(isProperFraction(6, 3)).toEqual(false); + expect(isProperFraction(10, 4)).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..3ab900cc3e 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,12 +9,25 @@ test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); -// Suggestion: Group the remaining test data into these categories: -// Number Cards (2-10) -// Face Cards (J, Q, K) -// Invalid Cards +// Case 2: 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); +}); -// 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 +// Case 3: Number cards (2-10) +test("should return the numeric value for number cards", () => { + expect(getCardValue("4♠")).toEqual(4); + expect(getCardValue("9♠")).toEqual(9); + expect(getCardValue("10♠")).toEqual(10); +}); +// Case 4: Invalid cards +test("should throw an error for invalid cards", () => { + expect(() => getCardValue("invalid")).toThrow(); + expect(() => getCardValue("11♠")).toThrow(); + expect(() => getCardValue("0")).toThrow(); + expect(() => getCardValue("-8♦")).toThrow(); + expect(() => getCardValue("a♣")).toThrow(); +}); \ No newline at end of file