From bfeeb31e5a2f61049b7873ef942602f4f0bb3625 Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Fri, 6 Mar 2026 23:59:10 +0000 Subject: [PATCH 1/5] Implement getAngleType function to classify angles and add corresponding tests --- .../implement/1-get-angle-type.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) 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 9e05a871e..fee5c5246 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 @@ -16,6 +16,20 @@ 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"; + } else { + return "Invalid angle"; + } + } // The line below allows us to load the getAngleType function into tests in other files. @@ -35,3 +49,25 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +// Example: Identify Acute Angles +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); + +// Example: Identify Obtuse Angles +const obtuse = getAngleType(135); +assertEquals(obtuse, "Obtuse angle"); + +// Example: Identify Straight Angles +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +// Example: Identify Reflex Angles +const reflex = getAngleType(270); +assertEquals(reflex, "Reflex angle"); + +// Example: Identify Invalid Angles +const invalid = getAngleType(-45); +assertEquals(invalid, "Invalid angle"); + + From e1f536eb2098f7cdd955ccac9a65409c65e25bfc Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Sat, 7 Mar 2026 00:11:45 +0000 Subject: [PATCH 2/5] Implement isProperFraction function to determine proper fractions and add corresponding tests --- .../implement/2-is-proper-fraction.js | 34 +++++++++++++++++++ 1 file changed, 34 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 970cb9b64..46ef5c644 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,13 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function + if (denominator === 0) { + return false; // A fraction with a denominator of 0 is undefined, so it's not a proper fraction. + } + if (Math.abs(numerator) < Math.abs(denominator)) { + return true; // A proper fraction has an absolute value of the numerator less than the absolute value of the denominator. + } + return false; // If none of the above conditions are met, it's not a proper fraction. } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +38,30 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +// Example: -1/2 is a proper fraction +assertEquals(isProperFraction(-1, 2), true); + +// Example: 1/-2 is a proper fraction +assertEquals(isProperFraction(1, -2), true); + +// Example: -1/-2 is a proper fraction +assertEquals(isProperFraction(-1, -2), true); + +// Example: 2/1 is not a proper fraction +assertEquals(isProperFraction(2, 1), false); + +// Example: -2/1 is not a proper fraction +assertEquals(isProperFraction(-2, 1), false); + +// Example: 0/1 is a proper fraction +assertEquals(isProperFraction(0, 1), true); + +// Example: 1/0 is not a proper fraction (undefined) +assertEquals(isProperFraction(1, 0), false); + +// Example: -1/0 is not a proper fraction (undefined) +assertEquals(isProperFraction(-1, 0), false); + +// Example: 0/0 is not a proper fraction (undefined) +assertEquals(isProperFraction(0, 0), false); From 850c2123548a44cd967f79ecbcafac6deefcc75f Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Sat, 7 Mar 2026 13:06:54 +0000 Subject: [PATCH 3/5] Implement getCardValue function to return card values and handle invalid cards --- .../implement/3-get-card-value.js | 34 +++++++++++++++++++ 1 file changed, 34 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 c7559e787..5f2aa78b3 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,24 @@ function getCardValue(card) { // TODO: Implement this function + const rank = card.slice(0, -1); + const suit = card.slice(-1); + + // Validate the suit + const validSuits = ["♠", "♥", "♦", "♣"]; + if (!validSuits.includes(suit)) { + throw new Error("Invalid card: Invalid suit"); + } + + if (rank === "A") { + return 11; + } else if (["J", "Q", "K"].includes(rank)) { + return 10; + } else if (["2", "3", "4", "5", "6", "7", "8", "9", "10"].includes(rank)) { + return Number(rank); // Convert the rank string to a number + } else { + throw new Error("Invalid card: Invalid rank"); + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -40,6 +58,9 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("A♥"), 11); +assertEquals(getCardValue("Q♣"), 10); +assertEquals(getCardValue("K♠"), 10); // Handling invalid cards try { @@ -50,3 +71,16 @@ try { } catch (e) {} // What other invalid card cases can you think of? +try { + getCardValue("11♠"); + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card"); +} catch (e) {} + +try { + getCardValue("A♤"); + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card"); +} catch (e) {} From fe32f508e0ec49b644e32d4970b193f1d54320eb Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Sat, 7 Mar 2026 16:35:57 +0000 Subject: [PATCH 4/5] Add tests for angle classification and card value handling --- .../1-get-angle-type.test.js | 31 +++++++++++++++++++ .../2-is-proper-fraction.test.js | 16 ++++++++++ .../3-get-card-value.test.js | 28 ++++++++++++++++- 3 files changed, 74 insertions(+), 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 d777f348d..9a311b2c2 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,38 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when (angle === 90)`, () => { + // Test right angle + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { + // Test various obtuse angles, including boundary cases + 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)`, () => { + // Test straight angle + expect(getAngleType(180)).toEqual("Straight angle"); +}); + // Case 5: Reflex angles +test(`should return "Reflex angle" when (180 < angle < 360)`, () => { + // Test various reflex angles, including boundary cases + 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 or angle >= 360)`, () => { + // Test various invalid angles, including boundary cases + expect(getAngleType(-1)).toEqual("Invalid angle"); + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(361)).toEqual("Invalid angle"); +}); 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 7f087b2ba..09df4e192 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 @@ -7,4 +7,20 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); // Special case: numerator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); + expect(isProperFraction(-1, 0)).toEqual(false); + expect(isProperFraction(0, 0)).toEqual(false); +}); + +test(`should return true for valid proper fractions for negatives`, () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(1, -2)).toEqual(true); + expect(isProperFraction(-1, -2)).toEqual(true); +}); + +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(-1, 0)).toEqual(false); + expect(isProperFraction(2, 1)).toBe(false); + expect(isProperFraction(-2, 1)).toBe(false); + expect(isProperFraction(2, 2)).toBe(false); }); 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 cf7f9dae2..93d869b4e 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,6 +9,33 @@ test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); +// Case 2: 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); +}); + +// Case 3: Number Cards (2-10) +test(`Should return the 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); +}); + +// Handling invalid cards +test(`Should throw an error for invalid cards`, () => { + expect(() => getCardValue("invalid")).toThrow(); + expect(() => getCardValue("AinvalidSuit")).toThrow(); + expect(() => getCardValue("InvalidRank♠")).toThrow(); +}); + // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) // Face Cards (J, Q, K) @@ -17,4 +44,3 @@ 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 - From 007257697291ce7242aa5ff9e4ecf94c1973a66a Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Mon, 9 Mar 2026 02:18:33 +0000 Subject: [PATCH 5/5] Refactor angle type and proper fraction functions; enhance tests for accuracy and coverage --- .../implement/1-get-angle-type.js | 3 --- .../implement/2-is-proper-fraction.js | 8 ++++---- .../rewrite-tests-with-jest/1-get-angle-type.test.js | 1 + .../2-is-proper-fraction.test.js | 10 +++++----- .../rewrite-tests-with-jest/3-get-card-value.test.js | 2 ++ 5 files changed, 12 insertions(+), 12 deletions(-) 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 fee5c5246..6d0da3e50 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 @@ -29,7 +29,6 @@ function getAngleType(angle) { } else { return "Invalid angle"; } - } // The line below allows us to load the getAngleType function into tests in other files. @@ -69,5 +68,3 @@ assertEquals(reflex, "Reflex angle"); // Example: Identify Invalid Angles const invalid = getAngleType(-45); assertEquals(invalid, "Invalid angle"); - - 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 46ef5c644..23c5d8bb3 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 @@ -13,12 +13,12 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function if (denominator === 0) { - return false; // A fraction with a denominator of 0 is undefined, so it's not a proper fraction. + return false; } if (Math.abs(numerator) < Math.abs(denominator)) { - return true; // A proper fraction has an absolute value of the numerator less than the absolute value of the denominator. + return true; } - return false; // If none of the above conditions are met, it's not a proper fraction. + return false; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -64,4 +64,4 @@ assertEquals(isProperFraction(1, 0), false); assertEquals(isProperFraction(-1, 0), false); // Example: 0/0 is not a proper fraction (undefined) -assertEquals(isProperFraction(0, 0), false); +assertEquals(isProperFraction(0, 0), false); 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 9a311b2c2..9ac76d8a6 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 @@ -11,6 +11,7 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { expect(getAngleType(1)).toEqual("Acute angle"); expect(getAngleType(45)).toEqual("Acute angle"); expect(getAngleType(89)).toEqual("Acute angle"); + expect(getAngleType(89.9)).toBe("Acute angle"); }); // Case 2: Right angle 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 09df4e192..f3b9fa2bf 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 @@ -11,16 +11,16 @@ test(`should return false when denominator is zero`, () => { expect(isProperFraction(0, 0)).toEqual(false); }); -test(`should return true for valid proper fractions for negatives`, () => { +test(`should return true for valid proper fractions for Positives and Negatives`, () => { expect(isProperFraction(1, 2)).toEqual(true); expect(isProperFraction(-1, 2)).toEqual(true); expect(isProperFraction(1, -2)).toEqual(true); expect(isProperFraction(-1, -2)).toEqual(true); }); -test(`should return false when denominator is zero`, () => { +test(`should return false for improper fraction`, () => { expect(isProperFraction(-1, 0)).toEqual(false); - expect(isProperFraction(2, 1)).toBe(false); - expect(isProperFraction(-2, 1)).toBe(false); - expect(isProperFraction(2, 2)).toBe(false); + expect(isProperFraction(2, 1)).toEqual(false); + expect(isProperFraction(-2, 1)).toEqual(false); + expect(isProperFraction(2, 2)).toEqual(false); }); 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 93d869b4e..727eabfa7 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 @@ -34,6 +34,8 @@ test(`Should throw an error for invalid cards`, () => { expect(() => getCardValue("invalid")).toThrow(); expect(() => getCardValue("AinvalidSuit")).toThrow(); expect(() => getCardValue("InvalidRank♠")).toThrow(); + expect(() => getCardValue("A♤")).toThrow("Invalid card: Invalid suit"); + expect(() => getCardValue("11♠")).toThrow("Invalid card: Invalid rank"); }); // Suggestion: Group the remaining test data into these categories: