From f545cd32b13c7d78730a89e0eb2a3f084e20c385 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 12:52:56 +0100 Subject: [PATCH 1/8] Implement getAngleType function to determine angle types --- .../implement/1-get-angle-type.js | 14 +++++++++++++- 1 file changed, 13 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..ac053af89e 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,8 +16,20 @@ 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"; + 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. // This will be useful in the "rewrite tests with jest" step. module.exports = getAngleType; From 60bae09b055eaa537e4ec1e4886c39617185ac11 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 12:54:38 +0100 Subject: [PATCH 2/8] add test to get angle --- .../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..8f9347ddcf 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 angel is >90 & <180`, () => { + expect(getAngleType(100)).toEqual("Obtuse angle"); + expect(getAngleType(95)).toEqual("Obtuse angle"); +}); // Case 4: Straight angle +test(`should return "Straight angle" when angle === 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(260)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test('should return "Invalid angle" for angles outside the valid range', () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(-10)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(500)).toEqual("Invalid angle"); +}); From 3a0e465b597f2328cd85b2665ff3345ede95f58e Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 12:56:07 +0100 Subject: [PATCH 3/8] add proper fraction test --- .../2-is-proper-fraction.test.js | 49 +++++++++++++++++++ 1 file changed, 49 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..9b78ff35bb 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,52 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); +// This statement loads the isProperFraction function you wrote in the implement directory. +// We will use the same function, but write tests for it using Jest in this file. +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`, () => { + expect(isProperFraction(1, 0)).toEqual(false); +}); +test(`should return true when numerator is less than denominator`, () => { + // Proper fractions + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(3, 4)).toEqual(true); +}); +// Improper fractions +test("should return false when numerator is greater than denominator`", () => { + expect(isPrperFraction(5, 2)).toEqual(true); + expect(isProperFraction(3, 4)).toEqual(true); +}); +// Equal numerator and denominator +test("should return false when numerator equals denominator", () => { + expect(isProperFraction(4, 4)).toEqual(false); +}); + +// Numerator is zero +test("should return true when numerator is zero and denominator is positive", () => { + expect(isProperFunction(0.5)).toEqual(true); +}); +// Denominator is zero +test("should return false when denominator is zero", () => { + expect(isProperFunction(1, 0)).toEqual(false); +}); +// Both numerator and denominator are zero +test("should return false when numerator and denominator are zero", () => { + expect(isProperFunction(0, 0)).toEqual(false); +}); +// Negative numerator +test("should return false when numerator is negative", () => { + expect(isProperFunction(-1, 6)).toEqual(false); +}); +// Negative denominator +test("should return false when denominator is negative", () => { + expect(isProperFraction(1, -5)).toEqual(false); +}); +// Both numerator and denominator are negative +test("should return false when both numerator and denominator is negative", () => { + expect(isProperFraction(-4, -5)).toEqual(false); +}); From 6c4902058156d093eaad7fc0564032edb1d5b753 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 14:30:22 +0100 Subject: [PATCH 4/8] fix errors --- .../2-is-proper-fraction.test.js | 54 ++++++------------- 1 file changed, 17 insertions(+), 37 deletions(-) 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 9b78ff35bb..6428c2b0fa 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 @@ -1,59 +1,39 @@ -// This statement loads the isProperFraction function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. 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`, () => { - expect(isProperFraction(1, 0)).toEqual(false); -}); -// This statement loads the isProperFraction function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. -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`, () => { - expect(isProperFraction(1, 0)).toEqual(false); -}); -test(`should return true when numerator is less than denominator`, () => { - // Proper fractions +test("should return true when numerator is less than denominator", () => { expect(isProperFraction(1, 2)).toEqual(true); expect(isProperFraction(3, 4)).toEqual(true); }); -// Improper fractions -test("should return false when numerator is greater than denominator`", () => { - expect(isPrperFraction(5, 2)).toEqual(true); - expect(isProperFraction(3, 4)).toEqual(true); + +test("should return false when numerator is greater than denominator", () => { + expect(isProperFraction(5, 2)).toEqual(false); + expect(isProperFraction(10, 3)).toEqual(false); }); -// Equal numerator and denominator + test("should return false when numerator equals denominator", () => { expect(isProperFraction(4, 4)).toEqual(false); }); -// Numerator is zero test("should return true when numerator is zero and denominator is positive", () => { - expect(isProperFunction(0.5)).toEqual(true); + expect(isProperFraction(0, 5)).toEqual(true); }); -// Denominator is zero + test("should return false when denominator is zero", () => { - expect(isProperFunction(1, 0)).toEqual(false); + expect(isProperFraction(1, 0)).toEqual(false); }); -// Both numerator and denominator are zero + test("should return false when numerator and denominator are zero", () => { - expect(isProperFunction(0, 0)).toEqual(false); + expect(isProperFraction(0, 0)).toEqual(false); }); -// Negative numerator -test("should return false when numerator is negative", () => { - expect(isProperFunction(-1, 6)).toEqual(false); + +test("should return true when numerator is negative and denominator is positive", () => { + expect(isProperFraction(-1, 6)).toEqual(true); }); -// Negative denominator + test("should return false when denominator is negative", () => { expect(isProperFraction(1, -5)).toEqual(false); }); -// Both numerator and denominator are negative -test("should return false when both numerator and denominator is negative", () => { + +test("should return false when both numerator and denominator are negative", () => { expect(isProperFraction(-4, -5)).toEqual(false); }); From b6f832b300ba31169a558dd32098ea37fb16ae6c Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 14:43:27 +0100 Subject: [PATCH 5/8] code implement --- .../implement/2-is-proper-fraction.js | 7 +++++++ 1 file changed, 7 insertions(+) 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..ea17aa3799 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,13 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function + if (denominator <= 0) { + return false; + } + if (numerator < 0) { + return false; + } + return numerator < denominator; } // The line below allows us to load the isProperFraction function into tests in other files. From 9de9db0f9f1c0757cb1ec6946537d5ac10048ddf Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 15:24:03 +0100 Subject: [PATCH 6/8] get card value --- .../implement/3-get-card-value.js | 52 +++++++++++++++++++ .../3-get-card-value.test.js | 22 +++++++- 2 files changed, 73 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..ba21dba0f5 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,57 @@ function getCardValue(card) { // TODO: Implement this function + const validSuits = ["♠", "♥", "♦", "♣"]; + // Get the suit (last character) and rank (everything before it) + const suit = card.slice(-1); + const rank = card.slice(0, -1); + + // Check that the suit is valid + if (!validSuits.includes(suit)) { + throw new Error("Invalid card"); + } + // Ace + if (rank === "A") { + return 11; + } + + if (rank === "J" || rank === "Q" || rank === "K") { + return 10; + } + + if ( + rank === "2" || + rank === "3" || + rank === "4" || + rank === "5" || + rank === "6" || + rank === "7" || + rank === "8" || + rank === "9" || + rank === "10" + ) { + return Number(rank); + } + + throw new Error("Invalid card"); + + { + return Number(rank); + } + + // Invalid rank + throw new Error("Invalid card"); + getCardValue("1♠"); + getCardValue("11♣"); + getCardValue("0♦"); + getCardValue("B♥"); + getCardValue("X♠"); + + //invalid suit + getCardValue("AX"); + getCardValue("5*"); + getCardValue("10H"); + getCardValue("QS"); } // The line below allows us to load the getCardValue function into tests in other files. @@ -52,3 +103,4 @@ try { } // What other invalid card cases can you think of? +//invalid rank 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..ce4fc60cf2 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 @@ -8,6 +8,27 @@ const getCardValue = require("../implement/3-get-card-value"); test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); +// Case 2: Number cards (2–10) +test("should return the value of number cards", () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("5♦")).toEqual(5); + expect(getCardValue("10♣")).toEqual(10); +}); + +// Case 3: 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); +}); + +// Case 4: Invalid cards +test("should return 0 for invalid cards", () => { + expect(getCardValue("1♠")).toEqual(0); + expect(getCardValue("11♣")).toEqual(0); + expect(getCardValue("X♦")).toEqual(0); + expect(getCardValue("")).toEqual(0); +}); // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) @@ -17,4 +38,3 @@ test(`Should return 11 when given an ace card`, () => { // 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 - From 4472fa201071aeb010d249ae55f48af583bf6589 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 16:29:31 +0100 Subject: [PATCH 7/8] fix errors --- .../implement/2-is-proper-fraction.js | 3 - .../implement/3-get-card-value.js | 64 +++++++++---------- .../3-get-card-value.test.js | 13 ++-- 3 files changed, 38 insertions(+), 42 deletions(-) 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 ea17aa3799..a0149abf6a 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 @@ -15,9 +15,6 @@ function isProperFraction(numerator, denominator) { if (denominator <= 0) { return false; } - if (numerator < 0) { - return false; - } return numerator < denominator; } 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 ba21dba0f5..5922735315 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 @@ -27,6 +27,7 @@ function getCardValue(card) { // Get the suit (last character) and rank (everything before it) const suit = card.slice(-1); const rank = card.slice(0, -1); + console.log(suit, rank); // Check that the suit is valid if (!validSuits.includes(suit)) { @@ -56,24 +57,6 @@ function getCardValue(card) { } throw new Error("Invalid card"); - - { - return Number(rank); - } - - // Invalid rank - throw new Error("Invalid card"); - getCardValue("1♠"); - getCardValue("11♣"); - getCardValue("0♦"); - getCardValue("B♥"); - getCardValue("X♠"); - - //invalid suit - getCardValue("AX"); - getCardValue("5*"); - getCardValue("10H"); - getCardValue("QS"); } // The line below allows us to load the getCardValue function into tests in other files. @@ -88,19 +71,32 @@ function assertEquals(actualOutput, targetOutput) { ); } -// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// Examples: -assertEquals(getCardValue("9♠"), 9); - -// Handling invalid cards -try { - getCardValue("invalid"); - - // 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 🎉"); -} - -// What other invalid card cases can you think of? -//invalid rank +// // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. +// // Examples: +// assertEquals(getCardValue("9♠"), 9); + +// // Handling invalid cards +// try { +// getCardValue("invalid"); + +// // 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 🎉"); +// } + +// // What other invalid card cases can you think of? +// //invalid rank +// getCardValue("1♠"); +// getCardValue("11♣"); +// getCardValue("0♦"); +// getCardValue("B♥"); +// getCardValue("X♠"); + +// //invalid suit +// getCardValue("AX"); +// getCardValue("5*"); +// getCardValue("10H"); +// getCardValue("QS"); + +getCardValue("1♠"); 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 ce4fc60cf2..3aef51be31 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 @@ -23,11 +23,14 @@ test("should return 10 for face cards", () => { }); // Case 4: Invalid cards -test("should return 0 for invalid cards", () => { - expect(getCardValue("1♠")).toEqual(0); - expect(getCardValue("11♣")).toEqual(0); - expect(getCardValue("X♦")).toEqual(0); - expect(getCardValue("")).toEqual(0); +test("should return error for invalid cards", () => { + expect(() => { + getCardValue("1♠"); + }).toThrow("Invalid card"); + // expect(getCardValue("1♠")).toEqual(0); + // expect(getCardValue("11♣")).toEqual(0); + // expect(getCardValue("X♦")).toEqual(0); + // expect(getCardValue("")).toEqual(0); }); // Suggestion: Group the remaining test data into these categories: From 142c2826f97cdbf7af7b4ba44078aa817db0924e Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 16:50:21 +0100 Subject: [PATCH 8/8] fix throw error and test --- .../implement/3-get-card-value.js | 2 -- .../3-get-card-value.test.js | 13 +++++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) 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 5922735315..c2cddf4e11 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 @@ -98,5 +98,3 @@ function assertEquals(actualOutput, targetOutput) { // getCardValue("5*"); // getCardValue("10H"); // getCardValue("QS"); - -getCardValue("1♠"); 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 3aef51be31..cfebb0bc29 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 @@ -27,10 +27,15 @@ test("should return error for invalid cards", () => { expect(() => { getCardValue("1♠"); }).toThrow("Invalid card"); - // expect(getCardValue("1♠")).toEqual(0); - // expect(getCardValue("11♣")).toEqual(0); - // expect(getCardValue("X♦")).toEqual(0); - // expect(getCardValue("")).toEqual(0); + expect(() => { + getCardValue("11♠"); + }).toThrow("Invalid card"); + expect(() => { + getCardValue("X♦"); + }).toThrow("Invalid card"); + expect(() => { + getCardValue(""); + }).toThrow("Invalid card"); }); // Suggestion: Group the remaining test data into these categories: