From 5291d315f3eedd2274ac7e6ac111fa43d8864eff Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Thu, 2 Jul 2026 02:37:11 +0100 Subject: [PATCH 1/7] Implement getAngleType function to classify angles --- .../implement/1-get-angle-type.js | 32 ++++++++++++++++++- 1 file changed, 31 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..267b6f4d16 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,21 @@ 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(270); +assertEquals(reflex, "Reflex angle"); + +const invalidNegative = getAngleType(-10); +assertEquals(invalidNegative, "Invalid angle"); + +const invalidOver360 = getAngleType(400); +assertEquals(invalidOver360, "Invalid angle"); From 799a9c34bff74e535fc8a826e2db60cdade883ae Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Thu, 2 Jul 2026 02:56:03 +0100 Subject: [PATCH 2/7] Implement isProperFraction function and add test cases --- .../implement/2-is-proper-fraction.js | 10 +++++++++- 1 file changed, 9 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..ab5522f7e4 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,10 @@ // 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. @@ -31,3 +34,8 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(3, 1), false); +assertEquals(isProperFraction(1, 0), false); +assertEquals(isProperFraction(-1, 2), true); +assertEquals(isProperFraction(1, -2), true); +assertEquals(isProperFraction(-3, -1), false); From 39fcce838040c6753afeea7c3982488aa0141e51 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Thu, 2 Jul 2026 03:10:44 +0100 Subject: [PATCH 3/7] Implement getCardValue function to return numerical value of playing cards --- .../implement/3-get-card-value.js | 30 ++++++++++++++++++- 1 file changed, 29 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..d8c1da885f 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,35 @@ // 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", + ]; + // The suit is always the last character + 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; + } else if ((rank === "J", rank === "Q", rank === "K")) { + return 10; + } else { + return Number(rank); + } } // The line below allows us to load the getCardValue function into tests in other files. From d6dd1e0165b754393147750687ee2532f7383723 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Thu, 2 Jul 2026 03:24:45 +0100 Subject: [PATCH 4/7] Fix getCardValue function logic and add tests for invalid card cases --- .../implement/3-get-card-value.js | 44 ++++++++++++++++++- 1 file changed, 43 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 d8c1da885f..47578a1669 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 @@ -46,7 +46,7 @@ function getCardValue(card) { } if (rank === "A") { return 11; - } else if ((rank === "J", rank === "Q", rank === "K")) { + } else if (rank === "J" || rank === "Q" || rank === "K") { return 10; } else { return Number(rank); @@ -67,7 +67,18 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: +// Number cards assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("2♥"), 2); +assertEquals(getCardValue("10♦"), 10); + +// Ace +assertEquals(getCardValue("A♠"), 11); + +// Face cards +assertEquals(getCardValue("J♣"), 10); +assertEquals(getCardValue("Q♦"), 10); +assertEquals(getCardValue("K♥"), 10); // Handling invalid cards try { @@ -80,3 +91,34 @@ try { } // What other invalid card cases can you think of? + +try { + getCardValue("1♠"); // "1" isn't a valid rank + console.error("Error was not thrown for invalid rank 😢"); +} catch (e) { + console.log("Error thrown for invalid rank 🎉"); +} + +// Invalid suit +try { + getCardValue("9♦️"); // wrong/extra character in suit + console.error("Error was not thrown for invalid suit 😢"); +} catch (e) { + console.log("Error thrown for invalid suit 🎉"); +} + +// Completely invalid string +try { + getCardValue("invalid"); + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +// Empty string +try { + getCardValue(""); + console.error("Error was not thrown for empty string 😢"); +} catch (e) { + console.log("Error thrown for empty string 🎉"); +} From 6563959bffa0c45e43a8a5553ff7adafbae9bf21 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Fri, 3 Jul 2026 09:08:54 +0100 Subject: [PATCH 5/7] Add comprehensive tests for getAngleType function covering all angle types and invalid cases --- .../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 d777f348d3..f746a7f6a5 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(135)).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" for out-of-range or non-numeric values', () => { + expect(getAngleType(-10)).toEqual("Invalid angle"); + expect(getAngleType(400)).toEqual("Invalid angle"); + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType("abc")).toEqual("Invalid angle"); + expect(getAngleType(undefined)).toEqual("Invalid angle"); +}); From f0af80de685bc03086238ef330ce9be98a12dde9 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Fri, 3 Jul 2026 09:20:16 +0100 Subject: [PATCH 6/7] Add comprehensive tests for isProperFraction function covering edge cases and various scenarios --- .../2-is-proper-fraction.test.js | 34 +++++++++++++++++++ 1 file changed, 34 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..e5df5f0927 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,37 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); +// Special case: numerator is zero +test("should return false when denominator is zero", () => { + expect(isProperFraction(1, 0)).toEqual(false); +}); + +// Positive proper fractions +test("should return true for positive proper fractions", () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(3, 4)).toEqual(true); +}); + +// Positive improper fractions +test("should return false for positive improper fractions", () => { + expect(isProperFraction(5, 2)).toEqual(false); + expect(isProperFraction(4, 4)).toEqual(false); // equal numerator/denominator +}); + +// Negative numbers +test("should handle negative numerators and denominators", () => { + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(1, -2)).toEqual(true); + expect(isProperFraction(-3, -4)).toEqual(true); + expect(isProperFraction(-5, 2)).toEqual(false); +}); + +// Numerator is zero +test("should return true when numerator is zero and denominator is non-zero", () => { + expect(isProperFraction(0, 5)).toEqual(true); +}); + +// Both zero +test("should return false when both numerator and denominator are zero", () => { + expect(isProperFraction(0, 0)).toEqual(false); +}); From 8a9d777a9e75a9d226ac1ba23a0c45723056baef Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Fri, 3 Jul 2026 09:24:20 +0100 Subject: [PATCH 7/7] Refactor tests for getCardValue function to improve structure and clarity --- .../3-get-card-value.test.js | 21 +++++++++++++++++-- 1 file changed, 19 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..9a61a7fdef 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 @@ -5,16 +5,33 @@ const getCardValue = require("../implement/3-get-card-value"); // TODO: Write tests in Jest syntax to cover all possible outcomes. // Case 1: Ace (A) -test(`Should return 11 when given an ace card`, () => { +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) +test("should return correct value for number cards", () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("5♥")).toEqual(5); + 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 cards", () => { + expect(() => getCardValue("1♠")).toThrow(); + expect(() => getCardValue("Z♣")).toThrow(); + expect(() => getCardValue("A")).toThrow(); // missing suit + expect(() => getCardValue("")).toThrow(); // empty string +}); // 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 -