From d9ca97ab072a477086693467c6119fe6f9b96a12 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 18:16:07 +0100 Subject: [PATCH 1/7] my angle-type changes --- .../implement/1-get-angle-type.js | 62 +++++++++++++++---- 1 file changed, 50 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 9e05a871e2..fcf81f2259 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 @@ -10,28 +10,66 @@ // Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. - 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. -// This will be useful in the "rewrite tests with jest" step. module.exports = getAngleType; // This helper function is written to make our assertions easier to read. -// If the actual output matches the target output, the test will pass function assertEquals(actualOutput, targetOutput) { console.assert( actualOutput === targetOutput, - `Expected ${actualOutput} to equal ${targetOutput}` + `Expected "${actualOutput}" to equal "${targetOutput}"` ); } -// TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles -const right = getAngleType(90); -assertEquals(right, "Right angle"); +// ========================================== +// TEST SUITE +// ========================================== + +console.log("Running tests..."); + +// 1. Invalid Angles (Lower Bound & Below) +assertEquals(getAngleType(-15), "Invalid angle"); +assertEquals(getAngleType(0), "Invalid angle"); + +// 2. Acute Angles +assertEquals(getAngleType(1), "Acute angle"); +assertEquals(getAngleType(45), "Acute angle"); +assertEquals(getAngleType(89.9), "Acute angle"); + +// 3. Right Angle +assertEquals(getAngleType(90), "Right angle"); + +// 4. Obtuse Angles +assertEquals(getAngleType(90.1), "Obtuse angle"); +assertEquals(getAngleType(135), "Obtuse angle"); +assertEquals(getAngleType(179.9), "Obtuse angle"); + +// 5. Straight Angle +assertEquals(getAngleType(180), "Straight angle"); + +// 6. Reflex Angles +assertEquals(getAngleType(180.1), "Reflex angle"); +assertEquals(getAngleType(270), "Reflex angle"); +assertEquals(getAngleType(359.9), "Reflex angle"); + +// 7. Invalid Angles (Upper Bound & Above) +assertEquals(getAngleType(360), "Invalid angle"); +assertEquals(getAngleType(400), "Invalid angle"); + +console.log("All tests completed!"); \ No newline at end of file From cbcf5c2ac898230edb1f0152a5f043371bdad070 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 18:21:45 +0100 Subject: [PATCH 2/7] my proper code for angles --- .../implement/1-get-angle-type.js | 36 ------------------- 1 file changed, 36 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 fcf81f2259..945fa68e55 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 @@ -37,39 +37,3 @@ function assertEquals(actualOutput, targetOutput) { ); } -// ========================================== -// TEST SUITE -// ========================================== - -console.log("Running tests..."); - -// 1. Invalid Angles (Lower Bound & Below) -assertEquals(getAngleType(-15), "Invalid angle"); -assertEquals(getAngleType(0), "Invalid angle"); - -// 2. Acute Angles -assertEquals(getAngleType(1), "Acute angle"); -assertEquals(getAngleType(45), "Acute angle"); -assertEquals(getAngleType(89.9), "Acute angle"); - -// 3. Right Angle -assertEquals(getAngleType(90), "Right angle"); - -// 4. Obtuse Angles -assertEquals(getAngleType(90.1), "Obtuse angle"); -assertEquals(getAngleType(135), "Obtuse angle"); -assertEquals(getAngleType(179.9), "Obtuse angle"); - -// 5. Straight Angle -assertEquals(getAngleType(180), "Straight angle"); - -// 6. Reflex Angles -assertEquals(getAngleType(180.1), "Reflex angle"); -assertEquals(getAngleType(270), "Reflex angle"); -assertEquals(getAngleType(359.9), "Reflex angle"); - -// 7. Invalid Angles (Upper Bound & Above) -assertEquals(getAngleType(360), "Invalid angle"); -assertEquals(getAngleType(400), "Invalid angle"); - -console.log("All tests completed!"); \ No newline at end of file From 0879919b72d64e5f5981b198ba1e827721a3b970 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 18:27:41 +0100 Subject: [PATCH 3/7] code for proper fraction --- .../implement/2-is-proper-fraction.js | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 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..905a6907e0 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 @@ -4,18 +4,18 @@ // Assumption: The parameters are valid numbers (not NaN or Infinity). -// Note: If you are unfamiliar with proper fractions, please look up its mathematical definition. - -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. - function isProperFraction(numerator, denominator) { - // TODO: Implement this function + // A denominator of 0 is mathematically undefined, so it cannot be a proper fraction. + if (denominator === 0) { + return false; + } + + // A fraction is proper if the absolute value of the numerator + // is strictly less than the absolute value of the denominator. + return Math.abs(numerator) < Math.abs(denominator); } // 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; // Here's our helper again @@ -26,8 +26,3 @@ function assertEquals(actualOutput, targetOutput) { ); } -// TODO: Write tests to cover all cases. -// What combinations of numerators and denominators should you test? - -// Example: 1/2 is a proper fraction -assertEquals(isProperFraction(1, 2), true); From 0e4fe226657fe5dc11bec39e38f94d3a5cd38ed9 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 18:37:46 +0100 Subject: [PATCH 4/7] my card changes --- .../implement/3-get-card-value.js | 108 ++++++++++++------ 1 file changed, 75 insertions(+), 33 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 ff5c532e1d..3b19476101 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 @@ -1,35 +1,50 @@ -// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck - // Implement a function getCardValue, when given a string representing a playing card, // should return the numerical value of the card. -// A valid card string will contain a rank followed by the suit. -// The rank can be one of the following strings: -// "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" -// The suit can be one of the following emojis: -// "♠", "♥", "♦", "♣" -// For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦". +function getCardValue(card) { + // Validate that input is a non-empty string and has at least 2 characters (Rank + Suit) + if (typeof card !== "string" || card.length < 2) { + throw new Error("Invalid card format"); + } + + // Define valid suits + const validSuits = ["♠", "♥", "♦", "♣"]; -// When the card is an ace ("A"), the function should return 11. -// When the card is a face card ("J", "Q", "K"), the function should return 10. -// When the card is a number card ("2" to "10"), the function should return its numeric value. + // The suit is always the last character/emoji of the string. + // Using Array.from() or string methods safely extracts it. + const suit = card.slice(-1); + if (!validSuits.includes(suit)) { + throw new Error("Invalid card suit"); + } -// When the card string is invalid (not following the above format), the function should -// throw an error. + // The rank is everything up to the suit emoji. + const rank = card.slice(0, -1); -// Acceptance criteria: -// After you have implemented the function, write tests to cover all the cases, and -// execute the code to ensure all tests pass. + // Handle value mappings + if (rank === "A") { + return 11; + } + + if (["J", "Q", "K"].includes(rank)) { + return 10; + } -function getCardValue(card) { - // TODO: Implement this function + // Parse numeric ranks ("2" through "10") + const numericValue = parseInt(rank, 10); + if (!isNaN(numericValue) && numericValue >= 2 && numericValue <= 10 && String(numericValue) === rank) { + return numericValue; + } + + // If the rank doesn't match any criteria, it's invalid. + throw new Error("Invalid card rank"); } -// The line below allows us to load the getCardValue function into tests in other files. -// This will be useful in the "rewrite tests with jest" step. module.exports = getCardValue; -// Helper functions to make our assertions easier to read. +// ========================================== +// ASSERTION HELPERS +// ========================================== + function assertEquals(actualOutput, targetOutput) { console.assert( actualOutput === targetOutput, @@ -37,18 +52,45 @@ function assertEquals(actualOutput, targetOutput) { ); } -// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// Examples: -assertEquals(getCardValue("9♠"), 9); +// A helper to verify that an invalid input throws an error as expected +function assertThrows(invalidCard) { + try { + getCardValue(invalidCard); + console.error(`❌ Error was NOT thrown for invalid card: "${invalidCard}"`); + } catch (e) { + // Test passes if an error is thrown + } +} -// Handling invalid cards -try { - getCardValue("invalid"); +// ========================================== +// TEST SUITE +// ========================================== - // 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 🎉"); -} +console.log("Running tests..."); + +// 1. Valid Aces (Value: 11) +assertEquals(getCardValue("A♠"), 11); +assertEquals(getCardValue("A♥"), 11); + +// 2. Valid Face Cards (Value: 10) +assertEquals(getCardValue("J♣"), 10); +assertEquals(getCardValue("Q♦"), 10); +assertEquals(getCardValue("K♠"), 10); + +// 3. Valid Numeric Boundary Cards +assertEquals(getCardValue("2♥"), 2); +assertEquals(getCardValue("5♦"), 5); +assertEquals(getCardValue("9♠"), 9); +assertEquals(getCardValue("10♣"), 10); + +// 4. Invalid Card Scenarios (Should throw errors) +assertThrows("invalid"); // Completely wrong format +assertThrows("A"); // Missing suit +assertThrows("♠"); // Missing rank +assertThrows("1♠"); // 1 is not a valid rank (should be "A") +assertThrows("11♥"); // Out-of-bounds number card +assertThrows("A♣️"); // Suit variations or hidden characters +assertThrows("Q⭐️"); // Invalid suit emoji +assertThrows("J ♠"); // Unwanted spacing -// What other invalid card cases can you think of? +console.log("All tests completed!"); \ No newline at end of file From 1df0a8beba0f6e2c6d8c0f1b316d2ffd05cb5edd Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 18:44:50 +0100 Subject: [PATCH 5/7] valid angle type --- .../1-get-angle-type.test.js | 61 ++++++++++++++----- 1 file changed, 47 insertions(+), 14 deletions(-) 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..60eeb470f9 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 @@ -2,19 +2,52 @@ // We will use the same function, but write tests for it using Jest in this file. const getAngleType = require("../implement/1-get-angle-type"); -// TODO: Write tests in Jest syntax to cover all cases/outcomes, -// including boundary and invalid cases. +describe("getAngleType", () => { + + // Case 1: Acute angles + test('should return "Acute angle" when (0 < angle < 90)', () => { + expect(getAngleType(1)).toBe("Acute angle"); + expect(getAngleType(45)).toBe("Acute angle"); + expect(getAngleType(89.9)).toBe("Acute angle"); + }); -// Case 1: Acute angles -test(`should return "Acute angle" when (0 < angle < 90)`, () => { - // Test various acute angles, including boundary cases - expect(getAngleType(1)).toEqual("Acute angle"); - expect(getAngleType(45)).toEqual("Acute angle"); - expect(getAngleType(89)).toEqual("Acute angle"); -}); + // Case 2: Right angle + test('should return "Right angle" when angle is exactly 90', () => { + expect(getAngleType(90)).toBe("Right angle"); + }); -// Case 2: Right angle -// Case 3: Obtuse angles -// Case 4: Straight angle -// Case 5: Reflex angles -// Case 6: Invalid angles + // Case 3: Obtuse angles + test('should return "Obtuse angle" when (90 < angle < 180)', () => { + expect(getAngleType(90.1)).toBe("Obtuse angle"); + expect(getAngleType(135)).toBe("Obtuse angle"); + expect(getAngleType(179.9)).toBe("Obtuse angle"); + }); + + // Case 4: Straight angle + test('should return "Straight angle" when angle is exactly 180', () => { + expect(getAngleType(180)).toBe("Straight angle"); + }); + + // Case 5: Reflex angles + test('should return "Reflex angle" when (180 < angle < 360)', () => { + expect(getAngleType(180.1)).toBe("Reflex angle"); + expect(getAngleType(270)).toBe("Reflex angle"); + expect(getAngleType(359.9)).toBe("Reflex angle"); + }); + + // Case 6: Invalid angles + test('should return "Invalid angle" for angles outside the 0 to 360 range', () => { + // Negative angles + expect(getAngleType(-45)).toBe("Invalid angle"); + + // Lower boundary + expect(getAngleType(0)).toBe("Invalid angle"); + + // Upper boundary + expect(getAngleType(360)).toBe("Invalid angle"); + + // Exceeding upper boundary + expect(getAngleType(361)).toBe("Invalid angle"); + }); + +}); \ No newline at end of file From 6c83c12602c0e1daf4714c2d0c24a0921e22bc9a Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 18:47:46 +0100 Subject: [PATCH 6/7] properfraction code --- .../2-is-proper-fraction.test.js | 49 +++++++++++++++++-- 1 file changed, 45 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 7f087b2ba1..81e52b88b2 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,50 @@ // 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. +describe("isProperFraction", () => { + + // 1. Positive Proper Fractions + test("should return true for positive proper fractions (numerator < denominator)", () => { + expect(isProperFraction(1, 2)).toBe(true); + expect(isProperFraction(3, 4)).toBe(true); + expect(isProperFraction(99, 100)).toBe(true); + }); + + // 2. Positive Improper Fractions + test("should return false for positive improper fractions (numerator >= denominator)", () => { + expect(isProperFraction(5, 4)).toBe(false); + expect(isProperFraction(10, 2)).toBe(false); + expect(isProperFraction(4, 4)).toBe(false); // Exactly 1 + }); + + // 3. Zero Cases + test("should return false when denominator is zero", () => { + expect(isProperFraction(1, 0)).toBe(false); + expect(isProperFraction(0, 0)).toBe(false); + }); + + test("should return true when numerator is zero and denominator is non-zero", () => { + expect(isProperFraction(0, 5)).toBe(true); + expect(isProperFraction(0, -5)).toBe(true); + }); + + // 4. Negative Fractions + test("should evaluate proper fractions correctly when negative signs are present", () => { + expect(isProperFraction(-1, 3)).toBe(true); // Negative numerator + expect(isProperFraction(1, -3)).toBe(true); // Negative denominator + expect(isProperFraction(-1, -3)).toBe(true); // Both negative + }); + + test("should evaluate improper fractions correctly when negative signs are present", () => { + expect(isProperFraction(-5, 4)).toBe(false); // Magnitude > 1 + expect(isProperFraction(5, -4)).toBe(false); // Magnitude > 1 + expect(isProperFraction(-4, -4)).toBe(false); // Magnitude = 1 + }); + + // 5. Decimals / Floating Point Numbers + test("should handle decimal inputs using absolute magnitude values", () => { + expect(isProperFraction(1.5, 3)).toBe(true); + expect(isProperFraction(4.5, 3)).toBe(false); + }); -// Special case: numerator is zero -test(`should return false when denominator is zero`, () => { - expect(isProperFraction(1, 0)).toEqual(false); }); From 0f1412648fb619c8c72d746234b34c2dbe18da88 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 18:53:43 +0100 Subject: [PATCH 7/7] card value --- .../3-get-card-value.test.js | 78 +++++++++++++++---- 1 file changed, 65 insertions(+), 13 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..49027d7d9c 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 @@ -1,20 +1,72 @@ // This statement loads the getCardValue function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. +// We will use the same function, but write tests for it using Jest in this file const getCardValue = require("../implement/3-get-card-value"); -// TODO: Write tests in Jest syntax to cover all possible outcomes. +describe("getCardValue", () => { -// Case 1: Ace (A) -test(`Should return 11 when given an ace card`, () => { - expect(getCardValue("A♠")).toEqual(11); -}); + // Case 1: Aces + test("Should return 11 when given an ace card", () => { + expect(getCardValue("A♠")).toBe(11); + expect(getCardValue("A♥")).toBe(11); + expect(getCardValue("A♦")).toBe(11); + expect(getCardValue("A♣")).toBe(11); + }); + + // Case 2: Number Cards (2-10) + describe("Number Cards (2-10)", () => { + test("should return the exact numeric value for standard cards", () => { + expect(getCardValue("2♥")).toBe(2); + expect(getCardValue("5♦")).toBe(5); + expect(getCardValue("9♠")).toBe(9); + }); + + test("should correctly parse the two-digit boundary card 10", () => { + expect(getCardValue("10♣")).toBe(10); + expect(getCardValue("10♦")).toBe(10); + }); + }); + + // Case 3: Face Cards (J, Q, K) + describe("Face Cards (J, Q, K)", () => { + test("should return 10 for Jacks (J)", () => { + expect(getCardValue("J♣")).toBe(10); + }); + + test("should return 10 for Queens (Q)", () => { + expect(getCardValue("Q♦")).toBe(10); + }); -// Suggestion: Group the remaining test data into these categories: -// Number Cards (2-10) -// Face Cards (J, Q, K) -// Invalid Cards + test("should return 10 for Kings (K)", () => { + expect(getCardValue("K♠")).toBe(10); + }); + }); -// 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 + // Case 4: Invalid Cards (Error Handling) + describe("Invalid Cards", () => { + // Note: When testing exceptions in Jest, wrap the execution in an anonymous function. + test("should throw an error for text strings unrelated to cards", () => { + expect(() => getCardValue("invalid")).toThrow(); + }); + test("should throw an error if missing the rank or the suit", () => { + expect(() => getCardValue("A")).toThrow(); + expect(() => getCardValue("♠")).toThrow(); + }); + + test("should throw an error for numeric values out of boundaries", () => { + expect(() => getCardValue("1♠")).toThrow(); // Should be an Ace + expect(() => getCardValue("11♥")).toThrow(); // Invalid face range + expect(() => getCardValue("0♦")).toThrow(); // Zero baseline invalid + }); + + test("should throw an error for unsupported suits or symbols", () => { + expect(() => getCardValue("Q⭐️")).toThrow(); + expect(() => getCardValue("10X")).toThrow(); + }); + + test("should throw an error for spacing anomalies", () => { + expect(() => getCardValue("J ♠")).toThrow(); + }); + }); + +});