From e0d2999f1878b2e3399cb24c1b2afb0e09709557 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Fri, 17 Jul 2026 00:00:51 +0100 Subject: [PATCH 1/6] Add Jest tests for getCardValue function covering aces, face cards, number cards, and invalid inputs --- .../3-get-card-value.test.js | 33 +++++++++++++++++++ 1 file changed, 33 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..23c4c51ebf 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 @@ -4,11 +4,44 @@ const getCardValue = require("../implement/3-get-card-value"); // TODO: Write tests in Jest syntax to cover all possible outcomes. + // 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); +}); + +// Case 2: 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); }); +// Case 3: Number cards (2-10) +test(`Should return the numeric value 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 4: Invalid cards +test(`Should throw an error when given an invalid card`, () => { + expect(() => getCardValue("invalid")).toThrow("Invalid card"); + expect(() => getCardValue("1♠")).toThrow("Invalid card"); + expect(() => getCardValue("11♥")).toThrow("Invalid card"); + expect(() => getCardValue("A♦")).not.toThrow(); // Valid ace card + expect(() => getCardValue("J♣")).not.toThrow(); // Valid face card +}); + // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) // Face Cards (J, Q, K) From cd3e7530e5a3deba62be35bdfcb9efe27e7b84f1 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Thu, 16 Jul 2026 23:54:04 +0100 Subject: [PATCH 2/6] Add comprehensive Jest tests for isProperFraction function covering various cases --- .../2-is-proper-fraction.test.js | 54 +++++++++++++++++++ 1 file changed, 54 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..3ef73fa74b 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,63 @@ // 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. +const isProperFraction = require("../implement/2-is-proper-fraction"); + +// Case 1: Proper fractions +test(`should return true for proper fractions`, () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(-1, -2)).toEqual(true); +}); + +// Case 2: Improper fractions +test(`should return false for improper fractions`, () => { + expect(isProperFraction(2, 1)).toEqual(false); + expect(isProperFraction(3, 2)).toEqual(false); + expect(isProperFraction(-3, 2)).toEqual(false); + expect(isProperFraction(3, -2)).toEqual(false); +}); + +// Case 3: Zero numerator +test(`should return true when numerator is zero`, () => { + expect(isProperFraction(0, 1)).toEqual(true); + expect(isProperFraction(0, -1)).toEqual(true); +}); + +// Case 4: Zero denominator +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); +}); + +// Case 5: Negative fractions +test(`should return false for negative fractions with positive denominator`, () => { + expect(isProperFraction(-1, 2)).toEqual(true); +}); + +test(`should return false for negative fractions with negative denominator`, () => { + expect(isProperFraction(-1, -2)).toEqual(true); +}); + +// Case 6: Invalid fractions (denominator 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); +}); + +// Case 7: Special case: numerator is zero +test(`should return true when numerator is zero`, () => { + expect(isProperFraction(0, 1)).toEqual(true); + expect(isProperFraction(0, -1)).toEqual(true); +}); + // Special case: numerator is zero test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); + From a9155fc3cfb9bed11ddb033993a35b616a1f066d Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Thu, 16 Jul 2026 23:48:25 +0100 Subject: [PATCH 3/6] Add tests for angle classification and error handling in getAngleType function --- .../1-get-angle-type.test.js | 24 +++++++++++++++++++ 1 file changed, 24 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..c487d80b15 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,31 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when angle === 90`, () => { + 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(120)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); // Case 4: Straight angle +test(`should return "Straight angle" when angle === 180`, () => { + 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 throw an error when angle is negative`, () => { + expect(() => getAngleType(-1)).toThrow("Invalid angle"); +}); +test(`should throw an error when angle is greater than or equal to 360`, () => { + expect(() => getAngleType(360)).toThrow("Invalid angle"); +}); From d28f26ff3d433250da72c87c7f106db436362169 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Thu, 16 Jul 2026 23:45:25 +0100 Subject: [PATCH 4/6] Implement getCardValue function to validate and return card values, including error handling for invalid cards --- .../implement/3-get-card-value.js | 26 +++++++++++++++++++ 1 file changed, 26 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..377a189950 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,25 @@ function getCardValue(card) { // TODO: Implement this function + const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; + const validSuits = ["♠", "♥", "♦", "♣"]; + + // Checking if the card is valid + const rank = card.slice(0, -1); + const suit = card.slice(-1); + + if (!validRanks.includes(rank) || !validSuits.includes(suit)) { + throw new Error("Invalid card"); + } + + // Determininig the value of the card + if (rank === "A") { + return 11; + } else if (["J", "Q", "K"].includes(rank)) { + return 10; + } else { + return parseInt(rank, 10); + } } // 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("A♠"), 11); +assertEquals(getCardValue("J♠"), 10); +assertEquals(getCardValue("Q♠"), 10); +assertEquals(getCardValue("K♠"), 10); + // Handling invalid cards try { @@ -52,3 +76,5 @@ try { } // What other invalid card cases can you think of? +assertEquals(getCardValue("11♥"), 11); +assertEquals(getCardValue("A♦"), 11); From e15fb8462228eb43e0691928217b263df209cf89 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Thu, 16 Jul 2026 23:18:47 +0100 Subject: [PATCH 5/6] Implement isProperFraction function and add corresponding tests --- .../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..51fe7a8733 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,19 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function + if (denominator === 0) { + return false; + } + if (numerator === 0) { + return true; + } + if (numerator < 0 && denominator < 0) { + return isProperFraction(-numerator, -denominator); + } + if (numerator < 0 || denominator < 0) { + return false; + } + return numerator < denominator; } // The line below allows us to load the isProperFraction function into tests in other files. @@ -31,3 +44,15 @@ function assertEquals(actualOutput, targetOutput) { // Example: 1/2 is a proper fraction assertEquals(isProperFraction(1, 2), true); + +assertEquals(isProperFraction(2, 1), false); + +assertEquals(isProperFraction(0, 1), true); + +assertEquals(isProperFraction(1, 0), false); + +assertEquals(isProperFraction(-1, 2), true); + +assertEquals(isProperFraction(1, -2), false); + +assertEquals(isProperFraction(-1, -2), true); \ No newline at end of file From df757217d2cec820dd1f4e8d80a358f4439ae855 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Thu, 16 Jul 2026 23:45:25 +0100 Subject: [PATCH 6/6] Add tests for angle classification in getAngleType function --- .../implement/1-get-angle-type.js | 21 +++++++++++++++++++ 1 file changed, 21 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..1d8214741c 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 @@ -35,3 +35,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 invalidLow = getAngleType(-10); +assertEquals(invalidLow, "Invalid angle"); + +const invalidHigh = getAngleType(400); +assertEquals(invalidHigh, "Invalid angle"); + + +