From 394a8dc41376dd6397cb1b7f70f082c2c9e55b58 Mon Sep 17 00:00:00 2001 From: abmhts Date: Tue, 6 Oct 2026 17:26:57 +0100 Subject: [PATCH 01/12] angle type node:test --- .../1-get-angle-type.test.js | 22 ++++++++++++++++++- .../implement/1-get-angle-type.js | 13 ++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) 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..55f0c7993 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 @@ -6,7 +6,27 @@ import { getAngleType } from "../implement/1-get-angle-type.js"; // TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles -test("Classifies right angles", () => { +test("Classifies for exactly 90°", () => { const right = getAngleType(90); assert.equal(right, "Right angle"); }); +test("Classifies for angles greater than 0° and less than 90°", () => { + const acute = getAngleType(89); + assert.equal(acute, "Acute angle"); +}); +test("Classifies for angles greater than 90° and less than 180°", () => { + const obtuse = getAngleType(179); + assert.equal(obtuse, "Obtuse angle"); +}); +test("Classifies for exactly 180°", () => { + const straight = getAngleType(180); + assert.equal(straight, "Straight angle"); +}); +test("Classifies for angles greater than 180° and less than 360°", () => { + const reflex = getAngleType(359); + assert.equal(reflex, "Reflex angle"); +}); +test("Classifies for angles outside the valid range.", () => { + const invalid = getAngleType(361); + assert.equal(invalid, "Invalid angle"); +}); 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..aab300e3e 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,16 @@ // execute the code to ensure all tests pass. export 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"; + } + return "Invalid angle"; } From 0bc3787c353ca1449b72cc55410259c13ca35c8d Mon Sep 17 00:00:00 2001 From: abmhts Date: Tue, 6 Oct 2026 18:29:47 +0100 Subject: [PATCH 02/12] proper fraction node:test --- .../2-is-proper-fraction.test.js | 6 ++++++ .../implement/2-is-proper-fraction.js | 5 +++++ 2 files changed, 11 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..496bdc6b6 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,9 @@ test("Basic proper fraction", () => { // Example: 1/2 is a proper fraction assert.equal(isProperFraction(1, 2), true); }); +test("Basic proper fraction", () => { + assert.equal(isProperFraction(2, 1), false); +}); +test("Basic proper fraction", () => { + assert.equal(isProperFraction(1, 1), false); +}); 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..41fe92857 100644 --- a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -15,4 +15,9 @@ export function isProperFraction(numerator, denominator) { // TODO: Implement this function + if (numerator < denominator) { + return true; + } else { + return false; + } } From 42a359a53bcb97cdfea2d4579b55399ad2afd188 Mon Sep 17 00:00:00 2001 From: abmhts Date: Wed, 7 Oct 2026 10:13:49 +0100 Subject: [PATCH 03/12] get card value node:test --- .../3-get-card-value.test.js | 39 ++++++++++++++++++- .../implement/3-get-card-value.js | 19 ++++++++- 2 files changed, 55 insertions(+), 3 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..65dd92692 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,43 @@ test("Valid single-digit card", () => { assert.equal(getCardValue("9♠"), 9); }); +test("When the card is an ace (A), the function should return 11", () => { + assert.equal(getCardValue("A♠"), 11); + assert.equal(getCardValue("A♥"), 11); + assert.equal(getCardValue("A♦"), 11); + assert.equal(getCardValue("A♣"), 11); +}); +test("When the card is a face card (J, Q, K), the function should return 10", () => { + assert.equal(getCardValue("J♠"), 10); + assert.equal(getCardValue("Q♥"), 10); + assert.equal(getCardValue("K♦"), 10); +}); +test("When the card is a number card (2 to 10), the function should return its numeric value", () => { + assert.equal(getCardValue("2♠"), 2); + assert.equal(getCardValue("3♥"), 3); + assert.equal(getCardValue("4♦"), 4); + assert.equal(getCardValue("5♣"), 5); + assert.equal(getCardValue("6♠"), 6); + assert.equal(getCardValue("7♥"), 7); + assert.equal(getCardValue("8♦"), 8); + assert.equal(getCardValue("9♣"), 9); + assert.equal(getCardValue("10♠"), 10); +}); test("Arbitrary non-card string", () => { - assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error"); + assert.throws( + () => getCardValue("invalid"), + /Expected a number followed by a suit, but got "invalid"/, + "Expected clear error" + ); }); - // TODO: What other invalid card cases can you think of? + +test("Invalid card cases", () => { + assert.throws(() => getCardValue("1♠")); + assert.throws(() => getCardValue("11♠")); + assert.throws(() => getCardValue("X♠")); + assert.throws(() => getCardValue("A")); + assert.throws(() => getCardValue("2")); + assert.throws(() => getCardValue("2X")); + assert.throws(() => getCardValue("")); +}); 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..b9e5797b0 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,22 @@ // execute the code to ensure all tests pass. export function getCardValue(card) { - // TODO: Implement this function + const suit = card.slice(-1); + if (!["♠", "♥", "♦", "♣"].includes(suit)) { + throw new Error(`Expected a number followed by a suit, but got "${card}"`); + } + if (card.slice(0, -1) === "A") { + return 11; + } + if (card === "9♠") { + return 9; + } else if (card === "J♠" || card === "Q♥" || card === "K♦") { + return 10; + } else if ( + Number(card.slice(0, -1) >= 2 && Number(card.slice(0, -1) <= 10)) + ) { + return Number(card.slice(0, -1)); + } else { + throw new Error(`Expected a number followed by a suit, but got "${card}"`); + } } From 9cfaca3cae687abca6b3baeb0db8a6003e6e7c85 Mon Sep 17 00:00:00 2001 From: abmhts Date: Wed, 7 Oct 2026 11:40:49 +0100 Subject: [PATCH 04/12] get angle type - jest --- .../1-get-angle-type.test.js | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 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..4d9a4b8f7 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 @@ -7,12 +7,30 @@ import { getAngleType } from "../implement/1-get-angle-type.js"; 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 (angle > 90 && angle < 180)`, () => { + expect(getAngleType(179)).toEqual("Obtuse angle"); + expect(getAngleType(91)).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 (angle > 180 && angle < 360)`, () => { + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); // Case 6: Invalid angles +test(`should return angles outside the valid range.)`, () => { + expect(getAngleType(361)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(-1)).toEqual("Invalid angle"); + expect(getAngleType(0)).toEqual("Invalid angle"); +}); From 28b890881a6d37214ee9d2b99a518265163b2700 Mon Sep 17 00:00:00 2001 From: abmhts Date: Wed, 7 Oct 2026 12:40:44 +0100 Subject: [PATCH 05/12] proper fraction - jest --- .../2-is-proper-fraction.test.js | 15 +++++++++++++++ 1 file changed, 15 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..52e51ef9e 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,18 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js"; test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); +test(`should return false when numerator is (-)`, () => { + expect(isProperFraction(0, -1)).toEqual(false); +}); +test(`should return false when denominator is (-1)`, () => { + expect(isProperFraction(1, -1)).toEqual(false); +}); +test(`should return false when both denominator & numerator are zero`, () => { + expect(isProperFraction(0, 0)).toEqual(false); +}); +test(`should return false when both numerator is (-)`, () => { + expect(isProperFraction(-3, -6)).toEqual(false); +}); +test(`should return false when numerator is (-)`, () => { + expect(isProperFraction(-1, 0)).toEqual(true); +}); From 0deca0304c01e68a80f9b5cba678d8de7ec52b05 Mon Sep 17 00:00:00 2001 From: abmhts Date: Wed, 7 Oct 2026 13:15:51 +0100 Subject: [PATCH 06/12] get value - jest --- .../3-get-card-value.test.js | 29 ++++++++++++++++++- 1 file changed, 28 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..c7615ad48 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,37 @@ 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 its numeric value When the card is a number card ("2" to "10")`, () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("3♣")).toEqual(3); + expect(getCardValue("4♦")).toEqual(4); + expect(getCardValue("5♠")).toEqual(5); + expect(getCardValue("6♣")).toEqual(6); + expect(getCardValue("7♦")).toEqual(7); + expect(getCardValue("8♠")).toEqual(8); + expect(getCardValue("9♣")).toEqual(9); +}); + // Face Cards (J, Q, K) + +test("When the card is a face card (J, Q, K), the function should return 10", () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♥")).toEqual(10); + expect(getCardValue("K♦")).toEqual(10); +}); + // Invalid Cards +test("Invalid card cases", () => { + expect(() => getCardValue("1♠")).toThrow(); + expect(() => getCardValue("11♠")).toThrow(); + expect(() => getCardValue("X♠")).toThrow(); + expect(() => getCardValue("A")).toThrow(); + expect(() => getCardValue("2")).toThrow(); + expect(() => getCardValue("2X")).toThrow(); + expect(() => getCardValue("")).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 - From 1ea9237a5f73abf01857ef53cbe15a9b33b2f443 Mon Sep 17 00:00:00 2001 From: abmhts Date: Sat, 10 Oct 2026 14:32:42 +0100 Subject: [PATCH 07/12] =?UTF-8?q?Added=20the=20lower=20boundary=20=20(exac?= =?UTF-8?q?tly=200=C2=B0)=20and=20upper=20boundary=20(exactly=20360=C2=B0)?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1-get-angle-type.test.js | 8 ++++++++ 1 file changed, 8 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 55f0c7993..2876e31ee 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 @@ -30,3 +30,11 @@ test("Classifies for angles outside the valid range.", () => { const invalid = getAngleType(361); assert.equal(invalid, "Invalid angle"); }); +test("Classifies for exactly 0° (lower boundary)", () => { + const invalid = getAngleType(0); + assert.equal(invalid, "Invalid angle"); +}); +test("Classifies for exactly 360° (upper boundary)", () => { + const invalid = getAngleType(360); + assert.equal(invalid, "Invalid angle"); +}); From 0f3d125a38b8f2489ecc1723f19aedca50942f2d Mon Sep 17 00:00:00 2001 From: abmhts Date: Sat, 10 Oct 2026 15:03:29 +0100 Subject: [PATCH 08/12] added Math.abs --- 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 41fe92857..965d3e04f 100644 --- a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -15,7 +15,7 @@ export function isProperFraction(numerator, denominator) { // TODO: Implement this function - if (numerator < denominator) { + if (Math.abs(numerator) < Math.abs(denominator)) { return true; } else { return false; From c2b0ef2f2c31c40957a9aa503a9a9bc75bf5b91e Mon Sep 17 00:00:00 2001 From: abmhts Date: Sat, 10 Oct 2026 15:04:07 +0100 Subject: [PATCH 09/12] Included negatives and zeros. --- .../2-is-proper-fraction.test.js | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) 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 496bdc6b6..03b075ee8 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,9 +10,51 @@ test("Basic proper fraction", () => { // Example: 1/2 is a proper fraction assert.equal(isProperFraction(1, 2), true); }); -test("Basic proper fraction", () => { +// improper fraction +test("numerator larger than denominator", () => { assert.equal(isProperFraction(2, 1), false); }); -test("Basic proper fraction", () => { +test("numerator equal to denominator", () => { assert.equal(isProperFraction(1, 1), false); }); +// negative numerator +test("negative numerator, positive denominator, proper", () => { + assert.equal(isProperFraction(-1, 2), true); +}); +test("negative numerator, positive denominator, improper", () => { + assert.equal(isProperFraction(-3, 2), false); +}); +// negative denominator +test("positive numerator, negative denominator, proper", () => { + assert.equal(isProperFraction(1, -2), true); +}); +test("positive numerator, negative denominator, improper", () => { + assert.equal(isProperFraction(3, -2), false); +}); +// both negative +test("both negative, proper", () => { + assert.equal(isProperFraction(-1, -2), true); +}); +test("both negative, improper", () => { + assert.equal(isProperFraction(-3, -2), false); +}); +test("both negative, equal", () => { + assert.equal(isProperFraction(-2, -2), false); +}); +// zero numerator +test("zero numerator, positive denominator", () => { + assert.equal(isProperFraction(0, 5), true); +}); +test("zero numerator, negative denominator", () => { + assert.equal(isProperFraction(0, -5), true); +}); +// zero denominator +test("zero denominator, positive numerator", () => { + assert.equal(isProperFraction(5, 0), false); +}); +test("zero denominator, negative numerator", () => { + assert.equal(isProperFraction(-5, 0), false); +}); +test("zero numerator and zero denominator", () => { + assert.equal(isProperFraction(0, 0), false); +}); From 677e1679321e7a0f0803b2e9717bf704f72f3e10 Mon Sep 17 00:00:00 2001 From: abmhts Date: Sat, 10 Oct 2026 15:30:48 +0100 Subject: [PATCH 10/12] update - proper fraction test.jest --- .../2-is-proper-fraction.test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 52e51ef9e..69c76ecb5 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,18 +6,18 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js"; test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); -test(`should return false when numerator is (-)`, () => { - expect(isProperFraction(0, -1)).toEqual(false); +test(`should return true when numerator is zero and denominator is negative`, () => { + expect(isProperFraction(0, -1)).toEqual(true); }); -test(`should return false when denominator is (-1)`, () => { +test(`should return false when numerator and denominator are equal in size and denominator is negative`, () => { expect(isProperFraction(1, -1)).toEqual(false); }); test(`should return false when both denominator & numerator are zero`, () => { expect(isProperFraction(0, 0)).toEqual(false); }); -test(`should return false when both numerator is (-)`, () => { - expect(isProperFraction(-3, -6)).toEqual(false); +test(`should return true when both are negative and numerator is smaller in size`, () => { + expect(isProperFraction(-3, -6)).toEqual(true); }); -test(`should return false when numerator is (-)`, () => { - expect(isProperFraction(-1, 0)).toEqual(true); +test("should return false when denominator is 0 and numerator is negative", () => { + expect(isProperFraction(-1, 0)).toEqual(false); }); From 7c3ddb9e8c2cf30860905f31257375c884b093a0 Mon Sep 17 00:00:00 2001 From: abmhts Date: Sat, 10 Oct 2026 15:50:10 +0100 Subject: [PATCH 11/12] update2 --- .../2-is-proper-fraction.test.js | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) 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 69c76ecb5..ef6323b4e 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 @@ -3,21 +3,41 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js"; // 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 zero and denominator is positive", () => { + expect(isProperFraction(0, 5)).toEqual(true); }); test(`should return true when numerator is zero and denominator is negative`, () => { expect(isProperFraction(0, -1)).toEqual(true); }); +// Special case: denominator is zero +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(1, 0)).toEqual(false); +}); +test("should return false when denominator is 0 and numerator is negative", () => { + expect(isProperFraction(-1, 0)).toEqual(false); +}); +// Special case: Positive numerator, negative denominator test(`should return false when numerator and denominator are equal in size and denominator is negative`, () => { expect(isProperFraction(1, -1)).toEqual(false); }); +test("should return true when numerator is positive, denominator is negative and numerator is smaller in size", () => { + expect(isProperFraction(1, -2)).toEqual(true); + }); + // Special case: Both zero test(`should return false when both denominator & numerator are zero`, () => { expect(isProperFraction(0, 0)).toEqual(false); }); +// Special case:Negative numerator, negative denominator test(`should return true when both are negative and numerator is smaller in size`, () => { expect(isProperFraction(-3, -6)).toEqual(true); }); -test("should return false when denominator is 0 and numerator is negative", () => { - expect(isProperFraction(-1, 0)).toEqual(false); +test("should return false when both are negative and numerator is larger in size", () => { + expect(isProperFraction(-6, -3)).toEqual(false); +}); +// Special case:Negative numerator, positive denominator +test("should return true when numerator is negative, denominator is positive and numerator is smaller in size", () => { + expect(isProperFraction(-1, 2)).toEqual(true); +}); +test("should return false when numerator is negative, denominator is positive and numerator is larger in size", () => { + expect(isProperFraction(-3, 2)).toEqual(false); }); From 4ae76756303e459afe3228935586743910838c73 Mon Sep 17 00:00:00 2001 From: abmhts Date: Sat, 10 Oct 2026 21:35:21 +0100 Subject: [PATCH 12/12] Refactor - to handle all valid cards and reject invalid ones --- .../implement/3-get-card-value.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 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 b9e5797b0..9a510a4cc 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -24,22 +24,24 @@ // execute the code to ensure all tests pass. export function getCardValue(card) { + const rank = card.slice(0, -1); const suit = card.slice(-1); - if (!["♠", "♥", "♦", "♣"].includes(suit)) { - throw new Error(`Expected a number followed by a suit, but got "${card}"`); + + const validSuits = ["♠", "♥", "♦", "♣"]; + const numberRanks = ["2", "3", "4", "5", "6", "7", "8", "9", "10"]; + const faceRanks = ["J", "Q", "K"]; + + if (!validSuits.includes(suit)) { + throw new Error(`Expected a rank followed by a suit, but got "${card}"`); } - if (card.slice(0, -1) === "A") { + + if (rank === "A") { return 11; - } - if (card === "9♠") { - return 9; - } else if (card === "J♠" || card === "Q♥" || card === "K♦") { + } else if (faceRanks.includes(rank)) { return 10; - } else if ( - Number(card.slice(0, -1) >= 2 && Number(card.slice(0, -1) <= 10)) - ) { - return Number(card.slice(0, -1)); - } else { - throw new Error(`Expected a number followed by a suit, but got "${card}"`); + } else if (numberRanks.includes(rank)) { + return Number(rank); } + + throw new Error(`Expected a rank followed by a suit, but got "${card}"`); }