From 8f3450dece1a1b756ff7cc09bf439037c1d9bd1a Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Mon, 12 Oct 2026 23:45:33 +0100 Subject: [PATCH 01/15] add fizzbuzz function and corresponding tests --- test-driven-development/fizzbuzz.js | 10 +++++++ test-driven-development/fizzbuzz.test.js | 36 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test-driven-development/fizzbuzz.js create mode 100644 test-driven-development/fizzbuzz.test.js diff --git a/test-driven-development/fizzbuzz.js b/test-driven-development/fizzbuzz.js new file mode 100644 index 000000000..12198b29f --- /dev/null +++ b/test-driven-development/fizzbuzz.js @@ -0,0 +1,10 @@ +function fizzbuzz(number){ + if (number % 3 === 0 && number % 5 === 0){ + return "fizzbuzz"; + } else if (number % 5 === 0){ + return "buzz"; + } else if (number % 3 === 0){ + return "fizz"; + } + return number.toString(); +}; \ No newline at end of file diff --git a/test-driven-development/fizzbuzz.test.js b/test-driven-development/fizzbuzz.test.js new file mode 100644 index 000000000..e48f23149 --- /dev/null +++ b/test-driven-development/fizzbuzz.test.js @@ -0,0 +1,36 @@ +import {fizzbuzz} from './fizzbuzz.js'; +import assert from 'node:assert'; +import {test, describe} from 'node:test'; + +describe('division by 3 and 5', () => { + + test('15 returns fizzbuzz', () => { + assert.equal(fizzbuzz(15), "fizzbuzz"); + }); + + test('30 returns fizzbuzz', () => { + assert.equal(fizzbuzz(30), "fizzbuzz"); + }); + + test('90 returns fizzbuzz', () => { + assert.equal(fizzbuzz(90), "fizzbuzz"); + }); + +}); + + +describe('returning the number as a string', () => { + + test('1 returns "1"', () => { + assert.equal(fizzbuzz(1), "1"); + }); + + test('4 returns "4"', () => { + assert.equal(fizzbuzz(4), "4"); + }); + + test('91 returns "91"', () => { + assert.equal(fizzbuzz(91), "91"); + }); + +}); \ No newline at end of file From 78d73653256b02c57a4f9630bf01675f116e3156 Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Tue, 13 Oct 2026 00:17:40 +0100 Subject: [PATCH 02/15] implement countChar function to count occurrences of a specified character --- practice-tdd/count.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/practice-tdd/count.js b/practice-tdd/count.js index 5518c5712..f0d38fd50 100644 --- a/practice-tdd/count.js +++ b/practice-tdd/count.js @@ -1,3 +1,8 @@ export function countChar(stringOfCharacters, findCharacter) { - return 5 + let count = 0; + for (const char of stringOfCharacters) { + if (char === findCharacter) + count ++ + } + return count; } From bdc9bad7b702f5bc2168f4579b0eaba46cff911b Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Tue, 13 Oct 2026 00:18:39 +0100 Subject: [PATCH 03/15] refactor count.test.js to improve clarity and formatting --- practice-tdd/count.test.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js index cb3aaae59..932dd562a 100644 --- a/practice-tdd/count.test.js +++ b/practice-tdd/count.test.js @@ -1,5 +1,5 @@ -// implement a function countChar that counts the number of times a character occurs in a string import { countChar } from "./count.js"; + // Given a string `str` and a single character `char` to search for, // When the countChar function is called with these inputs, // Then it should: @@ -9,7 +9,6 @@ import { countChar } from "./count.js"; // 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`. - test("should count multiple occurrences of a character", () => { const str = "aaaaa"; const char = "a"; @@ -22,3 +21,9 @@ 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 when the character is not found in the string", () => { + const str = "hello"; + const char = "z"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); \ No newline at end of file From 9008c4d5c50b94c1788a614a5c9875a5a3cbafb9 Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Wed, 14 Oct 2026 00:13:16 +0100 Subject: [PATCH 04/15] implement getAngleType function to determine angle types based on degree values --- .../implement/1-get-angle-type.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/implement/1-get-angle-type.js b/implement-and-rewrite-tests/implement/1-get-angle-type.js index 8a6fba050..00df61114 100644 --- a/implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -17,5 +17,21 @@ // execute the code to ensure all tests pass. export 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"; + } + if (angle > 180 && angle < 360) { + return "Reflex angle"; + } + + return "Invalid angle"; } From 3b5aa4ea646e66d4c6bdbda49a666cfc918b4ace Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Wed, 14 Oct 2026 00:13:26 +0100 Subject: [PATCH 05/15] add comprehensive tests for angle classification including acute, obtuse, straight, reflex, and invalid cases --- .../1-get-angle-type.test.js | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js index cf50f6cad..7e223870a 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/1-get-angle-type.test.js @@ -3,10 +3,48 @@ import test from "node:test"; import { getAngleType } from "../implement/1-get-angle-type.js"; -// TODO: Write tests to cover all cases, including boundary and invalid cases. // Example: Identify Right Angles test("Classifies right angles", () => { const right = getAngleType(90); assert.equal(right, "Right angle"); }); + +// Acute Angles (0° < angle < 90°) +test("Classifies acute angles", () => { + assert.equal(getAngleType(1), "Acute angle"); + assert.equal(getAngleType(45), "Acute angle"); + assert.equal(getAngleType(89.9), "Acute angle"); +}); + +// Right Angles (angle === 90°) +test("Classifies right angles", () => { + assert.equal(getAngleType(90), "Right angle"); +}); + +// Obtuse Angles (90° < angle < 180°) +test("Classifies obtuse angles", () => { + assert.equal(getAngleType(90.1), "Obtuse angle"); + assert.equal(getAngleType(135), "Obtuse angle"); + assert.equal(getAngleType(179.9), "Obtuse angle"); +}); + +// Straight Angles (angle === 180°) +test("Classifies straight angles", () => { + assert.equal(getAngleType(180), "Straight angle"); +}); + +// Reflex Angles (180° < angle < 360°) +test("Classifies reflex angles", () => { + assert.equal(getAngleType(180.1), "Reflex angle"); + assert.equal(getAngleType(270), "Reflex angle"); + assert.equal(getAngleType(359.9), "Reflex angle"); +}); + +// Invalid & Boundary Cases (<= 0° or >= 360°) +test("Classifies invalid angles and exact boundaries", () => { + assert.equal(getAngleType(0), "Invalid angle"); + assert.equal(getAngleType(-45), "Invalid angle"); + assert.equal(getAngleType(360), "Invalid angle"); + assert.equal(getAngleType(400), "Invalid angle"); +}); From 5d4a5d7c19e8b85d314baaa511e05ab8f4181ff1 Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Wed, 14 Oct 2026 00:23:39 +0100 Subject: [PATCH 06/15] implement isProperFraction function to validate proper fractions --- .../implement/2-is-proper-fraction.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js index f983800f0..376a2cbc0 100644 --- a/implement-and-rewrite-tests/implement/2-is-proper-fraction.js +++ b/implement-and-rewrite-tests/implement/2-is-proper-fraction.js @@ -14,5 +14,9 @@ // execute the code to ensure all tests pass. export function isProperFraction(numerator, denominator) { - // TODO: Implement this function + if (denominator === 0) { + return false; + } + + return Math.abs(numerator) < Math.abs(denominator); } From cd8ba7b06a16817badaaf4b02472f67e2cb7cd2f Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Wed, 14 Oct 2026 00:23:49 +0100 Subject: [PATCH 07/15] add comprehensive tests for isProperFraction function to cover various cases --- .../2-is-proper-fraction.test.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js index a29084605..d821ad498 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js @@ -6,7 +6,33 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js"; // TODO: Write tests to cover all cases. // What combinations of numerators and denominators should you test? + test("Basic proper fraction", () => { // Example: 1/2 is a proper fraction assert.equal(isProperFraction(1, 2), true); + assert.equal(isProperFraction(3, 4), true); +}); + +test("Improper fraction where numerator is larger than denominator", () => { + assert.equal(isProperFraction(5, 2), false); + assert.equal(isProperFraction(4, 3), false); +}); + +test("Equal numerator and denominator (equals 1)", () => { + assert.equal(isProperFraction(3, 3), false); }); + +test("Denominator is zero", () => { + assert.equal(isProperFraction(1, 0), false); + assert.equal(isProperFraction(0, 0), false); +}); + +test("Zero numerator with non-zero denominator", () => { + assert.equal(isProperFraction(0, 5), true); +}); + +test("Negative numbers", () => { + assert.equal(isProperFraction(-1, 2), true); + assert.equal(isProperFraction(1, -2), true); + assert.equal(isProperFraction(-3, -2), false); +}); \ No newline at end of file From 526ac93a2fb6778c3ce3b21e72f1cfa33ee9e41b Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Wed, 14 Oct 2026 00:29:23 +0100 Subject: [PATCH 08/15] implement getCardValue function to return numerical values for playing cards --- .../implement/3-get-card-value.js | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/implement/3-get-card-value.js b/implement-and-rewrite-tests/implement/3-get-card-value.js index 9614ab1ee..b929b5bb3 100644 --- a/implement-and-rewrite-tests/implement/3-get-card-value.js +++ b/implement-and-rewrite-tests/implement/3-get-card-value.js @@ -24,5 +24,28 @@ // execute the code to ensure all tests pass. export function getCardValue(card) { - // TODO: Implement this function + if (typeof card !== "string") { + throw new Error(`Expected a string, but got ${typeof card}`); + } + + const cardRegex = /^(10|[2-9]|[AJQK])([♠♥♦♣])$/; + const match = card.match(cardRegex); + + if (!match) { + throw new Error( + `Expected a card rank followed by a suit, but got "${card}"` + ); + } + + const rank = match[1]; + + if (rank === "A") { + return 11; + } + + if (["J", "Q", "K"].includes(rank)) { + return 10; + } + + return Number(rank); } From 1e4b2176c5c94e166db60c34adca66b35db65f5e Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Wed, 14 Oct 2026 00:29:31 +0100 Subject: [PATCH 09/15] refactor tests for getCardValue function to improve clarity and coverage --- .../3-get-card-value.test.js | 71 +++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js b/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js index f5092d9b1..f590aac82 100644 --- a/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js +++ b/implement-and-rewrite-tests/implement-tests-with-node-test/3-get-card-value.test.js @@ -5,12 +5,73 @@ import { getCardValue } from "../implement/3-get-card-value.js"; // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. -test("Valid single-digit card", () => { - assert.equal(getCardValue("9♠"), 9); +test("Valid single-digit number cards return correct values", () => { + assert.equal(getCardValue("2♠"), 2); + assert.equal(getCardValue("5♥"), 5); + assert.equal(getCardValue("9♦"), 9); }); -test("Arbitrary non-card string", () => { - assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error"); +test("Valid double-digit card (10) returns 10", () => { + assert.equal(getCardValue("10♥"), 10); + assert.equal(getCardValue("10♣"), 10); }); -// TODO: What other invalid card cases can you think of? +test("Ace cards return 11", () => { + assert.equal(getCardValue("A♠"), 11); + assert.equal(getCardValue("A♦"), 11); +}); + +test("Face cards (J, Q, K) return 10", () => { + assert.equal(getCardValue("J♣"), 10); + assert.equal(getCardValue("Q♦"), 10); + assert.equal(getCardValue("K♠"), 10); +}); + +// Invalid Input Cases +test("Throws error for arbitrary non-card string", () => { + assert.throws( + () => getCardValue("invalid"), + /Expected a card rank followed by a suit/ + ); +}); + +test("Throws error for invalid ranks or suit-like characters", () => { + assert.throws( + () => getCardValue("1♠"), + /Expected a card rank followed by a suit/ + ); + assert.throws( + () => getCardValue("11♥"), + /Expected a card rank followed by a suit/ + ); + assert.throws( + () => getCardValue("Z♠"), + /Expected a card rank followed by a suit/ + ); +}); + +test("Throws error for invalid or missing suit", () => { + assert.throws( + () => getCardValue("10"), + /Expected a card rank followed by a suit/ + ); + assert.throws( + () => getCardValue("AX"), + /Expected a card rank followed by a suit/ + ); +}); + +test("Throws error for reversed order (suit before rank)", () => { + assert.throws( + () => getCardValue("♠A"), + /Expected a card rank followed by a suit/ + ); +}); + +test("Throws error for empty string or non-string input", () => { + assert.throws( + () => getCardValue(""), + /Expected a card rank followed by a suit/ + ); + assert.throws(() => getCardValue(10), /Expected a string/); +}); From 6612274671a204efe216c04b43c55e8bcd036fb3 Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Wed, 14 Oct 2026 00:34:45 +0100 Subject: [PATCH 10/15] add comprehensive tests for getAngleType function to cover all angle types and edge cases --- .../1-get-angle-type.test.js | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js b/implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js index e0ba786ab..32dc72a58 100644 --- a/implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js +++ b/implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js @@ -3,16 +3,43 @@ import { getAngleType } from "../implement/1-get-angle-type.js"; // TODO: Write tests in Jest syntax to cover all cases/outcomes, // including boundary and invalid cases. + // 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"); + expect(getAngleType(89.9)).toEqual("Acute angle"); }); // Case 2: Right angle +test(`should return "Right angle" when angle is exactly 90`, () => { + expect(getAngleType(90)).toEqual("Right angle"); +}); + // Case 3: Obtuse angles +test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { + expect(getAngleType(90.1)).toEqual("Obtuse angle"); + expect(getAngleType(135)).toEqual("Obtuse angle"); + expect(getAngleType(179.9)).toEqual("Obtuse angle"); +}); + // Case 4: Straight angle +test(`should return "Straight angle" when angle is exactly 180`, () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); + // Case 5: Reflex angles +test(`should return "Reflex angle" when (180 < angle < 360)`, () => { + expect(getAngleType(180.1)).toEqual("Reflex angle"); + expect(getAngleType(270)).toEqual("Reflex angle"); + expect(getAngleType(359.9)).toEqual("Reflex angle"); +}); + // Case 6: Invalid angles +test(`should return "Invalid angle" when angle is <= 0 or >= 360`, () => { + expect(getAngleType(0)).toEqual("Invalid angle"); + expect(getAngleType(-45)).toEqual("Invalid angle"); + expect(getAngleType(360)).toEqual("Invalid angle"); + expect(getAngleType(400)).toEqual("Invalid angle"); +}); \ No newline at end of file From ac6647364accacec772aa7f54863d9805704b71a Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Wed, 14 Oct 2026 00:36:58 +0100 Subject: [PATCH 11/15] add comprehensive tests for isProperFraction function to cover positive, negative, and zero cases --- .../2-is-proper-fraction.test.js | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js b/implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js index 5d49e2d8b..3ef0e69f5 100644 --- a/implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js +++ b/implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js @@ -2,7 +2,38 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js"; // TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. +// Positive numbers +test("should return true when positive numerator is less than positive denominator", () => { + expect(isProperFraction(1, 2)).toEqual(true); + expect(isProperFraction(3, 4)).toEqual(true); +}); + +test("should return false when positive numerator is equal to or greater than positive denominator", () => { + expect(isProperFraction(3, 3)).toEqual(false); + expect(isProperFraction(5, 2)).toEqual(false); +}); + // Special case: numerator is zero -test(`should return false when denominator is zero`, () => { + +test("should return false when denominator is zero", () => { expect(isProperFraction(1, 0)).toEqual(false); + expect(isProperFraction(0, 0)).toEqual(false); +}); + +test("should return true when numerator is zero and denominator is non-zero", () => { + expect(isProperFraction(0, 5)).toEqual(true); + expect(isProperFraction(0, -5)).toEqual(true); +}); + +// Negative numbers +test("should return true when absolute value of numerator is less than denominator", () => { + expect(isProperFraction(-1, 2)).toEqual(true); + expect(isProperFraction(1, -2)).toEqual(true); + expect(isProperFraction(-1, -2)).toEqual(true); +}); + +test("should return false when absolute value of numerator is equal to or greater than denominator", () => { + expect(isProperFraction(-5, 2)).toEqual(false); + expect(isProperFraction(5, -2)).toEqual(false); + expect(isProperFraction(-3, -3)).toEqual(false); }); From 02b9cb750a8f944afb6a92123f83f6104f2566dc Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Wed, 14 Oct 2026 00:40:05 +0100 Subject: [PATCH 12/15] refactor tests for getCardValue function to improve organization and clarity --- .../3-get-card-value.test.js | 52 ++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js b/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js index a6de5a82a..74a8b581d 100644 --- a/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js +++ b/implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js @@ -2,17 +2,57 @@ import { getCardValue } from "../implement/3-get-card-value.js"; // TODO: Write tests in Jest syntax to cover all possible outcomes. + // Case 1: Ace (A) -test(`Should return 11 when given an ace card`, () => { +test("Should return 11 when given an ace card", () => { expect(getCardValue("A♠")).toEqual(11); + expect(getCardValue("A♦")).toEqual(11); }); -// Suggestion: Group the remaining test data into these categories: -// Number Cards (2-10) -// Face Cards (J, Q, K) -// Invalid Cards +// Case 2: Number Cards (2-10) +test("Should return numeric value for single-digit number cards", () => { + expect(getCardValue("2♠")).toEqual(2); + expect(getCardValue("5♥")).toEqual(5); + expect(getCardValue("9♦")).toEqual(9); +}); + +test("Should return 10 for '10' cards across all suits", () => { + expect(getCardValue("10♥")).toEqual(10); + expect(getCardValue("10♣")).toEqual(10); +}); + +// Case 3: Face Cards (J, Q, K) +test("Should return 10 for face cards (J, Q, K)", () => { + expect(getCardValue("J♣")).toEqual(10); + expect(getCardValue("Q♦")).toEqual(10); + expect(getCardValue("K♠")).toEqual(10); +}); + +// Case 4: Invalid Cards +test("Should throw an error for arbitrary non-card strings", () => { + expect(() => getCardValue("invalid")).toThrow(); +}); + +test("Should throw an error for invalid ranks or suit-like characters", () => { + expect(() => getCardValue("1♠")).toThrow(); + expect(() => getCardValue("11♥")).toThrow(); + expect(() => getCardValue("Z♠")).toThrow(); +}); + +test("Should throw an error for missing or invalid suit", () => { + expect(() => getCardValue("10")).toThrow(); + expect(() => getCardValue("AX")).toThrow(); +}); + +test("Should throw an error when suit is before rank", () => { + expect(() => getCardValue("♠A")).toThrow(); +}); + +test("Should throw an error for non-string or empty inputs", () => { + expect(() => getCardValue("")).toThrow(); + expect(() => getCardValue(10)).toThrow(); +}); // To learn how to test whether a function throws an error as expected in Jest, // please refer to the Jest documentation: // https://jestjs.io/docs/expect#tothrowerror - From 4bea4760e2d0134d222b58044dc703839b4922d6 Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Wed, 14 Oct 2026 00:55:46 +0100 Subject: [PATCH 13/15] fix: remove extraneous practice-tdd files from PR branch --- practice-tdd/count.js | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 practice-tdd/count.js diff --git a/practice-tdd/count.js b/practice-tdd/count.js deleted file mode 100644 index f0d38fd50..000000000 --- a/practice-tdd/count.js +++ /dev/null @@ -1,8 +0,0 @@ -export function countChar(stringOfCharacters, findCharacter) { - let count = 0; - for (const char of stringOfCharacters) { - if (char === findCharacter) - count ++ - } - return count; -} From 1e0d93ff595c3d23b71da592b03819b6e96a0d30 Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Wed, 14 Oct 2026 00:58:23 +0100 Subject: [PATCH 14/15] fix: remove practice-tdd directory from branch to pass PR check --- practice-tdd/README.md | 13 ---------- practice-tdd/count.test.js | 29 ---------------------- practice-tdd/get-ordinal-number.js | 3 --- practice-tdd/get-ordinal-number.test.js | 20 ---------------- practice-tdd/repeat-str.js | 5 ---- practice-tdd/repeat-str.test.js | 32 ------------------------- 6 files changed, 102 deletions(-) delete mode 100644 practice-tdd/README.md delete mode 100644 practice-tdd/count.test.js delete mode 100644 practice-tdd/get-ordinal-number.js delete mode 100644 practice-tdd/get-ordinal-number.test.js delete mode 100644 practice-tdd/repeat-str.js delete mode 100644 practice-tdd/repeat-str.test.js diff --git a/practice-tdd/README.md b/practice-tdd/README.md deleted file mode 100644 index f7d82fe43..000000000 --- a/practice-tdd/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Practice TDD - -In this section you'll practice this key skill of building up your program test first. - -Use the Jest syntax and complete the provided files, meeting the acceptance criteria for each function. Use the VSCode test runner to run your tests and check your progress. - -Write the tests _before_ the code that will make them pass. - -Recommended order: - -1. `count.test.js` -1. `repeat-str.test.js` -1. `get-ordinal-number.test.js` diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js deleted file mode 100644 index 932dd562a..000000000 --- a/practice-tdd/count.test.js +++ /dev/null @@ -1,29 +0,0 @@ -import { countChar } from "./count.js"; - -// Given a string `str` and a single character `char` to search for, -// When the countChar function is called with these inputs, -// Then it should: - -// Scenario: Multiple Occurrences -// Given the input 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`. -test("should count multiple occurrences of a character", () => { - const str = "aaaaa"; - const char = "a"; - const count = countChar(str, char); - expect(count).toEqual(5); -}); - -// Scenario: No Occurrences -// Given the input string `str`, -// 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 when the character is not found in the string", () => { - const str = "hello"; - const char = "z"; - const count = countChar(str, char); - expect(count).toEqual(0); -}); \ No newline at end of file diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js deleted file mode 100644 index 5c6291f5e..000000000 --- a/practice-tdd/get-ordinal-number.js +++ /dev/null @@ -1,3 +0,0 @@ -export function getOrdinalNumber(num) { - return "1st"; -} diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js deleted file mode 100644 index e23174a18..000000000 --- a/practice-tdd/get-ordinal-number.test.js +++ /dev/null @@ -1,20 +0,0 @@ -import { getOrdinalNumber } from "./get-ordinal-number.js"; -// In this week's prep, we started implementing getOrdinalNumber. - -// Continue testing and implementing getOrdinalNumber for additional cases. -// Write your tests using Jest — remember to run your tests often for continual feedback. - -// To ensure thorough testing, we need broad scenarios that cover all possible cases. -// Listing individual values, however, can quickly lead to an unmanageable number of test cases. -// Instead of writing tests for individual numbers, consider grouping all possible input values -// into meaningful categories. Then, select representative samples from each category to test. -// This approach improves coverage and makes our tests easier to maintain. - -// 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"); -}); diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js deleted file mode 100644 index af273f3b0..000000000 --- a/practice-tdd/repeat-str.js +++ /dev/null @@ -1,5 +0,0 @@ -export 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"; -} diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js deleted file mode 100644 index 8a7036102..000000000 --- a/practice-tdd/repeat-str.test.js +++ /dev/null @@ -1,32 +0,0 @@ -// Implement a function repeatStr -import { repeatStr } from "./repeat-str.js"; -// Given a target string `str` and a positive integer `count`, -// When the repeatStr function is called with these inputs, -// Then it should: - -// Case: handle multiple repetitions: -// Given a target string `str` and a positive integer `count` greater than 1, -// When the repeatStr function is called with these inputs, -// Then it should return a string that contains the original `str` repeated `count` times. - -test("should repeat the string count times", () => { - const str = "hello"; - const count = 3; - const repeatedStr = repeatStr(str, count); - expect(repeatedStr).toEqual("hellohellohello"); -}); - -// Case: handle count of 1: -// 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. - -// 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. - -// 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. From 27995e058ab59e9bcd2ef0f8667757ef293501e8 Mon Sep 17 00:00:00 2001 From: Rahana Suleiman Date: Wed, 14 Oct 2026 01:11:03 +0100 Subject: [PATCH 15/15] fix: restore practice-tdd directory to match main --- practice-tdd/README.md | 13 ++++++++++ practice-tdd/count.js | 3 +++ practice-tdd/count.test.js | 24 +++++++++++++++++++ practice-tdd/get-ordinal-number.js | 3 +++ practice-tdd/get-ordinal-number.test.js | 20 ++++++++++++++++ practice-tdd/repeat-str.js | 5 ++++ practice-tdd/repeat-str.test.js | 32 +++++++++++++++++++++++++ 7 files changed, 100 insertions(+) create mode 100644 practice-tdd/README.md create mode 100644 practice-tdd/count.js create mode 100644 practice-tdd/count.test.js create mode 100644 practice-tdd/get-ordinal-number.js create mode 100644 practice-tdd/get-ordinal-number.test.js create mode 100644 practice-tdd/repeat-str.js create mode 100644 practice-tdd/repeat-str.test.js diff --git a/practice-tdd/README.md b/practice-tdd/README.md new file mode 100644 index 000000000..f7d82fe43 --- /dev/null +++ b/practice-tdd/README.md @@ -0,0 +1,13 @@ +# Practice TDD + +In this section you'll practice this key skill of building up your program test first. + +Use the Jest syntax and complete the provided files, meeting the acceptance criteria for each function. Use the VSCode test runner to run your tests and check your progress. + +Write the tests _before_ the code that will make them pass. + +Recommended order: + +1. `count.test.js` +1. `repeat-str.test.js` +1. `get-ordinal-number.test.js` diff --git a/practice-tdd/count.js b/practice-tdd/count.js new file mode 100644 index 000000000..5518c5712 --- /dev/null +++ b/practice-tdd/count.js @@ -0,0 +1,3 @@ +export function countChar(stringOfCharacters, findCharacter) { + return 5 +} diff --git a/practice-tdd/count.test.js b/practice-tdd/count.test.js new file mode 100644 index 000000000..cb3aaae59 --- /dev/null +++ b/practice-tdd/count.test.js @@ -0,0 +1,24 @@ +// implement a function countChar that counts the number of times a character occurs in a string +import { countChar } from "./count.js"; +// Given a string `str` and a single character `char` to search for, +// When the countChar function is called with these inputs, +// Then it should: + +// Scenario: Multiple Occurrences +// Given the input 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`. + +test("should count multiple occurrences of a character", () => { + const str = "aaaaa"; + const char = "a"; + const count = countChar(str, char); + expect(count).toEqual(5); +}); + +// Scenario: No Occurrences +// Given the input string `str`, +// 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. diff --git a/practice-tdd/get-ordinal-number.js b/practice-tdd/get-ordinal-number.js new file mode 100644 index 000000000..5c6291f5e --- /dev/null +++ b/practice-tdd/get-ordinal-number.js @@ -0,0 +1,3 @@ +export function getOrdinalNumber(num) { + return "1st"; +} diff --git a/practice-tdd/get-ordinal-number.test.js b/practice-tdd/get-ordinal-number.test.js new file mode 100644 index 000000000..e23174a18 --- /dev/null +++ b/practice-tdd/get-ordinal-number.test.js @@ -0,0 +1,20 @@ +import { getOrdinalNumber } from "./get-ordinal-number.js"; +// In this week's prep, we started implementing getOrdinalNumber. + +// Continue testing and implementing getOrdinalNumber for additional cases. +// Write your tests using Jest — remember to run your tests often for continual feedback. + +// To ensure thorough testing, we need broad scenarios that cover all possible cases. +// Listing individual values, however, can quickly lead to an unmanageable number of test cases. +// Instead of writing tests for individual numbers, consider grouping all possible input values +// into meaningful categories. Then, select representative samples from each category to test. +// This approach improves coverage and makes our tests easier to maintain. + +// 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"); +}); diff --git a/practice-tdd/repeat-str.js b/practice-tdd/repeat-str.js new file mode 100644 index 000000000..af273f3b0 --- /dev/null +++ b/practice-tdd/repeat-str.js @@ -0,0 +1,5 @@ +export 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"; +} diff --git a/practice-tdd/repeat-str.test.js b/practice-tdd/repeat-str.test.js new file mode 100644 index 000000000..8a7036102 --- /dev/null +++ b/practice-tdd/repeat-str.test.js @@ -0,0 +1,32 @@ +// Implement a function repeatStr +import { repeatStr } from "./repeat-str.js"; +// Given a target string `str` and a positive integer `count`, +// When the repeatStr function is called with these inputs, +// Then it should: + +// Case: handle multiple repetitions: +// Given a target string `str` and a positive integer `count` greater than 1, +// When the repeatStr function is called with these inputs, +// Then it should return a string that contains the original `str` repeated `count` times. + +test("should repeat the string count times", () => { + const str = "hello"; + const count = 3; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("hellohellohello"); +}); + +// Case: handle count of 1: +// 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. + +// 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. + +// 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.