From e59bc4c34d51e4fee9dc60f7462e0603663ccc37 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Wed, 4 Mar 2026 17:30:13 +0000 Subject: [PATCH 1/9] Implement getAngleType function and add tests Implemented the getAngleType function to determine angle types and added tests for various cases. --- .../implement/1-get-angle-type.js | 38 ++++++++++++++++++- 1 file changed, 37 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..8a305b3c2b 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,22 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (angle > 0 && angle < 90) { + return "Acute angle"; + } + if (angle === 90) { + return "Right 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. @@ -35,3 +50,24 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); + +const obtuse = getAngleType(120); +assertEquals(obtuse, "Obtuse angle"); + +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +const reflex = getAngleType(270); +assertEquals(reflex, "Reflex angle"); + +const invalidZero = getAngleType(0); +assertEquals(invalidZero, "Invalid angle"); + +const invalidNegative = getAngleType(-45); +assertEquals(invalidNegative, "Invalid angle"); + +const invalidOver = getAngleType(361); +assertEquals(invalidOver, "Invalid angle"); From 2ccb87759b78cdcb50444fc6001cf92b918e55e1 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Wed, 4 Mar 2026 17:38:23 +0000 Subject: [PATCH 2/9] Implement getCardValue function with error handling Implement getCardValue function to determine card value based on rank and suit, including error handling for invalid cards. --- .../implement/3-get-card-value.js | 33 +++++++++++++++++++ 1 file changed, 33 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 c7559e787e..ccffa4ca37 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,22 @@ function getCardValue(card) { // TODO: Implement this function + const rank = card.slice(0, -1); + const suit = card.slice(-1); + + const validSuits = ["♠", "♥", "♦", "♣"]; + const faceCards = ["10", "J", "Q", "K"]; + const numberCards = ["2", "3", "4", "5", "6", "7", "8", "9"]; + + if (!validSuits.includes(suit)) { + throw new Error("Invalid card suit"); + } + + if (rank === "A") return 11; + if (faceCards.includes(rank)) return 10; + if (numberCards.includes(rank)) return Number(rank); + + throw new Error("Invalid card rank"); } // The line below allows us to load the getCardValue function into tests in other files. @@ -40,13 +56,30 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("5♥"), 5); +assertEquals(getCardValue("K♦"), 10); +assertEquals(getCardValue("A♣"), 11); // Handling invalid cards try { getCardValue("invalid"); + console.error("Error was not thrown for completely invalid card"); +} catch (error) {} +try { + getCardValue("1♠"); + console.error("Error was not thrown for invalid card rank"); +} catch (error) { + assertEquals(error.message, "Invalid card rank"); +} // This line will not be reached if an error is thrown as expected console.error("Error was not thrown for invalid card"); } catch (e) {} // What other invalid card cases can you think of? +try { + getCardValue("5X"); + console.error("Error was not thrown for invalid card suit"); +} catch (error) { + assertEquals(error.message, "Invalid card suit"); +} From ea57d667fc004dba1355055946d6f0cae6eb093a Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Wed, 4 Mar 2026 17:42:51 +0000 Subject: [PATCH 3/9] Add tests for angle types in getAngleType function --- .../1-get-angle-type.test.js | 23 +++++++++++++++++++ 1 file changed, 23 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..68c3a220dc 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 @@ -14,7 +14,30 @@ 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(135)).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" when angle is <= 0 or >= 360`, () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(-10)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(400)).toEqual("Invalid angle"); +}); From 3a4fd15276c763e9a42e67910162124b7a2ff5a0 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Wed, 4 Mar 2026 17:46:16 +0000 Subject: [PATCH 4/9] Add tests for isProperFraction function --- .../2-is-proper-fraction.test.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) 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..ada36cb016 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 @@ -8,3 +8,37 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +// Proper fractions (positive numbers +test(`should return true when numerator is smaller than denominator`, () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(3, 4)).toEqual(true); +}); + +// Equal numbers → not proper +test(`should return false when numerator equals denominator`, () => { + expect(isProperFraction(2, 2)).toEqual(false); +}); + +// Improper fractions +test(`should return false when numerator is greater than denominator`, () => { + expect(isProperFraction(5, 4)).toEqual(false); + expect(isProperFraction(10, 3)).toEqual(false); +}); + +// Zero numerator +test(`should return true when numerator is zero and denominator is non-zero`, () => { + expect(isProperFraction(0, 5)).toEqual(true); +}); + +// Negative numbers +test(`should handle negative numbers correctly`, () => { + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(1, -2)).toEqual(true); + expect(isProperFraction(-3, -2)).toEqual(false); +}); + +// Both zero +test(`should return false when both numerator and denominator are zero`, () => { + expect(isProperFraction(0, 0)).toEqual(false); +}); From f6b6ecbdcd44245f6063b788f76e013705968b51 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Wed, 4 Mar 2026 17:49:44 +0000 Subject: [PATCH 5/9] Add tests for card values and error handling --- .../3-get-card-value.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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..b1cb9701ee 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 @@ -11,8 +11,25 @@ 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 the correct number for number cards`, () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("9♥")).toEqual(9); + expect(getCardValue("10♦")).toEqual(10); +}); // Face Cards (J, Q, K) +expect(getCardValue("J♣")).toEqual(10); + expect(getCardValue("Q♦")).toEqual(10); + expect(getCardValue("K♠")).toEqual(10); +}); // Invalid Cards +test(`Should throw an error for invalid card strings`, () => { + const invalidCards = ["", "A", "11♠", "1♠", "B♠", "10X", "♠A", "invalid"]; + + for (const badCard of invalidCards) { + expect(() => getCardValue(badCard)).toThrowError(); + } +}); + // To learn how to test whether a function throws an error as expected in Jest, // please refer to the Jest documentation: From 060fc0d79d870d8da4bc446554fb8244a7869d9f Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Wed, 4 Mar 2026 18:05:45 +0000 Subject: [PATCH 6/9] Implement isProperFraction function with tests Added checks for zero denominator and updated test cases for proper fractions. --- .../implement/2-is-proper-fraction.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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..0351c538ac 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 @@ -12,6 +12,11 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function + if (denominator === 0) { + return false; + } + + return Math.abs(numerator) < Math.abs(denominator); } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +36,23 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +// Equal numbers → will not be proper +assertEquals(isProperFraction(2, 2), false); + +// Improper fractions +assertEquals(isProperFraction(5, 4), false); +assertEquals(isProperFraction(10, 3), false); + +// Zero numerator → will be proper +assertEquals(isProperFraction(0, 5), true); + +// Negative numbers +assertEquals(isProperFraction(-1, 2), true); +assertEquals(isProperFraction(1, -2), true); +assertEquals(isProperFraction(-3, -2), false); + +// Denominator zero +assertEquals(isProperFraction(1, 0), false); +assertEquals(isProperFraction(0, 0), false); + From a4e8008b20bac3d46266aab59d4e9d3cb43920dd Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Sun, 15 Mar 2026 18:48:40 +0000 Subject: [PATCH 7/9] Reorder face and number cards in get card value --- .../implement/3-get-card-value.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ccffa4ca37..e4822318f5 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 @@ -27,8 +27,8 @@ function getCardValue(card) { const suit = card.slice(-1); const validSuits = ["♠", "♥", "♦", "♣"]; - const faceCards = ["10", "J", "Q", "K"]; - const numberCards = ["2", "3", "4", "5", "6", "7", "8", "9"]; + const faceCards = ["J", "Q", "K"]; + const numberCards = ["2", "3", "4", "5", "6", "7", "8", "9", "10"]; if (!validSuits.includes(suit)) { throw new Error("Invalid card suit"); From 42e1a892c51a532bfc53cd4338279e51a7aedb99 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Sun, 15 Mar 2026 18:49:57 +0000 Subject: [PATCH 8/9] Add tests for face card values in getCardValue --- .../rewrite-tests-with-jest/3-get-card-value.test.js | 2 ++ 1 file changed, 2 insertions(+) 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 b1cb9701ee..f0558c9cdc 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 @@ -17,6 +17,8 @@ test(`Should return the correct number for number cards`, () => { expect(getCardValue("10♦")).toEqual(10); }); // Face Cards (J, Q, K) + +test(Should return 10 for face cards, () => { expect(getCardValue("J♣")).toEqual(10); expect(getCardValue("Q♦")).toEqual(10); expect(getCardValue("K♠")).toEqual(10); From 15f30448f7b16e068d40b086e094cfd0cf8a3886 Mon Sep 17 00:00:00 2001 From: Khaliun Baatarkhuu Date: Sun, 15 Mar 2026 18:58:55 +0000 Subject: [PATCH 9/9] Update test cases for negative numbers in isProperFraction Refactor tests for negative numbers to improve clarity and consistency. --- .../2-is-proper-fraction.test.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 ada36cb016..2c891939ab 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 @@ -32,10 +32,13 @@ test(`should return true when numerator is zero and denominator is non-zero`, () }); // Negative numbers -test(`should handle negative numbers correctly`, () => { - expect(isProperFraction(-1, 2)).toEqual(true); - expect(isProperFraction(1, -2)).toEqual(true); - expect(isProperFraction(-3, -2)).toEqual(false); +test("should return true when |numerator| < |denominator| and signs differ", () => { + expect(isProperFraction(-1, 2)).toBe(true); + expect(isProperFraction(1, -2)).toBe(true); +}); + +test("should return false when |numerator| > |denominator| and both are negative", () => { + expect(isProperFraction(-3, -2)).toBe(false); }); // Both zero