From 698f2ba7b4301c2622a33396ae45b6d3c98a3e01 Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Wed, 7 Oct 2026 15:00:40 +0100 Subject: [PATCH 1/9] Implement a get-angle-type function --- .../implement/1-get-angle-type.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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..d9d57bdb2 100644 --- a/implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -16,6 +16,19 @@ // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. -export function getAngleType(angle) { - // TODO: Implement this function +function getAngleType(angle) { + if (angle === 90) { + return `Right angle`; + } else if (angle >= 0 && angle < 90) { + return `Acute 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`; } + +export { getAngleType }; From 898be59284398d3b51cf3e5565875e27aa279394 Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Wed, 7 Oct 2026 18:57:41 +0100 Subject: [PATCH 2/9] Write tests to cover all get-angle-type function cases --- .../1-get-angle-type.test.js | 25 +++++++++++++++++++ 1 file changed, 25 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..ff7879a45 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,28 @@ test("Classifies right angles", () => { const right = getAngleType(90); assert.equal(right, "Right angle"); }); + +test("Classifies acute angles", () => { + const acute = getAngleType(45); + assert.equal(acute, "Acute angle"); +}); + +test("Classifies obtuse angles", () => { + const obtuse = getAngleType(120); + 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(270); + assert.equal(reflex, "Reflex angle"); +}); + +test("Classifies invalid angles", () => { + const invalid = getAngleType(400); + assert.equal(invalid, "Invalid angle"); +}); From 7eba76c9df384157e93abee3e2e1c5e7abf1323e Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Wed, 7 Oct 2026 21:40:33 +0100 Subject: [PATCH 3/9] Implement is-proper-fraction function --- .../implement/2-is-proper-fraction.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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..7a2b894b1 100644 --- a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -13,6 +13,8 @@ // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. -export function isProperFraction(numerator, denominator) { - // TODO: Implement this function +function isProperFraction(numerator, denominator) { + return Math.abs(numerator) < Math.abs(denominator); } + +export { isProperFraction }; From 6033efe5a5725980904c8d88a834bbd71276ae9a Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Wed, 7 Oct 2026 22:48:15 +0100 Subject: [PATCH 4/9] Write tests to cover all proper-fraction-function cases --- .../2-is-proper-fraction.test.js | 28 +++++++++++++++++++ 1 file changed, 28 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..4f1f4a323 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,31 @@ test("Basic proper fraction", () => { // Example: 1/2 is a proper fraction assert.equal(isProperFraction(1, 2), true); }); + +test("Improper fraction where numerator is bigger than denominator", () => { + assert.equal(isProperFraction(3, 2), false); +}); + +test("Proper fraction with negative denominator", () => { + assert.equal(isProperFraction(1, -2), true); +}); + +test("Proper fraction with negative numerator", () => { + assert.equal(isProperFraction(-2, 4), true); +}); + +test("Proper fraction with both negatives where numerator is smaller", () => { + assert.equal(isProperFraction(-2, -4), true); +}); + +test("Proper fraction with both negatives where numerator is bigger", () => { + assert.equal(isProperFraction(-3, -2), false); +}); + +test("Improper fraction with equal values", () => { + assert.equal(isProperFraction(2, 2), false); +}); + +test("Proper fraction with zero numerator", () => { + assert.equal(isProperFraction(0, 4), true); +}); From 5ec0fc99fad48a77047715c999c4fde79281d26c Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Thu, 8 Oct 2026 10:27:59 +0100 Subject: [PATCH 5/9] Implement a get-card-value function --- .../implement/3-get-card-value.js | 28 +++++++++++++++++-- 1 file changed, 26 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 9614ab1ee..d072db14c 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -23,6 +23,30 @@ // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. -export function getCardValue(card) { - // TODO: Implement this function +function getCardValue(card) { + const cardRank = card.slice(0, -1); + + if (cardRank == "A") { + return 11; + } + if (cardRank == "J" || cardRank == "K" || cardRank == "Q") { + return 10; + } + if ( + cardRank == "2" || + cardRank == "3" || + cardRank == "4" || + cardRank == "5" || + cardRank == "6" || + cardRank == "7" || + cardRank == "8" || + cardRank == "9" || + cardRank == "10" + ) { + return Number(cardRank); + } else { + return "invalid"; + } } + +console.log(getCardValue("A♠")); From a7a2c63101c08ee9b1faa18114b1e83b7a48c30f Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Thu, 8 Oct 2026 21:04:24 +0100 Subject: [PATCH 6/9] Write a few tests and fix the code to add correct error messages --- .../3-get-card-value.test.js | 18 +++++++++++++++++- .../implement/3-get-card-value.js | 13 +++++++++++-- 2 files changed, 28 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..132a5dba8 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 @@ -10,7 +10,23 @@ test("Valid single-digit card", () => { }); 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("Valid double digit card", () => { + assert.equal(getCardValue("10♠"), 10); +}); + +test("No suit symbol", () => { + assert.throws( + () => getCardValue("A"), + Error, + "Should throw an error for card without suit" + ); +}); 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 d072db14c..c092bd0c9 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -25,6 +25,15 @@ function getCardValue(card) { const cardRank = card.slice(0, -1); + const suit = card.slice(-1); + + if (cardRank === card) { + throw new Error(`Expected a number followed by a suit, but got "${card}"`); + } + + if (!["♠", "♥", "♦", "♣"].includes(suit)) { + throw new Error(`Expected a number followed by a suit, but got "${card}"`); + } if (cardRank == "A") { return 11; @@ -45,8 +54,8 @@ function getCardValue(card) { ) { return Number(cardRank); } else { - return "invalid"; + throw new Error(`Expected a number followed by a suit, but got "${card}"`); } } -console.log(getCardValue("A♠")); +export { getCardValue }; From 77f784c45908a847a1a3b4d8aa4202077f16a870 Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Fri, 9 Oct 2026 14:36:00 +0100 Subject: [PATCH 7/9] Rewrite get-angle-type test in Jest, covering all cases --- .../1-get-angle-type.test.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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..99f13e277 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 @@ -12,7 +12,28 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // 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(-1)).toEqual("Invalid angle"); + expect(getAngleType(361)).toEqual("Invalid angle"); +}); From 29c23e64391caaa65aec330e125ed9975361acfb Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Fri, 9 Oct 2026 15:14:05 +0100 Subject: [PATCH 8/9] Rewrite is-proper-fraction test in Jest, covering all cases --- .../2-is-proper-fraction.test.js | 28 +++++++++++++++++++ 1 file changed, 28 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..c513b1eed 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,31 @@ 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 true when numerator is less than denominator`, () => { + expect(isProperFraction(1, 2)).toEqual(true); +}); + +test(`should return false when numerator is more than denominator`, () => { + expect(isProperFraction(3, 2)).toEqual(false); +}); + +test(`should return true when denominator is negative`, () => { + expect(isProperFraction(1, -2)).toEqual(true); +}); + +test(`should return true when nominator is negative`, () => { + expect(isProperFraction(-2, 4)).toEqual(true); +}); + +test(`should return true with both negatives where numerator is smaller`, () => { + expect(isProperFraction(-2, -4)).toEqual(true); +}); + +test(`should return false with both negatives where numerator is bigger`, () => { + expect(isProperFraction(-3, -2)).toEqual(false); +}); + +test(`should return false with equal values`, () => { + expect(isProperFraction(2, 2)).toEqual(false); +}); From 12da92fb9979d57c19e65b3faa21702199512ca3 Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Sat, 10 Oct 2026 02:07:27 +0100 Subject: [PATCH 9/9] Rewrite get-card-value test in Jest, fix the Node test, modify the implementation --- .../3-get-card-value.test.js | 60 +++++++++++++++---- .../implement/3-get-card-value.js | 11 ++-- .../3-get-card-value.test.js | 60 +++++++++++++++++++ 3 files changed, 113 insertions(+), 18 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 132a5dba8..0b19bf29c 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 @@ -5,24 +5,38 @@ import { getCardValue } from "../implement/3-get-card-value.js"; // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. +// test("Valid single-digit card", () => { +// assert.equal(getCardValue("9♠"), 9); +// }); + +// test("Arbitrary non-card string", () => { +// assert.throws( +// () => getCardValue("invalid"), +// /Expected a number followed by a suit, but got "invalid"/ +// ); +// }); + test("Valid single-digit card", () => { - assert.equal(getCardValue("9♠"), 9); + assert.equal(getCardValue("2♠"), 2); }); - -test("Arbitrary non-card string", () => { - assert.throws( - () => getCardValue("invalid"), - /Expected a number followed by a suit, but got "invalid"/, - "Expected clear error" - ); +test("Valid double-digit card", () => { + assert.equal(getCardValue("10♥"), 10); +}); +test("Valid king card", () => { + assert.equal(getCardValue("Q♣"), 10); +}); +test("Valid queen card", () => { + assert.equal(getCardValue("K♠"), 10); +}); +test("Valid jack card", () => { + assert.equal(getCardValue("J♦"), 10); +}); +test("Valid ace card", () => { + assert.equal(getCardValue("A♠"), 11); }); // TODO: What other invalid card cases can you think of? -test("Valid double digit card", () => { - assert.equal(getCardValue("10♠"), 10); -}); - test("No suit symbol", () => { assert.throws( () => getCardValue("A"), @@ -30,3 +44,25 @@ test("No suit symbol", () => { "Should throw an error for card without suit" ); }); + +test("Invalid number", () => { + assert.throws( + () => getCardValue("0"), + Error, + "Should throw an error for card with invalid number" + ); +}); +test("Empty input", () => { + assert.throws( + () => getCardValue(""), + Error, + "Should throw an error for empty input" + ); +}); +test("Any other invalid input", () => { + assert.throws( + () => getCardValue("10♥♥"), + Error, + "Should throw an error for an invalid input" + ); +}); 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 c092bd0c9..be208eb90 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -24,15 +24,14 @@ // execute the code to ensure all tests pass. function getCardValue(card) { + if (card == "") { + throw new Error(`Missing a specific number and specific suit symbol`); + } const cardRank = card.slice(0, -1); const suit = card.slice(-1); - if (cardRank === card) { - throw new Error(`Expected a number followed by a suit, but got "${card}"`); - } - if (!["♠", "♥", "♦", "♣"].includes(suit)) { - throw new Error(`Expected a number followed by a suit, but got "${card}"`); + throw new Error(`Missing a specific suit symbol`); } if (cardRank == "A") { @@ -54,7 +53,7 @@ function getCardValue(card) { ) { return Number(cardRank); } else { - throw new Error(`Expected a number followed by a suit, but got "${card}"`); + throw new Error(`Missing a specific number and specific suit symbol`); } } 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..78d739e98 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 @@ -15,4 +15,64 @@ 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 +// -----number cards------ +test(`Should return 2 when given a 2 card`, () => { + expect(getCardValue("2♥")).toEqual(2); +}); +test(`Should return 3 when given a 3 card`, () => { + expect(getCardValue("3♣")).toEqual(3); +}); +test(`Should return 4 when given a 4 card`, () => { + expect(getCardValue("4♦")).toEqual(4); +}); +test(`Should return 5 when given a 5 card`, () => { + expect(getCardValue("5♠")).toEqual(5); +}); +test(`Should return 6 when given a 6 card`, () => { + expect(getCardValue("6♦")).toEqual(6); +}); +test(`Should return 7 when given a 7 card`, () => { + expect(getCardValue("7♥")).toEqual(7); +}); +test(`Should return 8 when given a 8 card`, () => { + expect(getCardValue("8♠")).toEqual(8); +}); +test(`Should return 9 when given a 9 card`, () => { + expect(getCardValue("9♥")).toEqual(9); +}); +test(`Should return 10 when given a 10 card`, () => { + expect(getCardValue("10♣")).toEqual(10); +}); +// -----remaining face cards----- +test(`Should return 10 when given a jack card`, () => { + expect(getCardValue("J♥")).toEqual(10); +}); +test(`Should return 10 when given a king card`, () => { + expect(getCardValue("K♣")).toEqual(10); +}); +test(`Should return 10 when given a queen card`, () => { + expect(getCardValue("Q♥")).toEqual(10); +}); +// -----invalid cards----- +test("Should throw an error for card without suit", () => { + expect(() => getCardValue("A")).toThrow("Missing a specific suit symbol"); +}); + +test("Should throw an error for card with invalid number", () => { + expect(() => getCardValue("0♥")).toThrow( + "Missing a specific number and specific suit symbol" + ); +}); + +test("Should throw an error for empty input", () => { + expect(() => getCardValue("")).toThrow( + "Missing a specific number and specific suit symbol" + ); +}); + +test("Should throw an error for an invalid input", () => { + expect(() => getCardValue("J♥♥")).toThrow( + "Missing a specific number and specific suit symbol" + ); +});