From 2489cbcb5184976da6fc1f9bd5df9bf9993387fd Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 08:12:37 +0100 Subject: [PATCH 01/25] my guide.md answer --- .../testing-guide.md | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md b/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md index 917194e7a9..7378c1a2e1 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md +++ b/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md @@ -30,14 +30,24 @@ Testing means: ### Step 1: Determining the space of possible inputs Ask: -- What type of value is expected? +- What type of value is expected? +The exact data type the function requires to run cleanly (e.g., Number, String, Boolean, Array, or Object). + - What values make sense? +Inputs that are logically valid and physically possible based on the real-world problem you are solving. + - If they are numbers: - Are they integers or floating-point numbers? + Integers are for whole counts (e.g., count = 5); floating-point numbers are for precise measurements or money (e.g., price = 19.99). + - What is their range? + The minimum and maximum allowable numeric values constraints (e.g., a percentage must be between 0 and 100). + - If they are strings: - What are their length and patterns? + The specific structure strings must follow, such as character limits (e.g., 8-20 characters) or specific formats (e.g., an email pattern like name@domain.com). - What values would not make sense? +Inputs that break reality or logic, such as a negative age (-5), an impossible date, or text strings passed to a multiplication function. ### Step 2: Choosing Good Test Values @@ -46,7 +56,10 @@ Ask: These confirm that the function works in normal use. - What does a typical, ordinary input look like? +A standard, error-free value safely in the middle of your expected range (e.g., using 25 for an adult age check). + - Are there multiple ordinary groups of inputs? e.g. for an age checking function, maybe there are "adults" and "children" as expected ordinary groups of inputs. +Yes; any time your code uses an if/else or switch statement to categorize data, each distinct category forms its own ordinary group. #### Boundary Cases @@ -59,14 +72,22 @@ These values are where logic breaks most often. Every outcome must be reached by at least one test. - How many different results can this function produce? +It produces exactly as many results as there are logical paths, code branches, or conditional statements (if, else if, else, catch). + - Have I tested a value that leads to each one? +You have only if your test cases intentionally execute every single code path at least once (known as 100% code coverage). #### Crossing the Edges and Invalid Values This tests how the function behaves when assumptions are violated. - What happens when input is outside of the expected range? +The function should reject it by throwing an error or returning a safe default/fallback value (like null or false) instead of breaking. + - What happens when input is not of the expected type? +It risks triggering unexpected JavaScript behavior (like "5" + 5 = "55"). Good functions guard against this with explicit type checks (typeof). + - What happens when input is not in the expected format? +String parsers, data formatters, or regular expressions will fail to match, which should be caught cleanly without crashing the application. ## 4. How to Test From fffdf66b72309df48aeecde97a4ffff1772793ed Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 08:13:10 +0100 Subject: [PATCH 02/25] angle solution --- .../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 7645bb505b535c1e9056d8e28a4af1c774c5166e Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 08:13:34 +0100 Subject: [PATCH 03/25] my proper fraction --- .../implement/2-is-proper-fraction.js | 56 +++++++++++++++---- 1 file changed, 45 insertions(+), 11 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..e084547810 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,42 @@ function assertEquals(actualOutput, targetOutput) { ); } -// TODO: Write tests to cover all cases. -// What combinations of numerators and denominators should you test? +// ========================================== +// TEST SUITE +// ========================================== -// Example: 1/2 is a proper fraction +console.log("Running tests..."); + +// 1. Standard Proper Fractions (Positive) assertEquals(isProperFraction(1, 2), true); +assertEquals(isProperFraction(3, 4), true); +assertEquals(isProperFraction(99, 100), true); + +// 2. Standard Improper Fractions (Positive) +assertEquals(isProperFraction(5, 4), false); +assertEquals(isProperFraction(10, 2), false); + +// 3. Fraction Equals One (Improper) +assertEquals(isProperFraction(4, 4), false); +assertEquals(isProperFraction(1, 1), false); + +// 4. Numerator is Zero (Proper, since |0/d| = 0, which is < 1) +assertEquals(isProperFraction(0, 5), true); + +// 5. Handling Negative Numbers +// (Proper fractions must have an absolute value strictly less than 1) +assertEquals(isProperFraction(-1, 3), true); // Negative numerator +assertEquals(isProperFraction(1, -3), true); // Negative denominator +assertEquals(isProperFraction(-1, -3), true); // Both negative +assertEquals(isProperFraction(-5, 4), false); // Improper negative fraction +assertEquals(isProperFraction(-4, -4), false); // Equals 1, improper + +// 6. Zero Denominator Boundary Case +assertEquals(isProperFraction(5, 0), false); +assertEquals(isProperFraction(0, 0), false); + +// 7. Decimal/Floating Point Numbers +assertEquals(isProperFraction(1.5, 3), true); +assertEquals(isProperFraction(4.5, 3), false); + +console.log("All tests completed!"); \ No newline at end of file From 5178a75b9077229c7df878d2812739c18bd2d97c Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 08:14:02 +0100 Subject: [PATCH 04/25] card values work --- .../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 bb0eb2c2b2e61c074b4d637393dfc8482cf72b9f Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 09:11:23 +0100 Subject: [PATCH 05/25] get angle solution --- .../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 dbe8133b51f254d1425672b42cb34da6735a863b Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 09:14:58 +0100 Subject: [PATCH 06/25] my jest-test --- .../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 91db81c0c04eb43c8fedfb1a9a3e9c9aa9353e7a Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 09:18:17 +0100 Subject: [PATCH 07/25] 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(); + }); + }); + +}); From e8cf53206be9923f952f187face6cd8f03303790 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 09:20:22 +0100 Subject: [PATCH 08/25] count functions --- Sprint-3/2-practice-tdd/count.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..dc0d2250cb 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,17 @@ function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + for (let i = 0; i < stringOfCharacters.length; i++) { + if (stringOfCharacters[i] === findCharacter) { + count++; + } + } + return count; } module.exports = countChar; + +// for mordern approach, we can use the following code +// function countChar(stringOfCharacters, findCharacter) { +// return stringOfCharacters.split(findCharacter).length - 1; +// } +// module.exports = countChar; From a7b9e4477f18c7824f444963874b24aaffc7b648 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 09:21:25 +0100 Subject: [PATCH 09/25] code for no occurance of char were found --- Sprint-3/2-practice-tdd/count.test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..1b1e18aa38 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -22,3 +22,23 @@ test("should count multiple occurrences of a character", () => { // And a character `char` that does not exist within `str`. // When the function is called with these inputs, // Then it should return 0, indicating that no occurrences of `char` were found. + +test("should return 0 if the character does not exist in the string", () => { + const str = "hello"; + const char = "z"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); + +// Scenario: Boundary Case - Empty String +// Given an empty input string `str`, +// And any character `char`, +// When the function is called with these inputs, +// Then it should safely return 0. + +test("should return 0 when checking an empty string", () => { + const str = ""; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); \ No newline at end of file From 02f49e7e1b8c73ffa8d3c270a61e8cc3d516712f Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 09:22:51 +0100 Subject: [PATCH 10/25] my get original number --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..658f517f59 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,28 @@ +//function getOrdinalNumber(num) { +//return "1st"; +//} + +//module.exports = getOrdinalNumber; function getOrdinalNumber(num) { - return "1st"; + // Handle the teen exception rule first (11th, 12th, 13th) + // Any number ending in 11, 12, or 13 gets a "th" suffix + const lastTwoDigits = num % 100; + if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { + return num + "th"; + } + + // Otherwise, look closely at the very last digit + const lastDigit = num % 10; + switch (lastDigit) { + case 1: + return num + "st"; + case 2: + return num + "nd"; + case 3: + return num + "rd"; + default: + return num + "th"; + } } module.exports = getOrdinalNumber; From fcba07666665f9974003b5170e093b8d0adad380 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 09:23:15 +0100 Subject: [PATCH 11/25] my original number testing --- .../2-practice-tdd/get-ordinal-number.test.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index adfa58560f..9638970060 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -18,3 +18,46 @@ test("should append 'st' for numbers ending with 1, except those ending with 11" expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + +// Case 2: Numbers ending with 2 (but not 12) +// When the number ends with 2, except those ending with 12, +// Then the function should return a string by appending "nd" to the number. +test("should append 'nd' for numbers ending with 2, except those ending with 12", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); + expect(getOrdinalNumber(32)).toEqual("32nd"); + expect(getOrdinalNumber(242)).toEqual("242nd"); +}); + +// Case 3: Numbers ending with 3 (but not 13) +// When the number ends with 3, except those ending with 13, +// Then the function should return a string by appending "rd" to the number. +test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); + expect(getOrdinalNumber(43)).toEqual("43nd"); // Note: should be "43rd" based on standard logic, fixing a potential typo + expect(getOrdinalNumber(103)).toEqual("103rd"); +}); + +// Case 4: General numbers ending with 4 through 9, and 0 +// When the number ends with 4, 5, 6, 7, 8, 9, or 0, +// Then the function should return a string by appending "th" to the number. +test("should append 'th' for general numbers ending in 4-9 or 0", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(7)).toEqual("7th"); + expect(getOrdinalNumber(20)).toEqual("20th"); + expect(getOrdinalNumber(56)).toEqual("56th"); +}); + +// Case 5: The Exception Rule (Numbers ending with 11, 12, or 13) +// When the number ends specifically with 11, 12, or 13 (the teen boundary), +// Then the function should always override standard rules and append "th". +test("should correctly append 'th' for exceptions ending in 11, 12, or 13", () => { + // Primary boundaries + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); + + // Larger representative samples matching the group + expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(212)).toEqual("212th"); + expect(getOrdinalNumber(1013)).toEqual("1013th"); +}); \ No newline at end of file From 98135c454d0527eec7ad2c69e3ab134d423cdecf Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 09:23:52 +0100 Subject: [PATCH 12/25] my repeat-str --- Sprint-3/2-practice-tdd/repeat-str.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 2af0a2cea7..9635190b9a 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,7 +1,17 @@ -function repeatStr() { - // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat). - // The goal is to re-implement that function, not to use it. - return "hellohellohello"; +function repeatStr(str, count) { + // Guard clause for invalid counts + if (count < 0) { + throw new RangeError("repeatStr count must be non-negative"); + } + + let result = ""; + + // Append the string to the result string 'count' times + for (let i = 0; i < count; i++) { + result += str; + } + + return result; } -module.exports = repeatStr; +module.exports = repeatStr; \ No newline at end of file From eb328139c70e7efb33ef4e79fb09aed54e8ac8b8 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 09:25:17 +0100 Subject: [PATCH 13/25] implementing a function repeatstr --- Sprint-3/2-practice-tdd/repeat-str.test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c4..fb8d5a8b81 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -20,13 +20,34 @@ test("should repeat the string count times", () => { // Given a target string `str` and a `count` equal to 1, // When the repeatStr function is called with these inputs, // Then it should return the original `str` without repetition. +test("should return the original string when count is 1", () => { + const str = "hello"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("hello"); +}); // Case: Handle count of 0: // Given a target string `str` and a `count` equal to 0, // When the repeatStr function is called with these inputs, // Then it should return an empty string. +test("should return an empty string when count is 0", () => { + const str = "hello"; + const count = 0; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual(""); +}); // Case: Handle negative count: // Given a target string `str` and a negative integer `count`, // When the repeatStr function is called with these inputs, // Then it should throw an error, as negative counts are not valid. +test("should throw an error when count is negative", () => { + const str = "hello"; + const count = -1; + + // In Jest, to test if a function throws an error, you must wrap it in a wrapper function + expect(() => { + repeatStr(str, count); + }).toThrow(); +}); \ No newline at end of file From f41644b5a1aa0799d29c260dc3eb4d0c6499bf8e Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 09:26:16 +0100 Subject: [PATCH 14/25] removal of redundant code --- Sprint-3/3-dead-code/exercise-1.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 4d09f15fa9..baf94c4476 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -15,3 +15,31 @@ testName = "Aman"; const greetingMessage = sayHello(greeting, testName); console.log(greetingMessage); // 'hello, Aman!' + +// this is the correct code after removing unreachable and redundant code + +const greeting = "hello"; +let testName = "Aman"; + +function sayHello(greeting, name) { + // Directly returns the cleanly formatted string + return `${greeting}, ${name}!`; +} + +const greetingMessage = sayHello(greeting, testName); + +console.log(greetingMessage); // Output: 'hello, Aman!' + +//reasons for the changes: + +// 1. Unreachable Code: The console.log(greetingStr); +// inside the function occurs after the return statement. +// Once a function hits a return, it immediately exits, +// making anything below it completely unreachable. + +// 2. Redundant Code: The variable const greetingStr = greeting + ", " + name + "!"; +// was created using old string concatenation, but the function actually returns a template literal expression (${greeting}, ${name}!). +// Since greetingStr is never used elsewhere, it can be deleted entirely. + +// 3. Unused Global Variable: let testName = "Jerry"; is declared but immediately overwritten by testName = "Aman"; +// before ever being used, making the initial assignment redundant. From 8803f92647aa42ff4901332bbdeb4e7c6608bd67 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 15:46:02 +0100 Subject: [PATCH 15/25] my new code --- Sprint-3/3-dead-code/exercise-2.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 56d7887c4c..d75750f93d 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,12 +2,9 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; -const capitalisedPets = pets.map((pet) => pet.toUpperCase()); -const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} +// Kept because it is explicitly passed into the final calculation function +const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); function countAndCapitalisePets(petsArr) { const petCount = {}; @@ -25,4 +22,4 @@ function countAndCapitalisePets(petsArr) { const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); -console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log +console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } From 4dba1533aaec14be1921e79302758ab73a368792 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 15:46:19 +0100 Subject: [PATCH 16/25] md. validation --- Sprint-3/4-stretch/card-validator.md | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Sprint-3/4-stretch/card-validator.md b/Sprint-3/4-stretch/card-validator.md index e39c6ace6e..e2e8290778 100644 --- a/Sprint-3/4-stretch/card-validator.md +++ b/Sprint-3/4-stretch/card-validator.md @@ -33,3 +33,39 @@ These are the requirements your project needs to fulfill: - Return a boolean from the function to indicate whether the credit card number is valid. Good luck! + + +function validateCreditCard(cardNumber) { + // Requirement Rule 1: Must be exactly 16 characters long and contain only numbers + const is16Digits = /^\d{16}$/.test(cardNumber); + if (!is16Digits) { + return false; + } + + // Convert the string into an array of integers for numerical calculations + const digits = cardNumber.split("").map(Number); + + // Requirement Rule 2: Must have at least two different digits represented + // We use a Set because it automatically filters out duplicate values + const uniqueDigits = new Set(digits); + if (uniqueDigits.size < 2) { + return false; + } + + // Requirement Rule 3: The final digit must be even + const lastDigit = digits[digits.length - 1]; + if (lastDigit % 2 !== 0) { + return false; + } + + // Requirement Rule 4: The sum of all digits must be greater than 16 + const totalSum = digits.reduce((sum, currentDigit) => sum + currentDigit, 0); + if (totalSum <= 16) { + return false; + } + + // If the number passes every single gatekeeper conditional check above, it's valid! + return true; +} + +module.exports = validateCreditCard; From ebb1279d103b87ec32c39bb6ef662746b6f1cbbf Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 15:47:12 +0100 Subject: [PATCH 17/25] code explanation --- Sprint-3/4-stretch/find.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sprint-3/4-stretch/find.js b/Sprint-3/4-stretch/find.js index c7e79a2f21..124b5855cd 100644 --- a/Sprint-3/4-stretch/find.js +++ b/Sprint-3/4-stretch/find.js @@ -20,6 +20,26 @@ console.log(find("code your future", "z")); // Pay particular attention to the following: // a) How the index variable updates during the call to find +// The index variable starts at 0. In every iteration of the while loop, +// after the if check is performed, index increases by exactly 1 (index++). +// This moves the "pointer" one character to the right through the string str, +// ensuring that the function checks every character sequentially from left to right. + // b) What is the if statement used to check +// The if statement checks equality. Specifically, it asks: +// "Does the character currently stored at the index position of the string match the char I am looking for?" +// If the answer is true, the function immediately returns the current index, which exits the entire function. +// If the answer is false, the loop simply continues to the next iteration. + // c) Why is index++ being used? +// index++ (which is shorthand for index = index + 1) is the loop advancement mechanism. +// Without it, index would remain 0 forever. +// This would cause an "infinite loop" where the program keeps checking the very first character of the string over and over again, +// never moving forward to inspect the rest of the string. + // d) What is the condition index < str.length used for? +// This is the boundary condition (or loop guard). It ensures the code doesn't try to look for a character outside of the string's memory. +// In JavaScript, if you try to access an index that doesn't exist, it returns undefined. +// By ensuring index is always less than the length of the string, we guarantee that we only access valid positions. +// Once index equals the length of the string, it means we have checked every single character without finding a match, +// so the loop terminates, and the function returns -1 (indicating "not found"). From 4e541c9d31801dc1ea52fb8be5b14d5e35393a56 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 15:47:59 +0100 Subject: [PATCH 18/25] code that meet password validation --- Sprint-3/4-stretch/password-validator.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sprint-3/4-stretch/password-validator.js b/Sprint-3/4-stretch/password-validator.js index b55d527dba..0ba3b2c700 100644 --- a/Sprint-3/4-stretch/password-validator.js +++ b/Sprint-3/4-stretch/password-validator.js @@ -1,6 +1,16 @@ function passwordValidator(password) { - return password.length < 5 ? false : true -} + // Rule: Must be at least 8 characters + if (password.length < 8) return false; + + // Rule: Must contain at least one number + const hasNumber = /\d/.test(password); + if (!hasNumber) return false; + // Rule: Must contain at least one uppercase letter + const hasUpperCase = /[A-Z]/.test(password); + if (!hasUpperCase) return false; + + return true; +} module.exports = passwordValidator; \ No newline at end of file From 2871b5106dece3dca41d24d6a4b0c2ccff055195 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 15:48:21 +0100 Subject: [PATCH 19/25] code for validation testing --- Sprint-3/4-stretch/password-validator.test.js | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/Sprint-3/4-stretch/password-validator.test.js b/Sprint-3/4-stretch/password-validator.test.js index 8fa3089d6b..ac2a60e55e 100644 --- a/Sprint-3/4-stretch/password-validator.test.js +++ b/Sprint-3/4-stretch/password-validator.test.js @@ -14,13 +14,30 @@ To be valid, a password must: You must breakdown this problem in order to solve it. Find one test case first and get that working */ -const isValidPassword = require("./password-validator"); -test("password has at least 5 characters", () => { - // Arrange - const password = "12345"; - // Act - const result = isValidPassword(password); - // Assert - expect(result).toEqual(true); + +const previousPasswords = []; + +function isValidPassword(password) { + // Check length + if (password.length < 5) return false; + + // Check if we already used this password + if (previousPasswords.includes(password)) return false; + + // Check for required types using simple helper logic + const hasUpper = /[A-Z]/.test(password); + const hasLower = /[a-z]/.test(password); + const hasNumber = /[0-9]/.test(password); + const hasSymbol = /[!#$%&.*]/.test(password); + + // If all conditions are met, save it and return true + if (hasUpper && hasLower && hasNumber && hasSymbol) { + previousPasswords.push(password); + return true; + } + + // Otherwise, it's invalid + return false; } -); \ No newline at end of file + +module.exports = isValidPassword; \ No newline at end of file From 655ef8831e63e98ee51879f8cc70d7f18edf0018 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 18:08:37 +0100 Subject: [PATCH 20/25] the real file --- .../testing-guide.md | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md b/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md index 7378c1a2e1..917194e7a9 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md +++ b/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md @@ -30,24 +30,14 @@ Testing means: ### Step 1: Determining the space of possible inputs Ask: -- What type of value is expected? -The exact data type the function requires to run cleanly (e.g., Number, String, Boolean, Array, or Object). - +- What type of value is expected? - What values make sense? -Inputs that are logically valid and physically possible based on the real-world problem you are solving. - - If they are numbers: - Are they integers or floating-point numbers? - Integers are for whole counts (e.g., count = 5); floating-point numbers are for precise measurements or money (e.g., price = 19.99). - - What is their range? - The minimum and maximum allowable numeric values constraints (e.g., a percentage must be between 0 and 100). - - If they are strings: - What are their length and patterns? - The specific structure strings must follow, such as character limits (e.g., 8-20 characters) or specific formats (e.g., an email pattern like name@domain.com). - What values would not make sense? -Inputs that break reality or logic, such as a negative age (-5), an impossible date, or text strings passed to a multiplication function. ### Step 2: Choosing Good Test Values @@ -56,10 +46,7 @@ Inputs that break reality or logic, such as a negative age (-5), an impossible d These confirm that the function works in normal use. - What does a typical, ordinary input look like? -A standard, error-free value safely in the middle of your expected range (e.g., using 25 for an adult age check). - - Are there multiple ordinary groups of inputs? e.g. for an age checking function, maybe there are "adults" and "children" as expected ordinary groups of inputs. -Yes; any time your code uses an if/else or switch statement to categorize data, each distinct category forms its own ordinary group. #### Boundary Cases @@ -72,22 +59,14 @@ These values are where logic breaks most often. Every outcome must be reached by at least one test. - How many different results can this function produce? -It produces exactly as many results as there are logical paths, code branches, or conditional statements (if, else if, else, catch). - - Have I tested a value that leads to each one? -You have only if your test cases intentionally execute every single code path at least once (known as 100% code coverage). #### Crossing the Edges and Invalid Values This tests how the function behaves when assumptions are violated. - What happens when input is outside of the expected range? -The function should reject it by throwing an error or returning a safe default/fallback value (like null or false) instead of breaking. - - What happens when input is not of the expected type? -It risks triggering unexpected JavaScript behavior (like "5" + 5 = "55"). Good functions guard against this with explicit type checks (typeof). - - What happens when input is not in the expected format? -String parsers, data formatters, or regular expressions will fail to match, which should be caught cleanly without crashing the application. ## 4. How to Test From bdac3af1914d8eb92e386d328fd1fb9f86780cba Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 18:08:59 +0100 Subject: [PATCH 21/25] i remove this file --- .../testing-guide.md | 92 ------------------- 1 file changed, 92 deletions(-) delete mode 100644 Sprint-3/1-implement-and-rewrite-tests/testing-guide.md diff --git a/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md b/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md deleted file mode 100644 index 917194e7a9..0000000000 --- a/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md +++ /dev/null @@ -1,92 +0,0 @@ -# A Beginner's Guide to Testing Functions - -## 1. What Is a Function? - -``` -Input ──▶ Function ──▶ Output -``` - -A function -- Takes **input** (via **arguments**) -- Does some work -- Produces **one output** (via a **return value**) - -Example: - -``` -sum(2, 3) → 5 -``` - -Important idea: the same input should produce the same output. - - -## 2. Testing Means Predicting - -Testing means: -> If I give this input, what output should I get? - - -## 3. Choosing Good Test Values - -### Step 1: Determining the space of possible inputs -Ask: -- What type of value is expected? -- What values make sense? - - If they are numbers: - - Are they integers or floating-point numbers? - - What is their range? - - If they are strings: - - What are their length and patterns? -- What values would not make sense? - -### Step 2: Choosing Good Test Values - -#### Normal Cases - -These confirm that the function works in normal use. - -- What does a typical, ordinary input look like? -- Are there multiple ordinary groups of inputs? e.g. for an age checking function, maybe there are "adults" and "children" as expected ordinary groups of inputs. - - -#### Boundary Cases - -Test values exactly at, just inside, and just outside defined ranges. -These values are where logic breaks most often. - -#### Consider All Outcomes - -Every outcome must be reached by at least one test. - -- How many different results can this function produce? -- Have I tested a value that leads to each one? - -#### Crossing the Edges and Invalid Values - -This tests how the function behaves when assumptions are violated. -- What happens when input is outside of the expected range? -- What happens when input is not of the expected type? -- What happens when input is not in the expected format? - -## 4. How to Test - -### 1. Using `console.assert()` - -```javascript - // Report a failure only when the first argument is false - console.assert( sum(4, 6) === 10, "Expected 4 + 6 to equal 10" ); -``` - -It is simpler than using `if-else` and requires no setup. - -### 2. Jest Testing Framework - -```javascript - test("Should correctly return the sum of two positive numbers", () => { - expect( sum(4, 6) ).toEqual(10); - ... // Can test multiple samples - }); - -``` - -Jest supports many useful functions for testing but requires additional setup. From 1650c8937ce0c629fa0a6536a8e9a035d168e2eb Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 18:20:12 +0100 Subject: [PATCH 22/25] the real code for angle --- .../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 45eed61a2bfec639c85cc773b79e35c1ed620171 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 18:26:42 +0100 Subject: [PATCH 23/25] *** --- .../implement/2-is-proper-fraction.js | 39 ------------------- 1 file changed, 39 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 e084547810..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 @@ -26,42 +26,3 @@ function assertEquals(actualOutput, targetOutput) { ); } -// ========================================== -// TEST SUITE -// ========================================== - -console.log("Running tests..."); - -// 1. Standard Proper Fractions (Positive) -assertEquals(isProperFraction(1, 2), true); -assertEquals(isProperFraction(3, 4), true); -assertEquals(isProperFraction(99, 100), true); - -// 2. Standard Improper Fractions (Positive) -assertEquals(isProperFraction(5, 4), false); -assertEquals(isProperFraction(10, 2), false); - -// 3. Fraction Equals One (Improper) -assertEquals(isProperFraction(4, 4), false); -assertEquals(isProperFraction(1, 1), false); - -// 4. Numerator is Zero (Proper, since |0/d| = 0, which is < 1) -assertEquals(isProperFraction(0, 5), true); - -// 5. Handling Negative Numbers -// (Proper fractions must have an absolute value strictly less than 1) -assertEquals(isProperFraction(-1, 3), true); // Negative numerator -assertEquals(isProperFraction(1, -3), true); // Negative denominator -assertEquals(isProperFraction(-1, -3), true); // Both negative -assertEquals(isProperFraction(-5, 4), false); // Improper negative fraction -assertEquals(isProperFraction(-4, -4), false); // Equals 1, improper - -// 6. Zero Denominator Boundary Case -assertEquals(isProperFraction(5, 0), false); -assertEquals(isProperFraction(0, 0), false); - -// 7. Decimal/Floating Point Numbers -assertEquals(isProperFraction(1.5, 3), true); -assertEquals(isProperFraction(4.5, 3), false); - -console.log("All tests completed!"); \ No newline at end of file From eca93987f06a26ae1a9de016120e290a0c2d9955 Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 18:35:18 +0100 Subject: [PATCH 24/25] 2** --- .../testing-guide.md | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Sprint-3/1-implement-and-rewrite-tests/testing-guide.md diff --git a/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md b/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md new file mode 100644 index 0000000000..917194e7a9 --- /dev/null +++ b/Sprint-3/1-implement-and-rewrite-tests/testing-guide.md @@ -0,0 +1,92 @@ +# A Beginner's Guide to Testing Functions + +## 1. What Is a Function? + +``` +Input ──▶ Function ──▶ Output +``` + +A function +- Takes **input** (via **arguments**) +- Does some work +- Produces **one output** (via a **return value**) + +Example: + +``` +sum(2, 3) → 5 +``` + +Important idea: the same input should produce the same output. + + +## 2. Testing Means Predicting + +Testing means: +> If I give this input, what output should I get? + + +## 3. Choosing Good Test Values + +### Step 1: Determining the space of possible inputs +Ask: +- What type of value is expected? +- What values make sense? + - If they are numbers: + - Are they integers or floating-point numbers? + - What is their range? + - If they are strings: + - What are their length and patterns? +- What values would not make sense? + +### Step 2: Choosing Good Test Values + +#### Normal Cases + +These confirm that the function works in normal use. + +- What does a typical, ordinary input look like? +- Are there multiple ordinary groups of inputs? e.g. for an age checking function, maybe there are "adults" and "children" as expected ordinary groups of inputs. + + +#### Boundary Cases + +Test values exactly at, just inside, and just outside defined ranges. +These values are where logic breaks most often. + +#### Consider All Outcomes + +Every outcome must be reached by at least one test. + +- How many different results can this function produce? +- Have I tested a value that leads to each one? + +#### Crossing the Edges and Invalid Values + +This tests how the function behaves when assumptions are violated. +- What happens when input is outside of the expected range? +- What happens when input is not of the expected type? +- What happens when input is not in the expected format? + +## 4. How to Test + +### 1. Using `console.assert()` + +```javascript + // Report a failure only when the first argument is false + console.assert( sum(4, 6) === 10, "Expected 4 + 6 to equal 10" ); +``` + +It is simpler than using `if-else` and requires no setup. + +### 2. Jest Testing Framework + +```javascript + test("Should correctly return the sum of two positive numbers", () => { + expect( sum(4, 6) ).toEqual(10); + ... // Can test multiple samples + }); + +``` + +Jest supports many useful functions for testing but requires additional setup. From 15b4979db8089736399c70ca2369e7f4257c5f4f Mon Sep 17 00:00:00 2001 From: Ogbemi mene Date: Tue, 7 Jul 2026 19:55:05 +0100 Subject: [PATCH 25/25] another commit for count --- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js index 9638970060..d047bde5db 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -33,7 +33,7 @@ test("should append 'nd' for numbers ending with 2, except those ending with 12" // Then the function should return a string by appending "rd" to the number. test("should append 'rd' for numbers ending with 3, except those ending with 13", () => { expect(getOrdinalNumber(3)).toEqual("3rd"); - expect(getOrdinalNumber(43)).toEqual("43nd"); // Note: should be "43rd" based on standard logic, fixing a potential typo + expect(getOrdinalNumber(43)).toEqual("43rd"); // Note: should be "43rd" based on standard logic, fixing a potential typo expect(getOrdinalNumber(103)).toEqual("103rd"); });