From 3355b69f5b457028a64309d1990a0f678e54e5eb Mon Sep 17 00:00:00 2001 From: cywong Date: Wed, 8 Jul 2026 20:41:09 +0100 Subject: [PATCH 1/9] Implement getAngleType function for angle classification Implemented the getAngleType function to classify angles. --- .../implement/1-get-angle-type.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 9e05a871e2..1698c5a2db 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -15,7 +15,28 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + // [ChunYanWong] Implement this function + if (angle === 90) { + return "Right angle"; + } + + if (angle < 90 && angle > 0) { + return "Acute angle"; + } + + if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } + + if (angle === 180) { + return "Straight angle"; + } + + if (angle > 180 && angle < 360) { + return "Reflex angle"; + } + + return "Invalid angle"; } // The line below allows us to load the getAngleType function into tests in other files. From bf0b351bfe5899d5ce378b3064ce3ff1ed947eb7 Mon Sep 17 00:00:00 2001 From: cywong Date: Wed, 8 Jul 2026 20:44:11 +0100 Subject: [PATCH 2/9] Implement isProperFraction function Implement isProperFraction function to check if a fraction is proper. --- .../implement/2-is-proper-fraction.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js index 970cb9b641..526b0b910a 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -11,7 +11,13 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + // [ChunYanWong] Implement this function + if (denominator === 0) { + return false; + } + + // Compare absolute values + return Math.abs(numerator) < Math.abs(denominator); } // The line below allows us to load the isProperFraction function into tests in other files. From 4444b088a26127df8f9084707c7cdee2a5ff10ee Mon Sep 17 00:00:00 2001 From: cywong Date: Wed, 8 Jul 2026 20:50:43 +0100 Subject: [PATCH 3/9] Implement getCardValue function for card value retrieval Implement getCardValue function to return card values based on rank. --- .../implement/3-get-card-value.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index ff5c532e1d..308bd61ce3 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -23,6 +23,26 @@ function getCardValue(card) { // TODO: Implement this function + const suit = card.slice(-1); + const rank = card.slice(0, -1); + + + // Ace value + if (rank === "A") { + return 11; + } + + // Face card values + if (["J", "Q", "K"].includes(rank)) { + return 10; + } + + // Number card values ("2" through "10") + const numericValue = parseInt(rank, 10); + if (!isNaN(numericValue) && numericValue >= 2 && numericValue <= 10) { + return numericValue; + } + } // The line below allows us to load the getCardValue function into tests in other files. From d1ad5fdcd01012fba304ebf0ac7531a2b5a9ee72 Mon Sep 17 00:00:00 2001 From: cywong Date: Wed, 8 Jul 2026 20:51:09 +0100 Subject: [PATCH 4/9] Implement getCardValue function Added implementation comment for the getCardValue function. --- .../1-implement-and-rewrite-tests/implement/3-get-card-value.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index 308bd61ce3..e6024b23d6 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -22,7 +22,7 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + // [ChunYanWong] Implement this function const suit = card.slice(-1); const rank = card.slice(0, -1); From 93151d40b66b74c6626980c54f1b5051bc809b82 Mon Sep 17 00:00:00 2001 From: cywong Date: Fri, 10 Jul 2026 17:01:37 +0100 Subject: [PATCH 5/9] Add tests for angle types in getAngleType function --- .../1-get-angle-type.test.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index d777f348d3..8361d674c6 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -13,8 +13,29 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { expect(getAngleType(89)).toEqual("Acute angle"); }); + +// [ChunYanWong] // Case 2: Right angle +test('should return "Right angle" for exactly 90', () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); // Case 3: Obtuse angles +test('should return "Obtuse angle" for values between 90 and 180', () => { + expect(getAngleType(90.1)).toEqual("Obtuse angle"); + expect(getAngleType(135)).toEqual("Obtuse angle"); + expect(getAngleType(179.9)).toEqual("Obtuse angle"); +}); // Case 4: Straight angle +test('should return "Straight angle" for exactly 180', () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); // Case 5: Reflex angles +test('should return "Reflex angle" for values between 180 and 360', () => { + expect(getAngleType(180.1)).toEqual("Reflex angle"); + expect(getAngleType(270)).toEqual("Reflex angle"); + expect(getAngleType(359.9)).toEqual("Reflex angle"); +}); // Case 6: Invalid angles +test('should return "Invalid angle" for values greater than 360', () => { + expect(getAngleType(400)).toEqual("Invalid angle"); +}); From d9a7a5b0647cbbac0264e7ad124ca49e93d97e51 Mon Sep 17 00:00:00 2001 From: cywong Date: Fri, 10 Jul 2026 17:09:08 +0100 Subject: [PATCH 6/9] Update test case syntax to Jest format --- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index 8361d674c6..0ce2ac4816 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -6,7 +6,7 @@ const getAngleType = require("../implement/1-get-angle-type"); // including boundary and invalid cases. // Case 1: Acute angles -test(`should return "Acute angle" when (0 < angle < 90)`, () => { +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"); From f718131045c007dfa2e5e458dacbfe7c65e9640a Mon Sep 17 00:00:00 2001 From: cywong Date: Fri, 10 Jul 2026 17:10:21 +0100 Subject: [PATCH 7/9] Rewrite tests for isProperFraction using Jest Added Jest test cases for proper fraction validation. --- .../2-is-proper-fraction.test.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index 7f087b2ba1..0a9c153d8a 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -5,6 +5,24 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); // TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. // Special case: numerator is zero -test(`should return false when denominator is zero`, () => { +test('should return false when denominator is zero', () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +//[Chun Yan Wong] + +test('returns true when numerator absolute value is less than denominator absolute value', () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(3, -5)).toEqual(true); +}); + +test('returns false when numerator absolute value is equal to denominator absolute value', () => { + expect(isProperFraction(2, 2)).toEqual(false); + expect(isProperFraction(-3, 3)).toEqual(false); +}); + +test('returns false when numerator absolute value is greater than denominator absolute value', () => { + expect(isProperFraction(5, 2)).toEqual(false); + expect(isProperFraction(-7, 3)).toEqual(false); +}); From a9c07355df3a8270b0eecd28c89e746f4f4465b9 Mon Sep 17 00:00:00 2001 From: cywong Date: Fri, 10 Jul 2026 17:39:16 +0100 Subject: [PATCH 8/9] Add error handling for invalid card values Throw an error for invalid card strings. --- .../implement/3-get-card-value.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index e6024b23d6..54ba4ec3da 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js @@ -43,6 +43,9 @@ function getCardValue(card) { return numericValue; } + throw new Error("Invalid card string"); + + } // The line below allows us to load the getCardValue function into tests in other files. From e59ab401cb4a71acb84acea2516086a60bb57071 Mon Sep 17 00:00:00 2001 From: cywong Date: Fri, 10 Jul 2026 17:41:39 +0100 Subject: [PATCH 9/9] Rewrite tests for getCardValue using Jest --- .../3-get-card-value.test.js | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index cf7f9dae2e..59b1401d51 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -9,11 +9,31 @@ test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); -// Suggestion: Group the remaining test data into these categories: -// Number Cards (2-10) -// Face Cards (J, Q, K) -// Invalid Cards +// Number cards (2–10) +test('returns correct numeric values for number cards', () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("5♥")).toEqual(5); + expect(getCardValue("9♦")).toEqual(9); + expect(getCardValue("10♣")).toEqual(10); +}); + +// Face cards +test('returns 10 for face cards', () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♥")).toEqual(10); + expect(getCardValue("K♦")).toEqual(10); +}); +// Ace +test('returns 11 for Ace', () => { + expect(getCardValue("A♣")).toEqual(11); +}); + +// Invalid cards +test('invalid card strings should throw an error', () => { + expect(() => getCardValue("A")).toThrow(); + expect(() => getCardValue("B")).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