From 6c22f9ec06833e050ffeb00c2d02d588dd352967 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Thu, 8 Oct 2026 15:19:24 +0100 Subject: [PATCH 01/16] Implement getAngleType function --- .../implement/1-get-angle-type.js | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/implement/1-get-angle-type.js b/implement-and-rewrite-tests/implement/1-get-angle-type.js index 8a6fba050..a2e2cb7d2 100644 --- a/implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -17,5 +17,25 @@ // execute the code to ensure all tests pass. export function getAngleType(angle) { - // TODO: Implement this function + if (angle <= 0 || angle >= 360) { + return "Invalid angle"; + } + + if (angle < 90) { + return "Acute angle"; + } + + if (angle === 90) { + return "Right angle"; + } + + if (angle < 180) { + return "Obtuse angle"; + } + + if (angle === 180) { + return "Straight angle"; + } + + return "Reflex angle"; } From eb772742bb9007752dc4272742760891dbd1b7b7 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Thu, 8 Oct 2026 15:35:38 +0100 Subject: [PATCH 02/16] Implement tests for multiple cases --- .../1-get-angle-type.test.js | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index cf50f6cad..9a8b2a805 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -10,3 +10,43 @@ test("Classifies right angles", () => { const right = getAngleType(90); assert.equal(right, "Right angle"); }); + +test("Returns invalid angle for less than 0", () => { + const negative = getAngleType(-10); + assert.equal(negative, "Invalid angle"); +}); + +test("Returns invalid angle for 0", () => { + const angle0 = getAngleType(-10); + assert.equal(angle0, "Invalid angle"); +}); + +test("Returns invalid angle for greater than 360", () => { + const greater360 = getAngleType(450); + assert.equal(greater360, "Invalid angle"); +}); + +test("Returns invalid angle for 360", () => { + const angle360 = getAngleType(360); + assert.equal(angle360, "Invalid angle"); +}); + +test("Classifies acute angles", () => { + const acute = getAngleType(34); + assert.equal(acute, "Acute angle"); +}); + +test("Classifies obtuse angles", () => { + const obtuse = getAngleType(125); + assert.equal(obtuse, "Obtuse angle"); +}); + +test("Classifies straight angles", () => { + const straight = getAngleType(180); + assert.equal(straight, "Straight angle"); +}); + +test("Classifies reflex angles", () => { + const reflex = getAngleType(260); + assert.equal(reflex, "Reflex angle"); +}); From ccba93fb9a1f6ebc966113dce90dc9207ec681e6 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Thu, 8 Oct 2026 15:39:55 +0100 Subject: [PATCH 03/16] Implement isProperFraction function --- implement-and-rewrite-tests/implement/2-is-proper-fraction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js index f983800f0..0b4a4d686 100644 --- a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -14,5 +14,5 @@ // execute the code to ensure all tests pass. export function isProperFraction(numerator, denominator) { - // TODO: Implement this function + return numerator < denominator; } From 5dafd1c26e7edcdaa3145b64000046e15aee4b1b Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Thu, 8 Oct 2026 15:46:46 +0100 Subject: [PATCH 04/16] Update function to use absolute values to account for negative numbers --- implement-and-rewrite-tests/implement/2-is-proper-fraction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 0b4a4d686..91194267d 100644 --- a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -14,5 +14,5 @@ // execute the code to ensure all tests pass. export function isProperFraction(numerator, denominator) { - return numerator < denominator; + return Math.abs(numerator) < Math.abs(denominator); } From c1141162929f9e9c3b236a18eba5246d1c7f3ce1 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Thu, 8 Oct 2026 16:00:40 +0100 Subject: [PATCH 05/16] Implement tests for multiple cases --- .../2-is-proper-fraction.test.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js index a29084605..2da0de3c5 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js @@ -10,3 +10,35 @@ test("Basic proper fraction", () => { // Example: 1/2 is a proper fraction assert.equal(isProperFraction(1, 2), true); }); + +test("Basic improper fraction", () => { + assert.equal(isProperFraction(3, 2), false); +}); + +test("equal numerator and denominator", () => { + assert.equal(isProperFraction(5, 5), false); +}); + +test("negative numerator proper fraction", () => { + assert.equal(isProperFraction(-1, 2), true); +}); + +test("negative denominator proper fraction", () => { + assert.equal(isProperFraction(1, -2), true); +}); + +test("negative denominator and negative numerator proper fraction", () => { + assert.equal(isProperFraction(-1, -2), true); +}); + +test("negative numerator improper fraction", () => { + assert.equal(isProperFraction(-3, 2), false); +}); + +test("negative denominator improper fraction", () => { + assert.equal(isProperFraction(3, -2), false); +}); + +test("negative denominator and negative numerator improper fraction", () => { + assert.equal(isProperFraction(-3, -2), false); +}); From f985ebf3571b9db26117e529719614f07a6031c4 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Thu, 8 Oct 2026 18:40:02 +0100 Subject: [PATCH 06/16] Implement getCardValue function --- .../implement/3-get-card-value.js | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/implement/3-get-card-value.js b/implement-and-rewrite-tests/implement/3-get-card-value.js index 9614ab1ee..553b4798b 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -24,5 +24,32 @@ // execute the code to ensure all tests pass. export function getCardValue(card) { - // TODO: Implement this function + if ( + card.at(-1) !== "♠" && + card.at(-1) !== "♥" && + card.at(-1) !== "♦" && + card.at(-1) !== "♣" + ) { + throw new Error(`Expected a number followed by a suit, but got ${card}`); + } + + if (!isNaN(card.slice(0, -1))) { + if (card.slice(0, -1) >= 2 && card.slice(0, -1) <= 10) { + return Number(card.slice(0, -1)); + } + } + + if ( + card.slice(0, 1) === "J" || + card.slice(0, 1) === "Q" || + card.slice(0, 1) === "K" + ) { + return 10; + } + + if (card.slice(0, 1) === "A") { + return 11; + } + + throw new Error(`Expected a number followed by a suit, but got ${card}`); } From 04ad78b2618892bd28477f23766c65695ee8f4e8 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Fri, 9 Oct 2026 17:08:21 +0100 Subject: [PATCH 07/16] Change how suits and rank validated --- .../implement/3-get-card-value.js | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/implement-and-rewrite-tests/implement/3-get-card-value.js b/implement-and-rewrite-tests/implement/3-get-card-value.js index 553b4798b..df905728f 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -24,32 +24,27 @@ // execute the code to ensure all tests pass. export function getCardValue(card) { - if ( - card.at(-1) !== "♠" && - card.at(-1) !== "♥" && - card.at(-1) !== "♦" && - card.at(-1) !== "♣" - ) { - throw new Error(`Expected a number followed by a suit, but got ${card}`); - } + const validSuits = ["♠", "♥", "♦", "♣"]; + const validNumberRanks = ["2", "3", "4", "5", "6", "7", "8", "9", "10"]; + const validFace = ["J", "Q", "K"]; + + const suit = card.at(-1); + const rank = card.slice(0, -1); - if (!isNaN(card.slice(0, -1))) { - if (card.slice(0, -1) >= 2 && card.slice(0, -1) <= 10) { - return Number(card.slice(0, -1)); - } + if (!validSuits.includes(suit)) { + throw new Error(`Expected a number followed by a suit, but got "${card}"`); + } + if (validNumberRanks.includes(rank)) { + return Number(rank); } - if ( - card.slice(0, 1) === "J" || - card.slice(0, 1) === "Q" || - card.slice(0, 1) === "K" - ) { + if (validFace.includes(rank)) { return 10; } - if (card.slice(0, 1) === "A") { + if (rank === "A") { return 11; } - throw new Error(`Expected a number followed by a suit, but got ${card}`); + throw new Error(`Expected a number followed by a suit, but got "${card}"`); } From 10548f8e8a0e128439b080a0ba07d8688241c603 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Fri, 9 Oct 2026 17:36:49 +0100 Subject: [PATCH 08/16] Implement tests --- .../3-get-card-value.test.js | 181 +++++++++++++++++- 1 file changed, 179 insertions(+), 2 deletions(-) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js index f5092d9b1..2738f6ff8 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js @@ -9,8 +9,185 @@ test("Valid single-digit card", () => { assert.equal(getCardValue("9♠"), 9); }); +test("Valid double-digit card", () => { + assert.equal(getCardValue("10♠"), 10); +}); + +test("Valid face card", () => { + assert.equal(getCardValue("J♣"), 10); +}); + +test("Valid ace card", () => { + assert.equal(getCardValue("A♦"), 11); +}); + test("Arbitrary non-card string", () => { - assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error"); + const card = "invalid"; + assert.throws( + () => getCardValue("invalid"), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); }); -// TODO: What other invalid card cases can you think of? +test("Three digit card string", () => { + const card = "125♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with leading 0", () => { + const card = "02♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with face followed by number", () => { + const card = "J2♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with number followed by face", () => { + const card = "2J♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with multiple same suit", () => { + const card = "2♦♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with multiple different suit", () => { + const card = "2♣♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with decimal number", () => { + const card = "2.5♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with negative number", () => { + const card = "-2♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with leading whitespace", () => { + const card = " 2♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with trailing whitespace", () => { + const card = "2♦ "; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with middle whitespace", () => { + const card = "2 ♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with invalid face", () => { + const card = "M♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with invalid Ace", () => { + const card = "A10♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with no suit", () => { + const card = "10"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with no rank", () => { + const card = "♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Empty String", () => { + const card = ""; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with invalid number one above max", () => { + const card = "12♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); + +test("Card with invalid number one below min", () => { + const card = "1♦"; + assert.throws( + () => getCardValue(card), + new RegExp(`Expected a number followed by a suit, but got "${card}"`), + "Expected clear error" + ); +}); From 12b0097a719cc6e4ce011e6242897f9753742169 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Sat, 10 Oct 2026 14:50:52 +0100 Subject: [PATCH 09/16] Write tests with jest --- .../1-get-angle-type.test.js | 62 +++++++++++++------ 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index e0ba786ab..e888d4ae5 100644 --- a/implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -1,18 +1,44 @@ -import { getAngleType } from "../implement/1-get-angle-type.js"; - -// TODO: Write tests in Jest syntax to cover all cases/outcomes, -// including boundary and invalid cases. - -// Case 1: Acute angles -test(`should return "Acute angle" when (0 < angle < 90)`, () => { - // Test various acute angles, including boundary cases - expect(getAngleType(1)).toEqual("Acute angle"); - expect(getAngleType(45)).toEqual("Acute angle"); - expect(getAngleType(89)).toEqual("Acute angle"); -}); - -// Case 2: Right angle -// Case 3: Obtuse angles -// Case 4: Straight angle -// Case 5: Reflex angles -// Case 6: Invalid angles +import { getAngleType } from "../implement/1-get-angle-type.js"; + +// TODO: Write tests in Jest syntax to cover all cases/outcomes, +// including boundary and invalid cases. + +// Case 1: Acute angles +test(`should return "Acute angle" when (0 < angle < 90)`, () => { + // Test various acute angles, including boundary cases + expect(getAngleType(1)).toEqual("Acute angle"); + expect(getAngleType(45)).toEqual("Acute angle"); + expect(getAngleType(89)).toEqual("Acute angle"); +}); + +// Case 2: Right angle +test(`should return "Right angle" when angle = 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 = 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 when angle <= 0, angle >= 360`, () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(-45)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(540)).toEqual("Invalid angle"); +}); From 991e7bb117b32b801ea5afa47ede499366358da4 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Sat, 10 Oct 2026 14:54:30 +0100 Subject: [PATCH 10/16] Add test with zero denominator and zero numerator --- .../2-is-proper-fraction.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js index 2da0de3c5..4593e8de8 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js @@ -42,3 +42,11 @@ test("negative denominator improper fraction", () => { test("negative denominator and negative numerator improper fraction", () => { assert.equal(isProperFraction(-3, -2), false); }); + +test("zero denominator", () => { + assert.equal(isProperFraction(3, 0), false); +}); + +test("zero numerator", () =>{ + assert.equal(isProperFraction(0,2), true); +}) \ No newline at end of file From a20fd675d4a6ec3aa2fb757e02a8cb2dc1bd65e8 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Mon, 12 Oct 2026 15:54:27 +0100 Subject: [PATCH 11/16] Write tests with jest --- .../2-is-proper-fraction.test.js | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index 5d49e2d8b..061b21c65 100644 --- a/implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -6,3 +6,80 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js"; test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +//Case 1: Basic proper fraction +test(`should return true for numerator < denominator`, () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(3, 5)).toEqual(true); + expect(isProperFraction(7, 9)).toEqual(true); + expect(isProperFraction(12, 26)).toEqual(true); +}); + +//Case 2: Basic improper fraction +test(`should return false for numerator > denominator`, () => { + expect(isProperFraction(3, 2)).toEqual(false); + expect(isProperFraction(5, 3)).toEqual(false); + expect(isProperFraction(10, 5)).toEqual(false); + expect(isProperFraction(25, 6)).toEqual(false); +}); + +//Case 3: Equal numbers +test(`should return false for numerator = denominator`, () => { + expect(isProperFraction(2, 2)).toEqual(false); + expect(isProperFraction(5, 5)).toEqual(false); + expect(isProperFraction(27, 27)).toEqual(false); + expect(isProperFraction(36, 36)).toEqual(false); +}); + +//Case 4: proper fraction negative numerator +test(`should return true for abs(numerator) < denominator`, () => { + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(-3, 5)).toEqual(true); + expect(isProperFraction(-7, 9)).toEqual(true); + expect(isProperFraction(-12, 26)).toEqual(true); +}); + +//Case 5: improper fraction negative numerator +test(`should return false for abs(numerator) > denominator`, () => { + expect(isProperFraction(-3, 2)).toEqual(false); + expect(isProperFraction(-5, 3)).toEqual(false); + expect(isProperFraction(-10, 5)).toEqual(false); + expect(isProperFraction(-25, 6)).toEqual(false); +}); + +//Case 6: proper fraction negative denominator +test(`should return true for numerator < abs(denominator)`, () => { + expect(isProperFraction(1, -2)).toEqual(true); + expect(isProperFraction(3, -5)).toEqual(true); + expect(isProperFraction(7, -9)).toEqual(true); + expect(isProperFraction(12, -26)).toEqual(true); +}); + +//Case 7: improper fraction negative denominator +test(`should return false for numerator > abs(denominator)`, () => { + expect(isProperFraction(3, -2)).toEqual(false); + expect(isProperFraction(5, -3)).toEqual(false); + expect(isProperFraction(10, -5)).toEqual(false); + expect(isProperFraction(25, -6)).toEqual(false); +}); + +//Case 8: proper fraction negative numerator and denominator +test(`should return true for abs(numerator) < abs(denominator)`, () => { + expect(isProperFraction(-1, -2)).toEqual(true); + expect(isProperFraction(-3, -5)).toEqual(true); + expect(isProperFraction(-7, -9)).toEqual(true); + expect(isProperFraction(-12, -26)).toEqual(true); +}); + +//Case 9: improper fraction negative numerator and denominator +test(`should return false for abs(numerator) > abs(denominator)`, () => { + expect(isProperFraction(-3, -2)).toEqual(false); + expect(isProperFraction(-5, -3)).toEqual(false); + expect(isProperFraction(-10, -5)).toEqual(false); + expect(isProperFraction(-25, -6)).toEqual(false); +}); + +//Case 10: zero numerator +test(`should return true for numerator = 0`, () => { + expect(isProperFraction(0, 2)).toEqual(true); +}); From a6c67edaf25c198a9e3e7b9b50339844834bb15e Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Mon, 12 Oct 2026 16:59:51 +0100 Subject: [PATCH 12/16] Edit error message --- .../3-get-card-value.test.js | 76 ++++++++++++++----- .../implement/3-get-card-value.js | 4 +- 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js index 2738f6ff8..f8be7f1b1 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js @@ -25,7 +25,9 @@ test("Arbitrary non-card string", () => { const card = "invalid"; assert.throws( () => getCardValue("invalid"), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -34,7 +36,9 @@ test("Three digit card string", () => { const card = "125♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -43,7 +47,9 @@ test("Card with leading 0", () => { const card = "02♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -52,7 +58,9 @@ test("Card with face followed by number", () => { const card = "J2♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -61,7 +69,9 @@ test("Card with number followed by face", () => { const card = "2J♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -70,7 +80,9 @@ test("Card with multiple same suit", () => { const card = "2♦♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -79,7 +91,9 @@ test("Card with multiple different suit", () => { const card = "2♣♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -88,7 +102,9 @@ test("Card with decimal number", () => { const card = "2.5♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -97,7 +113,9 @@ test("Card with negative number", () => { const card = "-2♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -106,7 +124,9 @@ test("Card with leading whitespace", () => { const card = " 2♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -115,7 +135,9 @@ test("Card with trailing whitespace", () => { const card = "2♦ "; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -124,7 +146,9 @@ test("Card with middle whitespace", () => { const card = "2 ♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -133,7 +157,9 @@ test("Card with invalid face", () => { const card = "M♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -142,7 +168,9 @@ test("Card with invalid Ace", () => { const card = "A10♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -151,7 +179,9 @@ test("Card with no suit", () => { const card = "10"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -160,7 +190,9 @@ test("Card with no rank", () => { const card = "♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -169,7 +201,9 @@ test("Empty String", () => { const card = ""; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -178,7 +212,9 @@ test("Card with invalid number one above max", () => { const card = "12♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); @@ -187,7 +223,9 @@ test("Card with invalid number one below min", () => { const card = "1♦"; assert.throws( () => getCardValue(card), - new RegExp(`Expected a number followed by a suit, but got "${card}"`), + new RegExp( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ), "Expected clear error" ); }); diff --git a/implement-and-rewrite-tests/implement/3-get-card-value.js b/implement-and-rewrite-tests/implement/3-get-card-value.js index df905728f..0fbf4700d 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -32,7 +32,7 @@ export function getCardValue(card) { const rank = card.slice(0, -1); if (!validSuits.includes(suit)) { - throw new Error(`Expected a number followed by a suit, but got "${card}"`); + throw new Error(`Invalid input. Expected a number followed by a suit, but got "${card}"`); } if (validNumberRanks.includes(rank)) { return Number(rank); @@ -46,5 +46,5 @@ export function getCardValue(card) { return 11; } - throw new Error(`Expected a number followed by a suit, but got "${card}"`); + throw new Error(`Invalid input. Expected a number followed by a suit, but got "${card}"`); } From 8e1ec5627720bee9676feb30ce88ed15e3eb8d99 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Mon, 12 Oct 2026 18:13:23 +0100 Subject: [PATCH 13/16] Write tests with jest --- .../3-get-card-value.test.js | 99 ++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index a6de5a82a..bd1e5157f 100644 --- a/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -9,10 +9,107 @@ 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 2 when given 2♠`, () => { + expect(getCardValue("2♠")).toEqual(2); +}); +test(`Should return 3 when given 3♠`, () => { + expect(getCardValue("3♠")).toEqual(3); +}); +test(`Should return 4 when given 4♠`, () => { + expect(getCardValue("4♠")).toEqual(4); +}); +test(`Should return 5 when given 5♠`, () => { + expect(getCardValue("5♠")).toEqual(5); +}); +test(`Should return 6 when given 6♠`, () => { + expect(getCardValue("6♠")).toEqual(6); +}); +test(`Should return 7 when given 7♠`, () => { + expect(getCardValue("7♠")).toEqual(7); +}); +test(`Should return 8 when given 8♠`, () => { + expect(getCardValue("8♠")).toEqual(8); +}); +test(`Should return 9 when given 9♠`, () => { + expect(getCardValue("9♠")).toEqual(9); +}); +test(`Should return 10 when given 10♠`, () => { + expect(getCardValue("10♠")).toEqual(10); +}); + // Face Cards (J, Q, K) +test(`Should return 10 when given J♣`, () => { + expect(getCardValue("J♣")).toEqual(10); +}); +test(`Should return 10 when given Q♣`, () => { + expect(getCardValue("Q♣")).toEqual(10); +}); +test(`Should return 10 when given K♣`, () => { + expect(getCardValue("K♣")).toEqual(10); +}); + // Invalid Cards +test(`Should get Invalid when given "Arbitrary non-card string"`, () => { + expect(() => getCardValue("Arbitrary non-card string")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "125♦" three digit card`, () => { + expect(() => getCardValue("125♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "02♦" card with leading 0`, () => { + expect(() => getCardValue("02♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "J2♦" card with face followed by number`, () => { + expect(() => getCardValue("J2♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "2J♦" card with number followed by a face`, () => { + expect(() => getCardValue("2J♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "2♦♦" card with two of same suits`, () => { + expect(() => getCardValue("2♦♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "2♣♦" card with two different suits`, () => { + expect(() => getCardValue("2♣♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "2.5♦" card with decimal number`, () => { + expect(() => getCardValue("2.5♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "-2♦" card with negative number`, () => { + expect(() => getCardValue("-2♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given " 2♦" card with leading whitespace`, () => { + expect(() => getCardValue(" 2♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "2♦ " card with trailing whitespace`, () => { + expect(() => getCardValue("2♦ ")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "2♦ " card with trailing whitespace`, () => { + expect(() => getCardValue("2♦ ")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "2 ♦" card with trailing whitespace`, () => { + expect(() => getCardValue("2 ♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "M♦" card with invalid face`, () => { + expect(() => getCardValue("M♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "A10♦" card with invalid Ace`, () => { + expect(() => getCardValue("A10♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "10" card with no suit`, () => { + expect(() => getCardValue("10")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "♦" card with no rank`, () => { + expect(() => getCardValue("♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "" empty string`, () => { + expect(() => getCardValue("")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "12♦" one above max number`, () => { + expect(() => getCardValue("12♦")).toThrow(/Invalid/); +}); +test(`Should get Invalid when given "1♦" one below min number`, () => { + expect(() => getCardValue("1♦")).toThrow(/Invalid/); +}); // 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 fe19a00f6d8a1c9274c923b8c6fa479476509909 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Mon, 12 Oct 2026 18:23:59 +0100 Subject: [PATCH 14/16] Formating fix --- implement-and-rewrite-tests/implement/3-get-card-value.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/implement-and-rewrite-tests/implement/3-get-card-value.js b/implement-and-rewrite-tests/implement/3-get-card-value.js index 0fbf4700d..3d26b4f85 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -32,7 +32,9 @@ export function getCardValue(card) { const rank = card.slice(0, -1); if (!validSuits.includes(suit)) { - throw new Error(`Invalid input. Expected a number followed by a suit, but got "${card}"`); + throw new Error( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ); } if (validNumberRanks.includes(rank)) { return Number(rank); @@ -46,5 +48,7 @@ export function getCardValue(card) { return 11; } - throw new Error(`Invalid input. Expected a number followed by a suit, but got "${card}"`); + throw new Error( + `Invalid input. Expected a number followed by a suit, but got "${card}"` + ); } From f3789ad8b625ef17d962bebbac05ff696a436e04 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Mon, 19 Oct 2026 14:33:07 +0100 Subject: [PATCH 15/16] Fix error message --- .../3-get-card-value.test.js | 38 +++++++++---------- .../implement/3-get-card-value.js | 4 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js index f8be7f1b1..3f3f8e66c 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js @@ -26,7 +26,7 @@ test("Arbitrary non-card string", () => { assert.throws( () => getCardValue("invalid"), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -37,7 +37,7 @@ test("Three digit card string", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -48,7 +48,7 @@ test("Card with leading 0", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -59,7 +59,7 @@ test("Card with face followed by number", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -70,7 +70,7 @@ test("Card with number followed by face", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -81,7 +81,7 @@ test("Card with multiple same suit", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -92,7 +92,7 @@ test("Card with multiple different suit", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -103,7 +103,7 @@ test("Card with decimal number", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -114,7 +114,7 @@ test("Card with negative number", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -125,7 +125,7 @@ test("Card with leading whitespace", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -136,7 +136,7 @@ test("Card with trailing whitespace", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -147,7 +147,7 @@ test("Card with middle whitespace", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -158,7 +158,7 @@ test("Card with invalid face", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -169,7 +169,7 @@ test("Card with invalid Ace", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -180,7 +180,7 @@ test("Card with no suit", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -191,7 +191,7 @@ test("Card with no rank", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -202,7 +202,7 @@ test("Empty String", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -213,7 +213,7 @@ test("Card with invalid number one above max", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); @@ -224,7 +224,7 @@ test("Card with invalid number one below min", () => { assert.throws( () => getCardValue(card), new RegExp( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ), "Expected clear error" ); diff --git a/implement-and-rewrite-tests/implement/3-get-card-value.js b/implement-and-rewrite-tests/implement/3-get-card-value.js index 3d26b4f85..ce29ee666 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -33,7 +33,7 @@ export function getCardValue(card) { if (!validSuits.includes(suit)) { throw new Error( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ); } if (validNumberRanks.includes(rank)) { @@ -49,6 +49,6 @@ export function getCardValue(card) { } throw new Error( - `Invalid input. Expected a number followed by a suit, but got "${card}"` + `Invalid input. Expected a valid rank followed by a suit, but got "${card}"` ); } From f55fcc79dc56c08113fa53bf264ccc41db84a818 Mon Sep 17 00:00:00 2001 From: Mahir Shah Date: Mon, 19 Oct 2026 14:34:03 +0100 Subject: [PATCH 16/16] Remove duplicate test --- .../rewrite-tests-with-jest/3-get-card-value.test.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index bd1e5157f..3318b263e 100644 --- a/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -82,9 +82,6 @@ test(`Should get Invalid when given " 2♦" card with leading whitespace`, () => test(`Should get Invalid when given "2♦ " card with trailing whitespace`, () => { expect(() => getCardValue("2♦ ")).toThrow(/Invalid/); }); -test(`Should get Invalid when given "2♦ " card with trailing whitespace`, () => { - expect(() => getCardValue("2♦ ")).toThrow(/Invalid/); -}); test(`Should get Invalid when given "2 ♦" card with trailing whitespace`, () => { expect(() => getCardValue("2 ♦")).toThrow(/Invalid/); });