From 281f53b280484215340463d87919d70671317c8e Mon Sep 17 00:00:00 2001 From: Edina Kurdi Date: Sun, 5 Jul 2026 16:35:03 +0100 Subject: [PATCH 1/6] implement function for angles and write test cases --- .../implement/1-get-angle-type.js | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 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 9e05a871e2..537a738d18 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,9 +15,13 @@ // execute the code to ensure all tests pass. function getAngleType(angle) { - // TODO: Implement this function + if (angle <= 0 || angle >= 360) return "Invalid angle"; + if (angle < 90) return "Acute angle"; + if (angle === 90) return "Right angle"; + if (angle < 180) return "Obtuse angle"; + if (angle === 180) return "Straight angle"; + if (angle < 360) return "Reflex angle"; } - // The line below allows us to load the getAngleType function into tests in other files. // This will be useful in the "rewrite tests with jest" step. module.exports = getAngleType; @@ -35,3 +39,47 @@ function assertEquals(actualOutput, targetOutput) { // Example: Identify Right Angles const right = getAngleType(90); assertEquals(right, "Right angle"); + +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +const acute_upper_boundary = getAngleType(89); +assertEquals(acute_upper_boundary, "Acute angle"); + +const acute_lower_boundary = getAngleType(1); +assertEquals(acute_lower_boundary, "Acute angle"); + +const invalid_negative = getAngleType(-1); +assertEquals(invalid_negative, "Invalid angle"); + +const invalid_zero = getAngleType(0); +assertEquals(invalid_zero, "Invalid angle"); + +const invalid_full = getAngleType(360); +assertEquals(invalid_full, "Invalid angle"); + +const invalid_big = getAngleType(361); +assertEquals(invalid_big, "Invalid angle"); + +const obtuse_lower_boundary = getAngleType(91); +assertEquals(obtuse_lower_boundary, "Obtuse angle"); + +const obtuse_upper_boundary = getAngleType(179); +assertEquals(obtuse_upper_boundary, "Obtuse angle"); + +const reflex_lower_boundary = getAngleType(181); +assertEquals(reflex_lower_boundary, "Reflex angle"); + +const reflex_upper_boundary = getAngleType(359); +assertEquals(reflex_upper_boundary, "Reflex angle"); + +//decimal test cases + +const acute_decimal = getAngleType(89.9); +assertEquals(acute_decimal, "Acute angle"); + +const obtuse_decimal = getAngleType(179.9); +assertEquals(obtuse_decimal, "Obtuse angle"); + +const reflex_decimal = getAngleType(180.1); +assertEquals(reflex_decimal, "Reflex angle"); From f8431cf4d9c1ac62d28c7c33127127d458488944 Mon Sep 17 00:00:00 2001 From: Edina Kurdi Date: Sun, 5 Jul 2026 17:42:04 +0100 Subject: [PATCH 2/6] implement isProperFraction() and add tests --- .../implement/2-is-proper-fraction.js | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) 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..d3a043a71d 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,10 @@ // execute the code to ensure all tests pass. function isProperFraction(numerator, denominator) { - // TODO: Implement this function + if (denominator === 0 || numerator === 0) return false; + if (!(denominator % 1 === 0 && numerator % 1 === 0)) return false; + if (Math.abs(numerator) < Math.abs(denominator)) return true; + else return false; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -28,6 +31,25 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all cases. // What combinations of numerators and denominators should you test? - +// definition is |numerator| < |denominator| so negative values need to be tested as well; also 0 for either - wouldn't be a fraction (or a valid fraction if its the den); also when the num = den // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(-3, 4), true); +assertEquals(isProperFraction(3, -4), true); + +//numerator or denominator is 0 +assertEquals(isProperFraction(0, 2), false); +assertEquals(isProperFraction(2, 0), false); + +//result is a whole number +assertEquals(isProperFraction(-2, 2), false); +assertEquals(isProperFraction(-3, -3), false); +assertEquals(isProperFraction(3, 3), false); + +//numerator or denominator is a decimal +assertEquals(isProperFraction(1.2, 3), false); +assertEquals(isProperFraction(1, 1.2), false); + +//numerator or denominator is negative +assertEquals(isProperFraction(-4, 5), true); +assertEquals(isProperFraction(-5, 4), false); From 7c5d0b404d1b25c885047f40ad5fa987ce19f1d8 Mon Sep 17 00:00:00 2001 From: Edina Kurdi Date: Sun, 5 Jul 2026 21:06:30 +0100 Subject: [PATCH 3/6] implement getCardValue() function and add tests --- .../implement/3-get-card-value.js | 85 ++++++++++++++++++- 1 file changed, 84 insertions(+), 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 ff5c532e1d..5ac834c805 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,26 @@ // execute the code to ensure all tests pass. function getCardValue(card) { - // TODO: Implement this function + const suits = ["♠", "♥", "♦", "♣"]; + if (card[0] === "A" && suits.includes(card[1]) && card.length === 2) + return 11; + if ( + (card[0] === "J" || card[0] === "Q" || card[0] === "K") && + suits.includes(card[1]) && + card.length === 2 + ) + return 10; + if ( + ["2", "3", "4", "5", "6", "7", "8", "9"].includes(card[0]) && + suits.includes(card[1]) && + card.length === 2 + ) + return Number(card[0]); + if (card.slice(0, 2) == "10" && suits.includes(card[2]) && card.length === 3) + return 10; + throw new Error( + 'Invalid input: Expected rank followed by a suit symbol. For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦"' + ); } // The line below allows us to load the getCardValue function into tests in other files. @@ -40,6 +59,11 @@ function assertEquals(actualOutput, targetOutput) { // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. // Examples: assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("Q♦"), 10); +assertEquals(getCardValue("K♣"), 10); +assertEquals(getCardValue("10♥"), 10); +assertEquals(getCardValue("2♦"), 2); +assertEquals(getCardValue("7♦"), 7); // Handling invalid cards try { @@ -52,3 +76,62 @@ try { } // What other invalid card cases can you think of? +// for instance "1♦" where it starts with 1 but its not 10 +// where it includes the correct answer but there are added characters maybe space(s) like "9♠ " +//where its the opposite way : "♠9" +//where it starts with a valid number but has otherwise more digits eg: "9♠♠" or "99♠" +//where there is a different symbol from the 4 given such as ❤️ + +try { + getCardValue("1♥"); + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("9♠ "); + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("♠9"); + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("99♠"); + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("9♠♠"); + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} + +try { + getCardValue("9❤️"); + + // This line will not be reached if an error is thrown as expected + console.error("Error was not thrown for invalid card 😢"); +} catch (e) { + console.log("Error thrown for invalid card 🎉"); +} From 0d211421bbe242cc94805b274293478219b71d01 Mon Sep 17 00:00:00 2001 From: Edina Kurdi Date: Sun, 5 Jul 2026 22:29:13 +0100 Subject: [PATCH 4/6] rewrite cards test with jest(exercise 3) --- .../3-get-card-value.test.js | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 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..eedb8414f6 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 @@ -7,14 +7,43 @@ const getCardValue = require("../implement/3-get-card-value"); // Case 1: Ace (A) test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); + expect(getCardValue("A♥")).toEqual(11); + expect(getCardValue("A♦")).toEqual(11); + expect(getCardValue("A♣")).toEqual(11); }); // Suggestion: Group the remaining test data into these categories: -// Number Cards (2-10) -// Face Cards (J, Q, K) +// Case 2: Number Cards (2-10) +test(`Should return the number when given a number card`, () => { + 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); +}); + +// Case 3: Face Cards (J, Q, K) +test(`Should return 10 when given a face card`, () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♣")).toEqual(10); + expect(getCardValue("K♥")).toEqual(10); +}); + // Invalid Cards +test(`Should return an error when given a invalid input`, () => { + expect(() => getCardValue("J♠ ")).toThrow(); + expect(() => getCardValue("Q")).toThrow(); + expect(() => getCardValue("9♠ ")).toThrow(); + expect(() => getCardValue("♠9")).toThrow(); + expect(() => getCardValue("♠99")).toThrow(); + expect(() => getCardValue("99♠")).toThrow(); + expect(() => getCardValue("9❤️")).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 - From dec4845593a7691830e417377eff7af85d753905 Mon Sep 17 00:00:00 2001 From: Edina Kurdi Date: Sun, 5 Jul 2026 23:05:43 +0100 Subject: [PATCH 5/6] rewrite angle test with jest(exercise 1) --- .../1-get-angle-type.test.js | 30 +++++++++++++++++++ 1 file changed, 30 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..f7705c7d2f 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,37 @@ 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(100)).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(300)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test('Should return "Invalid angle" when the input is invalid', () => { + expect(getAngleType(-1)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(361)).toEqual("Invalid angle"); +}); From 5a195ff7e541830469dc628751fe991df114e219 Mon Sep 17 00:00:00 2001 From: Edina Kurdi Date: Sun, 5 Jul 2026 23:18:38 +0100 Subject: [PATCH 6/6] rewrite proper fraction test with jest(exercise 2) --- .../2-is-proper-fraction.test.js | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 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 7f087b2ba1..859d8fadb8 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 @@ -2,9 +2,37 @@ // We will use the same function, but write tests for it using Jest in this file. 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. +// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.] -// Special case: numerator is zero +//case 1: proper function + +test("should return true when |numerator| < |denominator|", () => { + expect(isProperFraction(-3, 4)).toEqual(true); + expect(isProperFraction(3, -4)).toEqual(true); + expect(isProperFraction(1, 2)).toEqual(true); +}); + +//case 2: result is a whole number +test("should return false when the result is a whole number", () => { + expect(isProperFraction(2, 2)).toEqual(false); + expect(isProperFraction(-2 - 2)).toEqual(false); + expect(isProperFraction(2, -2)).toEqual(false); +}); + +//case 3: numerator or denominator is a decimal +test("should return false if the numerator or denominator is a decimal", () => { + expect(isProperFraction(1.5, 2)).toEqual(false); + expect(isProperFraction(1, 1.5)).toEqual(false); +}); + +//case 4: numerator or denominator is negative +test("should return true even if the numerator or denominator is negative", () => { + expect(isProperFraction(-4, 5)).toEqual(true); + expect(isProperFraction(4, -5)).toEqual(true); +}); + +// Special case: numerator or denominator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); + expect(isProperFraction(0, 1)).toEqual(false); });