From f545cd32b13c7d78730a89e0eb2a3f084e20c385 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 12:52:56 +0100 Subject: [PATCH 01/15] Implement getAngleType function to determine angle types --- .../implement/1-get-angle-type.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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..ac053af89e 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -16,8 +16,20 @@ function getAngleType(angle) { // TODO: Implement this function + if (angle > 0 && angle < 90) { + return "Acute angle"; + } + if (angle === 90) return "Right angle"; + if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } + 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; From 60bae09b055eaa537e4ec1e4886c39617185ac11 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 12:54:38 +0100 Subject: [PATCH 02/15] add test to get angle --- .../1-get-angle-type.test.js | 22 +++++++++++++++++++ 1 file changed, 22 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..8f9347ddcf 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,29 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle +test(`should return "Right angle" when angle is 90`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); // Case 3: Obtuse angles +test(`should return "Obtuse angle" when angel is >90 & <180`, () => { + expect(getAngleType(100)).toEqual("Obtuse angle"); + expect(getAngleType(95)).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', () => { + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(260)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test('should return "Invalid angle" for angles outside the valid range', () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(-10)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(500)).toEqual("Invalid angle"); +}); From 3a0e465b597f2328cd85b2665ff3345ede95f58e Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 12:56:07 +0100 Subject: [PATCH 03/15] add proper fraction test --- .../2-is-proper-fraction.test.js | 49 +++++++++++++++++++ 1 file changed, 49 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..9b78ff35bb 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -8,3 +8,52 @@ const isProperFraction = require("../implement/2-is-proper-fraction"); test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); +// This statement loads the isProperFraction function you wrote in the implement directory. +// 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. + +// Special case: numerator is zero +test(`should return false when denominator is zero`, () => { + expect(isProperFraction(1, 0)).toEqual(false); +}); +test(`should return true when numerator is less than denominator`, () => { + // Proper fractions + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(3, 4)).toEqual(true); +}); +// Improper fractions +test("should return false when numerator is greater than denominator`", () => { + expect(isPrperFraction(5, 2)).toEqual(true); + expect(isProperFraction(3, 4)).toEqual(true); +}); +// Equal numerator and denominator +test("should return false when numerator equals denominator", () => { + expect(isProperFraction(4, 4)).toEqual(false); +}); + +// Numerator is zero +test("should return true when numerator is zero and denominator is positive", () => { + expect(isProperFunction(0.5)).toEqual(true); +}); +// Denominator is zero +test("should return false when denominator is zero", () => { + expect(isProperFunction(1, 0)).toEqual(false); +}); +// Both numerator and denominator are zero +test("should return false when numerator and denominator are zero", () => { + expect(isProperFunction(0, 0)).toEqual(false); +}); +// Negative numerator +test("should return false when numerator is negative", () => { + expect(isProperFunction(-1, 6)).toEqual(false); +}); +// Negative denominator +test("should return false when denominator is negative", () => { + expect(isProperFraction(1, -5)).toEqual(false); +}); +// Both numerator and denominator are negative +test("should return false when both numerator and denominator is negative", () => { + expect(isProperFraction(-4, -5)).toEqual(false); +}); From 6c4902058156d093eaad7fc0564032edb1d5b753 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 14:30:22 +0100 Subject: [PATCH 04/15] fix errors --- .../2-is-proper-fraction.test.js | 54 ++++++------------- 1 file changed, 17 insertions(+), 37 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 9b78ff35bb..6428c2b0fa 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 @@ -1,59 +1,39 @@ -// This statement loads the isProperFraction function you wrote in the implement directory. -// 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. - -// Special case: numerator is zero -test(`should return false when denominator is zero`, () => { - expect(isProperFraction(1, 0)).toEqual(false); -}); -// This statement loads the isProperFraction function you wrote in the implement directory. -// 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. - -// Special case: numerator is zero -test(`should return false when denominator is zero`, () => { - expect(isProperFraction(1, 0)).toEqual(false); -}); -test(`should return true when numerator is less than denominator`, () => { - // Proper fractions +test("should return true when numerator is less than denominator", () => { expect(isProperFraction(1, 2)).toEqual(true); expect(isProperFraction(3, 4)).toEqual(true); }); -// Improper fractions -test("should return false when numerator is greater than denominator`", () => { - expect(isPrperFraction(5, 2)).toEqual(true); - expect(isProperFraction(3, 4)).toEqual(true); + +test("should return false when numerator is greater than denominator", () => { + expect(isProperFraction(5, 2)).toEqual(false); + expect(isProperFraction(10, 3)).toEqual(false); }); -// Equal numerator and denominator + test("should return false when numerator equals denominator", () => { expect(isProperFraction(4, 4)).toEqual(false); }); -// Numerator is zero test("should return true when numerator is zero and denominator is positive", () => { - expect(isProperFunction(0.5)).toEqual(true); + expect(isProperFraction(0, 5)).toEqual(true); }); -// Denominator is zero + test("should return false when denominator is zero", () => { - expect(isProperFunction(1, 0)).toEqual(false); + expect(isProperFraction(1, 0)).toEqual(false); }); -// Both numerator and denominator are zero + test("should return false when numerator and denominator are zero", () => { - expect(isProperFunction(0, 0)).toEqual(false); + expect(isProperFraction(0, 0)).toEqual(false); }); -// Negative numerator -test("should return false when numerator is negative", () => { - expect(isProperFunction(-1, 6)).toEqual(false); + +test("should return true when numerator is negative and denominator is positive", () => { + expect(isProperFraction(-1, 6)).toEqual(true); }); -// Negative denominator + test("should return false when denominator is negative", () => { expect(isProperFraction(1, -5)).toEqual(false); }); -// Both numerator and denominator are negative -test("should return false when both numerator and denominator is negative", () => { + +test("should return false when both numerator and denominator are negative", () => { expect(isProperFraction(-4, -5)).toEqual(false); }); From b6f832b300ba31169a558dd32098ea37fb16ae6c Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 14:43:27 +0100 Subject: [PATCH 05/15] code implement --- .../implement/2-is-proper-fraction.js | 7 +++++++ 1 file changed, 7 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..ea17aa3799 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,13 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function + if (denominator <= 0) { + return false; + } + if (numerator < 0) { + return false; + } + return numerator < denominator; } // The line below allows us to load the isProperFraction function into tests in other files. From 9de9db0f9f1c0757cb1ec6946537d5ac10048ddf Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 15:24:03 +0100 Subject: [PATCH 06/15] get card value --- .../implement/3-get-card-value.js | 52 +++++++++++++++++++ .../3-get-card-value.test.js | 22 +++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js b/Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js index ff5c532e1d..ba21dba0f5 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,57 @@ function getCardValue(card) { // TODO: Implement this function + const validSuits = ["♠", "♥", "♦", "♣"]; + // Get the suit (last character) and rank (everything before it) + const suit = card.slice(-1); + const rank = card.slice(0, -1); + + // Check that the suit is valid + if (!validSuits.includes(suit)) { + throw new Error("Invalid card"); + } + // Ace + if (rank === "A") { + return 11; + } + + if (rank === "J" || rank === "Q" || rank === "K") { + return 10; + } + + if ( + rank === "2" || + rank === "3" || + rank === "4" || + rank === "5" || + rank === "6" || + rank === "7" || + rank === "8" || + rank === "9" || + rank === "10" + ) { + return Number(rank); + } + + throw new Error("Invalid card"); + + { + return Number(rank); + } + + // Invalid rank + throw new Error("Invalid card"); + getCardValue("1♠"); + getCardValue("11♣"); + getCardValue("0♦"); + getCardValue("B♥"); + getCardValue("X♠"); + + //invalid suit + getCardValue("AX"); + getCardValue("5*"); + getCardValue("10H"); + getCardValue("QS"); } // The line below allows us to load the getCardValue function into tests in other files. @@ -52,3 +103,4 @@ try { } // What other invalid card cases can you think of? +//invalid rank 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..ce4fc60cf2 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 @@ -8,6 +8,27 @@ const getCardValue = require("../implement/3-get-card-value"); test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); +// Case 2: Number cards (2–10) +test("should return the value of number cards", () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("5♦")).toEqual(5); + expect(getCardValue("10♣")).toEqual(10); +}); + +// Case 3: Face cards (J, Q, K) +test("should return 10 for face cards", () => { + expect(getCardValue("J♠")).toEqual(10); + expect(getCardValue("Q♥")).toEqual(10); + expect(getCardValue("K♦")).toEqual(10); +}); + +// Case 4: Invalid cards +test("should return 0 for invalid cards", () => { + expect(getCardValue("1♠")).toEqual(0); + expect(getCardValue("11♣")).toEqual(0); + expect(getCardValue("X♦")).toEqual(0); + expect(getCardValue("")).toEqual(0); +}); // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) @@ -17,4 +38,3 @@ test(`Should return 11 when given an ace card`, () => { // To learn how to test whether a function throws an error as expected in Jest, // please refer to the Jest documentation: // https://jestjs.io/docs/expect#tothrowerror - From 4472fa201071aeb010d249ae55f48af583bf6589 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 16:29:31 +0100 Subject: [PATCH 07/15] fix errors --- .../implement/2-is-proper-fraction.js | 3 - .../implement/3-get-card-value.js | 64 +++++++++---------- .../3-get-card-value.test.js | 13 ++-- 3 files changed, 38 insertions(+), 42 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 ea17aa3799..a0149abf6a 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 @@ -15,9 +15,6 @@ function isProperFraction(numerator, denominator) { if (denominator <= 0) { return false; } - if (numerator < 0) { - return false; - } return numerator < denominator; } 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 ba21dba0f5..5922735315 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 @@ -27,6 +27,7 @@ function getCardValue(card) { // Get the suit (last character) and rank (everything before it) const suit = card.slice(-1); const rank = card.slice(0, -1); + console.log(suit, rank); // Check that the suit is valid if (!validSuits.includes(suit)) { @@ -56,24 +57,6 @@ function getCardValue(card) { } throw new Error("Invalid card"); - - { - return Number(rank); - } - - // Invalid rank - throw new Error("Invalid card"); - getCardValue("1♠"); - getCardValue("11♣"); - getCardValue("0♦"); - getCardValue("B♥"); - getCardValue("X♠"); - - //invalid suit - getCardValue("AX"); - getCardValue("5*"); - getCardValue("10H"); - getCardValue("QS"); } // The line below allows us to load the getCardValue function into tests in other files. @@ -88,19 +71,32 @@ function assertEquals(actualOutput, targetOutput) { ); } -// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// Examples: -assertEquals(getCardValue("9♠"), 9); - -// Handling invalid cards -try { - getCardValue("invalid"); - - // 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 🎉"); -} - -// What other invalid card cases can you think of? -//invalid rank +// // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. +// // Examples: +// assertEquals(getCardValue("9♠"), 9); + +// // Handling invalid cards +// try { +// getCardValue("invalid"); + +// // 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 🎉"); +// } + +// // What other invalid card cases can you think of? +// //invalid rank +// getCardValue("1♠"); +// getCardValue("11♣"); +// getCardValue("0♦"); +// getCardValue("B♥"); +// getCardValue("X♠"); + +// //invalid suit +// getCardValue("AX"); +// getCardValue("5*"); +// getCardValue("10H"); +// getCardValue("QS"); + +getCardValue("1♠"); 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 ce4fc60cf2..3aef51be31 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 @@ -23,11 +23,14 @@ test("should return 10 for face cards", () => { }); // Case 4: Invalid cards -test("should return 0 for invalid cards", () => { - expect(getCardValue("1♠")).toEqual(0); - expect(getCardValue("11♣")).toEqual(0); - expect(getCardValue("X♦")).toEqual(0); - expect(getCardValue("")).toEqual(0); +test("should return error for invalid cards", () => { + expect(() => { + getCardValue("1♠"); + }).toThrow("Invalid card"); + // expect(getCardValue("1♠")).toEqual(0); + // expect(getCardValue("11♣")).toEqual(0); + // expect(getCardValue("X♦")).toEqual(0); + // expect(getCardValue("")).toEqual(0); }); // Suggestion: Group the remaining test data into these categories: From 142c2826f97cdbf7af7b4ba44078aa817db0924e Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 16:50:21 +0100 Subject: [PATCH 08/15] fix throw error and test --- .../implement/3-get-card-value.js | 2 -- .../3-get-card-value.test.js | 13 +++++++++---- 2 files changed, 9 insertions(+), 6 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 5922735315..c2cddf4e11 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 @@ -98,5 +98,3 @@ function assertEquals(actualOutput, targetOutput) { // getCardValue("5*"); // getCardValue("10H"); // getCardValue("QS"); - -getCardValue("1♠"); 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 3aef51be31..cfebb0bc29 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 @@ -27,10 +27,15 @@ test("should return error for invalid cards", () => { expect(() => { getCardValue("1♠"); }).toThrow("Invalid card"); - // expect(getCardValue("1♠")).toEqual(0); - // expect(getCardValue("11♣")).toEqual(0); - // expect(getCardValue("X♦")).toEqual(0); - // expect(getCardValue("")).toEqual(0); + expect(() => { + getCardValue("11♠"); + }).toThrow("Invalid card"); + expect(() => { + getCardValue("X♦"); + }).toThrow("Invalid card"); + expect(() => { + getCardValue(""); + }).toThrow("Invalid card"); }); // Suggestion: Group the remaining test data into these categories: From 7bac0af1433c96d736bbe0d2143543a1ba4e337d Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Wed, 29 Jul 2026 22:33:30 +0100 Subject: [PATCH 09/15] test ordinal no --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 4 +++- Sprint-3/2-practice-tdd/get-ordinal-number.test.js | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db13..e0eb15f15b 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,7 @@ function getOrdinalNumber(num) { - return "1st"; + if (num % 10 === 1 && num % 100 !== 11) { + return `${num}st`; + } } module.exports = getOrdinalNumber; 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..8d74cc1bd6 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -12,9 +12,13 @@ const getOrdinalNumber = require("./get-ordinal-number"); // Case 1: Numbers ending with 1 (but not 11) // When the number ends with 1, except those ending with 11, -// Then the function should return a string by appending "st" to the number. test("should append 'st' for numbers ending with 1, except those ending with 11", () => { expect(getOrdinalNumber(1)).toEqual("1st"); expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); + +// Then the function should return a string by appending "st" to the number. +test('should append "th" when the number is 11', () => { + expect(addOrdinalSuffix(11)).toEqual("11th"); +}); From daa156978e1fad576766af1abcfedf09df592257 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Thu, 30 Jul 2026 09:34:35 +0100 Subject: [PATCH 10/15] code --- Sprint-3/2-practice-tdd/count.js | 11 +++++++++- Sprint-3/2-practice-tdd/count.test.js | 31 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d4..a72d6a18dd 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,14 @@ 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; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf7..c5423bc015 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -18,7 +18,38 @@ test("should count multiple occurrences of a character", () => { }); // Scenario: No Occurrences +test("should return 0 when the character is not in the string", () => { + const str = "hello"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); // Given the input string `str`, + // And a character `char` that does not exist within `str`. +test("should return 0 for an empty string", () => { + const str = ""; + const char = "a"; + + const count = countChar(str, char); + + expect(count).toEqual(0); +}); + // When the function is called with these inputs, +test("should return 0 when the character does not occur in the string", () => { + const str = "hello"; + const char = "z"; + + const count = countChar(str, char); + + expect(count).toEqual(0); +}); // Then it should return 0, indicating that no occurrences of `char` were found. +test("should return 0 when the character does not occur in the string", () => { + const str = "hello"; + const char = "z"; + + const count = countChar(str, char); + + expect(count).toEqual(0); +}); From ce733d80749462ff94fc91744cea80b5feb68f5a Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Sat, 1 Aug 2026 16:20:12 +0100 Subject: [PATCH 11/15] tdd repeat tests --- Sprint-3/2-practice-tdd/repeat-str.js | 16 ++++++++++++---- Sprint-3/2-practice-tdd/repeat-str.test.js | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 2af0a2cea7..48679b224e 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,7 +1,15 @@ -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) { + if (count < 0) { + throw new Error("Count cannot be negative"); + } + + let result = ""; + + for (let i = 0; i < count; i++) { + result += str; + } + + return result; } module.exports = repeatStr; diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c4..08dbdb666b 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -20,13 +20,29 @@ 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 repeat the string count times", () => { + 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 repeat the string count times", () => { + 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", () => { + expect(() => repeatStr("hello", -1)).toThrow(); +}); From 2db7cc1c7b8f92bdc9395835b371d41c1417fe02 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Sat, 1 Aug 2026 16:31:41 +0100 Subject: [PATCH 12/15] fix error --- Sprint-3/2-practice-tdd/count.js | 1 - Sprint-3/2-practice-tdd/count.test.js | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index a72d6a18dd..79977793e5 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -9,6 +9,5 @@ function countChar(stringOfCharacters, findCharacter) { return count; } -} module.exports = countChar; diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index c5423bc015..e3447d2448 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -5,7 +5,7 @@ const countChar = require("./count"); // Then it should: // Scenario: Multiple Occurrences -// Given the input string `str`, +// Given the inpunt string `str`, // And a character `char` that occurs one or more times in `str` (e.g., 'a' in 'aaaaa'), // When the function is called with these inputs, // Then it should correctly count occurrences of `char`. @@ -18,11 +18,6 @@ test("should count multiple occurrences of a character", () => { }); // Scenario: No Occurrences -test("should return 0 when the character is not in the string", () => { - const str = "hello"; - const count = countChar(str, char); - expect(count).toEqual(0); -}); // Given the input string `str`, // And a character `char` that does not exist within `str`. From 3b81778144b50ea480edf10c6de4cf6da1f12531 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Sat, 1 Aug 2026 16:49:26 +0100 Subject: [PATCH 13/15] tdd error fix --- Sprint-3/2-practice-tdd/get-ordinal-number.js | 10 +++++++++- 1 file changed, 9 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 e0eb15f15b..54f1c1563d 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -2,6 +2,14 @@ function getOrdinalNumber(num) { if (num % 10 === 1 && num % 100 !== 11) { return `${num}st`; } -} + if (num % 10 === 2 && num % 100 !== 12) { + return `${num}nd`; + } + if (num % 10 === 3 && num % 100 !== 13) { + return `${num}rd`; + } + + return `${num}th`; +} module.exports = getOrdinalNumber; From 4fddfd0b34b90b8379182448d370a9a4647e569d Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Sat, 1 Aug 2026 16:49:57 +0100 Subject: [PATCH 14/15] error --- .../2-practice-tdd/get-ordinal-number.test.js | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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 8d74cc1bd6..37cb313f85 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -1,4 +1,3 @@ -const getOrdinalNumber = require("./get-ordinal-number"); // In this week's prep, we started implementing getOrdinalNumber. // Continue testing and implementing getOrdinalNumber for additional cases. @@ -12,13 +11,29 @@ const getOrdinalNumber = require("./get-ordinal-number"); // Case 1: Numbers ending with 1 (but not 11) // When the number ends with 1, except those ending with 11, + +const getOrdinalNumber = require("./get-ordinal-number"); +// Case 1: Numbers ending with 1 (but not 11) test("should append 'st' for numbers ending with 1, except those ending with 11", () => { expect(getOrdinalNumber(1)).toEqual("1st"); expect(getOrdinalNumber(21)).toEqual("21st"); expect(getOrdinalNumber(131)).toEqual("131st"); }); +// Case 2: Numbers ending with 11 +test('should append "th" when the number ends with 11', () => { + expect(getOrdinalNumber(11)).toEqual("11th"); +}); // Then the function should return a string by appending "st" to the number. -test('should append "th" when the number is 11', () => { - expect(addOrdinalSuffix(11)).toEqual("11th"); +test('should append "th" when the number ends with 12', () => { + expect(getOrdinalNumber(12)).toEqual("12th"); +}); +test('should append "th" when the number is 13', () => { + expect(getOrdinalNumber(13)).toEqual("13th"); +}); +test('should append "nd" when the number ends with 2', () => { + expect(getOrdinalNumber(22)).toEqual("22nd"); +}); +test('should append "rd" when the number ends with 3', () => { + expect(getOrdinalNumber(23)).toEqual("23rd"); }); From 6e28c70a27fe62c6510aa44281af38bba44b7932 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Thu, 6 Aug 2026 09:51:41 +0100 Subject: [PATCH 15/15] fix restore original files --- .../implement/1-get-angle-type.js | 14 +--- .../implement/2-is-proper-fraction.js | 4 -- .../implement/3-get-card-value.js | 70 ++++--------------- .../1-get-angle-type.test.js | 22 ------ .../2-is-proper-fraction.test.js | 39 ++--------- .../3-get-card-value.test.js | 30 +------- 6 files changed, 19 insertions(+), 160 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 ac053af89e..9e05a871e2 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -16,20 +16,8 @@ function getAngleType(angle) { // TODO: Implement this function - if (angle > 0 && angle < 90) { - return "Acute angle"; - } - if (angle === 90) return "Right angle"; - if (angle > 90 && angle < 180) { - return "Obtuse angle"; - } - 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; 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 a0149abf6a..970cb9b641 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,10 +12,6 @@ function isProperFraction(numerator, denominator) { // TODO: Implement this function - if (denominator <= 0) { - return false; - } - return numerator < denominator; } // The line below allows us to load the isProperFraction function into tests in other files. 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 c2cddf4e11..ff5c532e1d 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,40 +23,6 @@ function getCardValue(card) { // TODO: Implement this function - const validSuits = ["♠", "♥", "♦", "♣"]; - // Get the suit (last character) and rank (everything before it) - const suit = card.slice(-1); - const rank = card.slice(0, -1); - console.log(suit, rank); - - // Check that the suit is valid - if (!validSuits.includes(suit)) { - throw new Error("Invalid card"); - } - // Ace - if (rank === "A") { - return 11; - } - - if (rank === "J" || rank === "Q" || rank === "K") { - return 10; - } - - if ( - rank === "2" || - rank === "3" || - rank === "4" || - rank === "5" || - rank === "6" || - rank === "7" || - rank === "8" || - rank === "9" || - rank === "10" - ) { - return Number(rank); - } - - throw new Error("Invalid card"); } // The line below allows us to load the getCardValue function into tests in other files. @@ -71,30 +37,18 @@ function assertEquals(actualOutput, targetOutput) { ); } -// // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -// // Examples: -// assertEquals(getCardValue("9♠"), 9); - -// // Handling invalid cards -// try { -// getCardValue("invalid"); +// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. +// Examples: +assertEquals(getCardValue("9♠"), 9); -// // This line will not be reached if an error is thrown as expected -// console.error("Error was not thrown for invalid card 😢"); -// } catch (e) { -// console.log("Error thrown for invalid card 🎉"); -// } +// Handling invalid cards +try { + getCardValue("invalid"); -// // What other invalid card cases can you think of? -// //invalid rank -// getCardValue("1♠"); -// getCardValue("11♣"); -// getCardValue("0♦"); -// getCardValue("B♥"); -// getCardValue("X♠"); + // 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 🎉"); +} -// //invalid suit -// getCardValue("AX"); -// getCardValue("5*"); -// getCardValue("10H"); -// getCardValue("QS"); +// What other invalid card cases can you think of? 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 8f9347ddcf..d777f348d3 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,29 +14,7 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { }); // Case 2: Right angle -test(`should return "Right angle" when angle is 90`, () => { - expect(getAngleType(90)).toEqual("Right angle"); -}); // Case 3: Obtuse angles -test(`should return "Obtuse angle" when angel is >90 & <180`, () => { - expect(getAngleType(100)).toEqual("Obtuse angle"); - expect(getAngleType(95)).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', () => { - expect(getAngleType(181)).toEqual("Reflex angle"); - expect(getAngleType(260)).toEqual("Reflex angle"); - expect(getAngleType(359)).toEqual("Reflex angle"); -}); - // Case 6: Invalid angles -test('should return "Invalid angle" for angles outside the valid range', () => { - expect(getAngleType(0)).toEqual("Invalid angle"); - expect(getAngleType(-10)).toEqual("Invalid angle"); - expect(getAngleType(360)).toEqual("Invalid angle"); - expect(getAngleType(500)).toEqual("Invalid angle"); -}); 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 6428c2b0fa..7f087b2ba1 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 @@ -1,39 +1,10 @@ +// This statement loads the isProperFraction function you wrote in the implement directory. +// We will use the same function, but write tests for it using Jest in this file. const isProperFraction = require("../implement/2-is-proper-fraction"); -test("should return true when numerator is less than denominator", () => { - expect(isProperFraction(1, 2)).toEqual(true); - expect(isProperFraction(3, 4)).toEqual(true); -}); - -test("should return false when numerator is greater than denominator", () => { - expect(isProperFraction(5, 2)).toEqual(false); - expect(isProperFraction(10, 3)).toEqual(false); -}); - -test("should return false when numerator equals denominator", () => { - expect(isProperFraction(4, 4)).toEqual(false); -}); - -test("should return true when numerator is zero and denominator is positive", () => { - expect(isProperFraction(0, 5)).toEqual(true); -}); +// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. -test("should return false when denominator is zero", () => { +// Special case: numerator is zero +test(`should return false when denominator is zero`, () => { expect(isProperFraction(1, 0)).toEqual(false); }); - -test("should return false when numerator and denominator are zero", () => { - expect(isProperFraction(0, 0)).toEqual(false); -}); - -test("should return true when numerator is negative and denominator is positive", () => { - expect(isProperFraction(-1, 6)).toEqual(true); -}); - -test("should return false when denominator is negative", () => { - expect(isProperFraction(1, -5)).toEqual(false); -}); - -test("should return false when both numerator and denominator are negative", () => { - expect(isProperFraction(-4, -5)).toEqual(false); -}); 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 cfebb0bc29..cf7f9dae2e 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 @@ -8,35 +8,6 @@ const getCardValue = require("../implement/3-get-card-value"); test(`Should return 11 when given an ace card`, () => { expect(getCardValue("A♠")).toEqual(11); }); -// Case 2: Number cards (2–10) -test("should return the value of number cards", () => { - expect(getCardValue("2♠")).toEqual(2); - expect(getCardValue("5♦")).toEqual(5); - expect(getCardValue("10♣")).toEqual(10); -}); - -// Case 3: Face cards (J, Q, K) -test("should return 10 for face cards", () => { - expect(getCardValue("J♠")).toEqual(10); - expect(getCardValue("Q♥")).toEqual(10); - expect(getCardValue("K♦")).toEqual(10); -}); - -// Case 4: Invalid cards -test("should return error for invalid cards", () => { - expect(() => { - getCardValue("1♠"); - }).toThrow("Invalid card"); - expect(() => { - getCardValue("11♠"); - }).toThrow("Invalid card"); - expect(() => { - getCardValue("X♦"); - }).toThrow("Invalid card"); - expect(() => { - getCardValue(""); - }).toThrow("Invalid card"); -}); // Suggestion: Group the remaining test data into these categories: // Number Cards (2-10) @@ -46,3 +17,4 @@ test("should return error for invalid cards", () => { // 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 +