From 0b66d4451c401e22df175f7836b72fe86dd265c1 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Fri, 9 Oct 2026 09:45:16 +0100 Subject: [PATCH 1/6] Implement getAngleType with node:test coverage --- .../1-get-angle-type.test.js | 29 +++++++++++++++---- .../implement/1-get-angle-type.js | 18 +++++++++--- 2 files changed, 37 insertions(+), 10 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..f2d53defc 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 @@ -1,12 +1,29 @@ +import {getAngleType} from "../implement/1-get-angle-type.js"; import assert from "node:assert"; import test from "node:test"; -import { getAngleType } from "../implement/1-get-angle-type.js"; +test("corrctly get angle type", function(){ + assert.equal(getAngleType(75), "Acute angle"); +}); -// TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles +test("corrctly get angle type", function(){ + assert.equal(getAngleType(90), "Right angle"); +}); -test("Classifies right angles", () => { - const right = getAngleType(90); - assert.equal(right, "Right angle"); +test("corrctly get angle type", function(){ + assert.equal(getAngleType(120), "Obtuse angle"); }); + +test("corrctly get angle type", function(){ + assert.equal(getAngleType(180), "Straight angle"); +}); + +test("corrctly get angle type", function(){ + assert.equal(getAngleType(210), "Reflex angle"); +}); + +test("corrctly get angle type", function(){ + assert.equal(getAngleType(400), "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..e126ea800 100644 --- a/implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -1,5 +1,17 @@ // Implement a function getAngleType -// +function getAngleType(angle) { + return angle > 0 && angle < 90 + ? "Acute angle" + : angle === 90 + ? "Right angle" + : angle > 90 && angle < 180 + ? "Obtuse angle" + : angle === 180 + ? "Straight angle" + : angle > 180 && angle < 360 + ? "Reflex angle" + : "Invalid angle"; +} // Don't forget to write tests in implement-tests-with-node-test. // // When given an angle in degrees, it should return a string indicating the type of angle: @@ -16,6 +28,4 @@ // 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 -} +export { getAngleType } From bcc603b91646eedbaac5cb93ed7135fa8de8baea Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Fri, 9 Oct 2026 11:15:13 +0100 Subject: [PATCH 2/6] Implement isProperFraction with node:test coverage --- .../2-is-proper-fraction.test.js | 26 ++++++++++++++++++- .../implement/2-is-proper-fraction.js | 10 +++++-- 2 files changed, 33 insertions(+), 3 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 a29084605..98e35b550 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 @@ -7,6 +7,30 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js"; // What combinations of numerators and denominators should you test? 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, 0), false); +}); + +test("Basic proper fraction", () => { + assert.equal(isProperFraction(0, 1), true); +}); + +test("Basic proper fraction", () => { + assert.equal(isProperFraction(1, 1), false); +}); + +test("Basic proper fraction", () => { + assert.equal(isProperFraction(-1, 2), true); +}); + + + + + 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..b8c7173b8 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,12 @@ // 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) { + if (denominator === 0) { + return false; + } + return Math.abs(numerator) < Math.abs(denominator); } + + +export { isProperFraction } From f8d6b5be260ff68e8102889e2ff179594608f82d Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Fri, 9 Oct 2026 12:48:44 +0100 Subject: [PATCH 3/6] Implement getCardValue with node:test coverage --- .../3-get-card-value.test.js | 25 ++++++++++++++- .../implement/3-get-card-value.js | 31 +++++++++++++++++-- 2 files changed, 53 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..2316f0b2a 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,31 @@ test("Valid single-digit card", () => { assert.equal(getCardValue("9♠"), 9); }); +test("Valid ten", () => { + assert.equal(getCardValue("10♥"), 10); +}); + +test("Ace returns 11", () => { + assert.equal(getCardValue("A♦"), 11); +}); + +test("Face cards return 10", () => { + assert.equal(getCardValue("J♣"), 10); + assert.equal(getCardValue("Q♠"), 10); + assert.equal(getCardValue("K♥"), 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" + ); +}); + +test("Missing suit throws", () => { + assert.throws(() => getCardValue("A"), /Expected a number followed by a suit/); }); + // TODO: What other invalid card cases can you think of? 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..a60c17103 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,33 @@ // 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 suit = card.slice(-1); + const rank = card.slice(0, -1); + const suits = ["♠", "♥", "♦", "♣"]; + const values = { + A: 11, + J: 10, + Q: 10, + K: 10, + "10": 10, + "9": 9, + "8": 8, + "7": 7, + "6": 6, + "5": 5, + "4": 4, + "3": 3, + "2": 2, + }; + + if (!suits.includes(suit) || values[rank] === undefined) { + throw new Error( + `Expected a number followed by a suit, but got "${card}"` + ); + } + + return values[rank]; } + +export { getCardValue } From f8013884556d98db75c28911ac3d769f56cc59c5 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Fri, 9 Oct 2026 13:28:37 +0100 Subject: [PATCH 4/6] Rewrite implement tests with Jest --- .../1-get-angle-type.test.js | 26 +++++++++++++++++++ .../2-is-proper-fraction.test.js | 12 +++++++++ .../3-get-card-value.test.js | 20 ++++++++++++++ 3 files changed, 58 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..222ac6ea6 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,33 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when angle is 90`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(120)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); + // Case 4: Straight angle +test(`should return "Straight angle" when angle is 180`, () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); + // Case 5: Reflex angles +test(`should return "Reflex angle" when (180 < angle < 360)`, () => { + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(270)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test(`should return "Invalid angle" for angles outside (0, 360)`, () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(-10)).toEqual("Invalid angle"); + expect(getAngleType(400)).toEqual("Invalid angle"); +}); 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..4396f081a 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,15 @@ 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 for proper fractions`, () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(0, 5)).toEqual(true); + expect(isProperFraction(-1, 2)).toEqual(true); +}); + +test(`should return false for improper fractions`, () => { + expect(isProperFraction(2, 1)).toEqual(false); + expect(isProperFraction(1, 1)).toEqual(false); + expect(isProperFraction(5, 3)).toEqual(false); +}); 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..cda2ae17d 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 @@ -16,3 +16,23 @@ test(`Should return 11 when given an ace card`, () => { // please refer to the Jest documentation: // https://jestjs.io/docs/expect#tothrowerror +test(`Should return numeric value for number cards`, () => { + expect(getCardValue("2♥")).toEqual(2); + expect(getCardValue("9♠")).toEqual(9); + expect(getCardValue("10♦")).toEqual(10); +}); + +test(`Should return 10 for face cards`, () => { + expect(getCardValue("J♣")).toEqual(10); + expect(getCardValue("Q♠")).toEqual(10); + expect(getCardValue("K♥")).toEqual(10); +}); + +test(`Should throw for invalid cards`, () => { + expect(() => getCardValue("invalid")).toThrow( + /Expected a number followed by a suit, but got "invalid"/ + ); + expect(() => getCardValue("A")).toThrow( + /Expected a number followed by a suit/ + ); +}); From 432760649a19a4342ba768fe73a20a4ecc485703 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sat, 10 Oct 2026 15:25:25 +0100 Subject: [PATCH 5/6] Address PR review: expand edge and invalid test cases --- .../1-get-angle-type.test.js | 11 ++++++ .../2-is-proper-fraction.test.js | 6 ++++ .../3-get-card-value.test.js | 35 +++++++++++++++++++ .../2-is-proper-fraction.test.js | 2 ++ .../3-get-card-value.test.js | 24 ++++++++++++- 5 files changed, 77 insertions(+), 1 deletion(-) 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 f2d53defc..1085b2bfd 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 @@ -26,4 +26,15 @@ test("corrctly get angle type", function(){ assert.equal(getAngleType(400), "Invalid angle"); }); +test("corrctly get angle type", function(){ + assert.equal(getAngleType(0), "Invalid angle"); +}); + +test("corrctly get angle type", function(){ + assert.equal(getAngleType(360), "Invalid angle"); +}); + +test("corrctly get angle type", function(){ + assert.equal(getAngleType(-70), "Invalid angle"); +}); 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 98e35b550..60d7789a4 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 @@ -30,7 +30,13 @@ test("Basic proper fraction", () => { assert.equal(isProperFraction(-1, 2), true); }); +test("Basic proper fraction", () => { + assert.equal(isProperFraction(1, -2), true); +}); +test("Basic proper fraction", () => { + assert.equal(isProperFraction(-1, -2), true); +}); 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 2316f0b2a..39eb05249 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 @@ -37,3 +37,38 @@ test("Missing suit throws", () => { // TODO: What other invalid card cases can you think of? + +test("Empty string throws", () => { + assert.throws( + () => getCardValue(""), + /Expected a number followed by a suit/ + ); +}); + +test("Suit only throws", () => { + assert.throws( + () => getCardValue("♠"), + /Expected a number followed by a suit/ + ); +}); + +test("Invalid rank throws", () => { + assert.throws( + () => getCardValue("1♠"), + /Expected a number followed by a suit/ + ); +}); + +test("Invalid suit throws", () => { + assert.throws( + () => getCardValue("9X"), + /Expected a number followed by a suit/ + ); +}); + +test("Rank with no suit character throws", () => { + assert.throws( + () => getCardValue("10"), + /Expected a number followed by a suit/ + ); +}); 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 4396f081a..0565b60bd 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 @@ -11,6 +11,8 @@ test(`should return true for proper fractions`, () => { expect(isProperFraction(1, 2)).toEqual(true); expect(isProperFraction(0, 5)).toEqual(true); expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(1, -2)).toEqual(true); + expect(isProperFraction(-1, -2)).toEqual(true); }); test(`should return false for improper fractions`, () => { 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 cda2ae17d..172eddcfb 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 @@ -18,6 +18,12 @@ test(`Should return 11 when given an ace card`, () => { test(`Should return numeric value for number cards`, () => { 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); expect(getCardValue("10♦")).toEqual(10); }); @@ -28,11 +34,27 @@ test(`Should return 10 for face cards`, () => { expect(getCardValue("K♥")).toEqual(10); }); -test(`Should throw for invalid cards`, () => { +// Invalid cards +test(`should throw for invalid cards`, () => { expect(() => getCardValue("invalid")).toThrow( /Expected a number followed by a suit, but got "invalid"/ ); expect(() => getCardValue("A")).toThrow( /Expected a number followed by a suit/ ); + expect(() => getCardValue("")).toThrow( + /Expected a number followed by a suit/ + ); + expect(() => getCardValue("♠")).toThrow( + /Expected a number followed by a suit/ + ); + expect(() => getCardValue("1♠")).toThrow( + /Expected a number followed by a suit/ + ); + expect(() => getCardValue("9X")).toThrow( + /Expected a number followed by a suit/ + ); + expect(() => getCardValue("10")).toThrow( + /Expected a number followed by a suit/ + ); }); From 1917427dcd2233f85280fe1434deff9f86a8e528 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 11 Oct 2026 06:40:22 +0100 Subject: [PATCH 6/6] Add missing mixed-sign and negative improper fraction tests --- .../2-is-proper-fraction.test.js | 9 +++++++++ .../rewrite-tests-with-jest/2-is-proper-fraction.test.js | 3 +++ 2 files changed, 12 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 60d7789a4..ec3036b0e 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 @@ -38,5 +38,14 @@ test("Basic proper fraction", () => { assert.equal(isProperFraction(-1, -2), true); }); +test("Basic proper fraction", () => { + assert.equal(isProperFraction(-5, 2), false); +}); +test("Basic proper fraction", () => { + assert.equal(isProperFraction(5, -2), false); +}); +test("Basic proper fraction", () => { + assert.equal(isProperFraction(-3, -2), false); +}); 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 0565b60bd..ab11487c9 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 @@ -19,4 +19,7 @@ test(`should return false for improper fractions`, () => { expect(isProperFraction(2, 1)).toEqual(false); expect(isProperFraction(1, 1)).toEqual(false); expect(isProperFraction(5, 3)).toEqual(false); + expect(isProperFraction(-5, 2)).toEqual(false); + expect(isProperFraction(5, -2)).toEqual(false); + expect(isProperFraction(-3, -2)).toEqual(false); });