From a4739dd1d93e7eb10eb39f1ccb6956726484ccdf Mon Sep 17 00:00:00 2001 From: Ales-Os-Dev_Lab Date: Sat, 28 Feb 2026 14:48:16 +0000 Subject: [PATCH 1/6] Implement getAngleType function to classify angles and add corresponding tests --- .../implement/1-get-angle-type.js | 31 +++++++++++++++++++ 1 file changed, 31 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 9e05a871e2..f13aac3e9b 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,19 @@ 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 +48,21 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +const acute = getAngleType(65); +assertEquals(acute, "Acute angle"); + +const obtuse = getAngleType(124); +assertEquals(obtuse, "Obtuse angle"); + +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +const reflex = getAngleType(293); +assertEquals(reflex, "Reflex angle"); + +const invalid1 = getAngleType(-19); +assertEquals(invalid1, "Invalid angle"); + +const invalid2 = getAngleType(372); +assertEquals(invalid2, "Invalid angle"); From a62fa276dce2e2ac23016719532f694a34a88d2c Mon Sep 17 00:00:00 2001 From: Ales-Os-Dev_Lab Date: Sat, 28 Feb 2026 16:07:51 +0000 Subject: [PATCH 2/6] Implement isProperFraction function to determine proper fractions and add corresponding tests --- .../implement/2-is-proper-fraction.js | 25 ++++++++++++++++++- 1 file changed, 24 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..06acba6f75 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,8 +12,19 @@ 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 (numerator === 0) { + return true; // A fraction with a numerator of 0 is a proper fraction (0/1 = 0). + } + if (Math.abs(numerator) < Math.abs(denominator)) { + return true; // If the absolute value of the numerator is less than the absolute value of the denominator, + // it's a proper fraction. + } + return false; // Otherwise, it's not a proper fraction. +} // The line below allows us to load the isProperFraction function into tests in other files. // This will be useful in the "rewrite tests with jest" step. module.exports = isProperFraction; @@ -31,3 +42,15 @@ function assertEquals(actualOutput, targetOutput) { // 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: 0/5 is a proper fraction +assertEquals(isProperFraction(0, 5), true); + +// Example: -5/10 is a proper fraction +assertEquals(isProperFraction(-5, 10), true); + +// Example: 0/0 is not a proper fraction +assertEquals(isProperFraction(0, 0), false); From 7da461adb303ade1a805c0a91d899adbccf5efbd Mon Sep 17 00:00:00 2001 From: Ales-Os-Dev_Lab Date: Tue, 3 Mar 2026 09:26:04 +0000 Subject: [PATCH 3/6] Implement getCardValue function with validation for ranks and suits, including error handling for invalid inputs --- .../implement/3-get-card-value.js | 94 +++++++++++++++++++ 1 file changed, 94 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..215ec6afd9 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,50 @@ function getCardValue(card) { // TODO: Implement this function + + // 1. Define valid suits and ranks + const suits = ["♠", "♥", "♦", "♣"]; + const ranks = [ + "A", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "J", + "Q", + "K", + ]; + + // 2. Basic validation: ensure card is a string and not empty + if (typeof card !== "string" || card.length === 0) { + throw new Error("Card must be a non-empty string"); + } + + // 3. Extract rank and suit from the card string + const rank = card.substring(0, card.length - 1); + const suit = card.substring(card.length - 1); + + // 4. Validate rank and suit + if (!ranks.includes(rank)) { + throw new Error("Invalid rank"); + } + if (!suits.includes(suit)) { + throw new Error("Invalid suit"); + } + + // 5. Return the appropriate value based on the rank + if (rank === "A") { + return 11; + } else if (["J", "Q", "K"].includes(rank)) { + return 10; + } else { + return parseInt(rank); + } } // The line below allows us to load the getCardValue function into tests in other files. @@ -50,3 +94,53 @@ try { } catch (e) {} // What other invalid card cases can you think of? + +try { + getCardValue("11♠"); + console.error("Error was not thrown for invalid rank"); +} catch (e) {} + +try { + getCardValue("A♤"); + console.error("Error was not thrown for invalid suit"); +} catch (e) {} + +try { + getCardValue(""); + console.error("Error was not thrown for empty string"); +} catch (e) {} + +try { + getCardValue(123); + console.error("Error was not thrown for non-string input"); +} catch (e) {} + +try { + getCardValue("10"); + console.error("Error was not thrown for missing suit"); +} catch (e) {} + +try { + getCardValue("♠"); + console.error("Error was not thrown for missing rank"); +} catch (e) {} + +try { + getCardValue("A"); + console.error("Error was not thrown for missing suit"); +} catch (e) {} + +try { + getCardValue("1♠"); + console.error("Error was not thrown for invalid rank"); +} catch (e) {} + +try { + getCardValue("10XX"); + console.error("Error was not thrown for extra characters"); +} catch (e) {} + +try { + getCardValue("Z♦"); + console.error("Error was not thrown for invalid rank"); +} catch (e) {} From d5c04be6b033aa29290cda7d1bd6a8395642c6ed Mon Sep 17 00:00:00 2001 From: Ales-Os-Dev_Lab Date: Tue, 3 Mar 2026 10:25:36 +0000 Subject: [PATCH 4/6] Added comprehensive tests in Jest for getAngleType function covering all angle types and invalid cases --- .../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..aff10dbeb1 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 exactly 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 exactly 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 throw an error for negative angles`, () => { + expect(() => getAngleType(-1)).toThrow("Invalid angle"); +}); +test(`should throw an error for angles >= 360`, () => { + expect(() => getAngleType(360)).toThrow("Invalid angle"); +}); From ca4d48e2b87a9f2987cc61d5e543a33620208f50 Mon Sep 17 00:00:00 2001 From: Ales-Os-Dev_Lab Date: Thu, 5 Mar 2026 09:02:13 +0000 Subject: [PATCH 5/6] Add comprehensive Jest tests for isProperFraction function covering various cases --- .../2-is-proper-fraction.test.js | 57 +++++++++++++++++++ 1 file changed, 57 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..20379d0c0d 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,60 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); + +test(`should return true when numerator is zero and denominator is non-zero`, () => { + expect(isProperFraction(0, 5)).toEqual(true); +}); + +// Proper fractions with positive numbers +test(`should return true for proper fractions with positive numerator and denominator`, () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(3, 4)).toEqual(true); +}); + +// Improper fractions with positive numbers +test(`should return false for improper fractions with positive numerator and denominator`, () => { + expect(isProperFraction(2, 1)).toEqual(false); + expect(isProperFraction(5, 3)).toEqual(false); +}); + +// Proper fractions with negative numbers +test(`should return true for proper fractions with negative numerator and positive denominator`, () => { + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(-3, 4)).toEqual(true); +}); + +test(`should return true for proper fractions with positive numerator and negative denominator`, () => { + expect(isProperFraction(1, -2)).toEqual(true); + expect(isProperFraction(3, -4)).toEqual(true); +}); + +// Improper fractions with negative numbers +test(`should return false for improper fractions with negative numerator and positive denominator`, () => { + expect(isProperFraction(-2, 1)).toEqual(false); + expect(isProperFraction(-5, 3)).toEqual(false); +}); +test(`should return false for improper fractions with positive numerator and negative denominator`, () => { + expect(isProperFraction(2, -1)).toEqual(false); + expect(isProperFraction(5, -3)).toEqual(false); +}); + +// Special case: both numerator and denominator are zero +test(`should return false when both numerator and denominator are zero`, () => { + expect(isProperFraction(0, 0)).toEqual(false); +}); + +// Numerator equals denominator +test("should return false when numerator equals denominator", () => { + expect(isProperFraction(5, 5)).toBe(false); + expect(isProperFraction(-5, -5)).toBe(false); +}); + +// Both numerator and denominator are negative +test("should return true for proper fractions with two negative numbers", () => { + expect(isProperFraction(-1, -3)).toBe(true); +}); + +test("should return false for improper fractions with two negative numbers", () => { + expect(isProperFraction(-10, -2)).toBe(false); +}); From 74fdc0a3bc48900d2a65265c2a068a4cbff1c969 Mon Sep 17 00:00:00 2001 From: Ales-Os-Dev_Lab Date: Thu, 5 Mar 2026 09:51:30 +0000 Subject: [PATCH 6/6] Refactor tests for getCardValue function to improve structure and coverage for number and face cards, including error handling for invalid inputs --- .../3-get-card-value.test.js | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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..a9c7097b94 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,10 +11,34 @@ 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 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); +}); // 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); +}); // Invalid Cards +test(`Should throw an error for invalid cards`, () => { + expect(() => getCardValue("1♠")).toThrow(); + expect(() => getCardValue("11♠")).toThrow(); + expect(() => getCardValue("B♠")).toThrow(); + expect(() => getCardValue("Z♠")).toThrow(); + expect(() => getCardValue("A")).toThrow(); + expect(() => getCardValue("10")).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 -