From 282f3345f72aebf10aa60fb37baf8ce9b835f26a Mon Sep 17 00:00:00 2001 From: Niangh Ciang Date: Thu, 25 Jun 2026 20:28:25 +0100 Subject: [PATCH 1/7] Implement a function getAngleType --- .../implement/1-get-angle-type.js | 29 ++++++++++++++++++- 1 file changed, 28 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..6e01ccbd3b 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,19 @@ // execute the code to ensure all tests pass. 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. @@ -35,3 +47,18 @@ 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(95); +assertEquals(obtuse, "Obtuse angle"); + +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +const reflex = getAngleType(185); +assertEquals(reflex, "Reflex angle"); + +const invalid = getAngleType(-1); +assertEquals(invalid, "Invalid angle"); From 7bfaafdb7c478670c7b16915f42b9ed88321e8ae Mon Sep 17 00:00:00 2001 From: Niangh Ciang Date: Thu, 25 Jun 2026 20:58:12 +0100 Subject: [PATCH 2/7] Implement a function isProperFraction --- .../implement/2-is-proper-fraction.js | 12 +++++++++++- 1 file changed, 11 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..f8681587bc 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,11 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + if (numerator > 0 && denominator > 0 && numerator < denominator) { + return true; + } else { + return false; + } } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +35,9 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(5, 10), true); +assertEquals(isProperFraction(2, 3), true); +assertEquals(isProperFraction(-2, 4), false); +assertEquals(isProperFraction(4, 4), false); +assertEquals(isProperFraction(2, -5), false); +assertEquals(isProperFraction(0, 2), false); From 71c043e03e3a180d8a984dc5a473f822c0918476 Mon Sep 17 00:00:00 2001 From: Niangh Ciang Date: Thu, 25 Jun 2026 22:14:05 +0100 Subject: [PATCH 3/7] Implement a function getCardValue --- .../implement/3-get-card-value.js | 48 ++++++++++++++++++- 1 file changed, 47 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..5a8712219f 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,23 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + const suit = card[card.length - 1]; + const rank = card.slice(0, card.length - 1); + const numericValue = Number(rank); + + const validSuits = ["♠", "♥", "♦", "♣"]; + + if (!validSuits.includes(suit)) { + throw new Error("Invalid card"); + } else if (rank === "A") { + return 11; + } else if (rank === "J" || rank === "Q" || rank === "K") { + return 10; + } else if (numericValue >= 2 && numericValue <= 10) { + return numericValue; + } else { + throw new Error("Invalid card"); + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -40,6 +56,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("A♣"), 11); +assertEquals(getCardValue("J♦"), 10); +assertEquals(getCardValue("10♥"), 10); +assertEquals(getCardValue("Q♦"), 10); +assertEquals(getCardValue("K♦"), 10); +assertEquals(getCardValue("2♥"), 2); // Handling invalid cards try { @@ -52,3 +74,27 @@ try { } // What other invalid card cases can you think of? +try { + getCardValue("1♠"); + console.error("Error was not thrown for invalid card 😢"); +} catch { + console.log("Error thrown for invalid card 🎉"); +} +try { + getCardValue("10X"); + console.error("Error was not thrown for invalid card 😢"); +} catch { + console.log("Error thrown for invalid card 🎉"); +} +try { + getCardValue("♠A"); + console.error("Error was not thrown for invalid card 😢"); +} catch { + console.log("Error thrown for invalid card 🎉"); +} +try { + getCardValue("10♠♠"); + console.error("Error was not thrown for invalid card 😢"); +} catch { + console.log("Error thrown for invalid card 🎉"); +} From 410f4c9d00b02e5430324c53f0b8c5b7401f815e Mon Sep 17 00:00:00 2001 From: Niangh Ciang Date: Thu, 25 Jun 2026 22:37:21 +0100 Subject: [PATCH 4/7] Install Jest in Sprint-3 --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0657e22dd8..5ebcdf7334 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "keywords": [], "author": "Code Your Future", "license": "ISC", - "dependencies": { - "jest": "^29.7.0" + "devDependencies": { + "jest": "^30.4.2" } -} \ No newline at end of file +} From 5fe1f76602f9c86af9dc6b59f059ecd793058e9a Mon Sep 17 00:00:00 2001 From: Niangh Ciang Date: Thu, 25 Jun 2026 22:59:11 +0100 Subject: [PATCH 5/7] Complete Jest tests for getAngleType --- .../1-get-angle-type.test.js | 22 +++++++++++++++++++ 1 file changed, 22 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..8bb92b2eeb 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,29 @@ 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(250)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); // Case 6: Invalid angles +test('should return "Invalid angle" for invalid angles', () => { + expect(getAngleType(-1)).toEqual("Invalid angle"); + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(999)).toEqual("Invalid angle"); +}); From 281357c6ad59f4566dc98d5a29c5b6b2b2ae267d Mon Sep 17 00:00:00 2001 From: Niangh Ciang Date: Thu, 25 Jun 2026 23:26:10 +0100 Subject: [PATCH 6/7] Complete Jest test suite for isProperFraction --- .../2-is-proper-fraction.test.js | 22 +++++++++++++++++++ 1 file changed, 22 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..7b7cb3f279 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,25 @@ 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 denominator is smaller`, () => { + expect(isProperFraction(4, 2)).toEqual(false); +}); +test("should return true when numerator < denominator and both positive", () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(3, 5)).toEqual(true); +}); +test("should return false when numerator is negative", () => { + expect(isProperFraction(-2, 5)).toEqual(false); +}); +test("should return false when denominator is negative", () => { + expect(isProperFraction(2, -5)).toEqual(false); +}); +test("should return false when numerator is greater than denominator", () => { + expect(isProperFraction(4, 2)).toEqual(false); +}); +test("should return false when numerator is zero", () => { + expect(isProperFraction(0, 5)).toEqual(false); +}); +test("should return false when numerator equals denominator", () => { + expect(isProperFraction(4, 4)).toEqual(false); +}); From 4beee730c169f19efefcaaed44783e2872bccc0c Mon Sep 17 00:00:00 2001 From: Niangh Ciang Date: Thu, 25 Jun 2026 23:39:00 +0100 Subject: [PATCH 7/7] Complete Jest test suite for getCardValue --- .../3-get-card-value.test.js | 20 +++++++++++++++++-- 1 file changed, 18 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 cf7f9dae2e..dc36fc9ee5 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 @@ -11,10 +11,26 @@ test(`Should return 11 when given an ace card`, () => { // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) +test("Should return correct value for number cards", () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("7♦")).toEqual(7); + 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 cards", () => { + expect(() => getCardValue("1♠")).toThrow(); + expect(() => getCardValue("11♦")).toThrow(); + expect(() => getCardValue("A?")).toThrow(); + expect(() => getCardValue("♠A")).toThrow(); + expect(() => getCardValue("")).toThrow(); + expect(() => getCardValue("10♠♠")).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 -