From 050f3c5a4f580201a7d12e78809b20da713ede07 Mon Sep 17 00:00:00 2001 From: Ihor Taradaiko Date: Mon, 23 Feb 2026 15:19:14 +0000 Subject: [PATCH 1/3] count.jest --- Sprint-3/2-practice-tdd/count.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-3/2-practice-tdd/count.test.js b/Sprint-3/2-practice-tdd/count.test.js index 179ea0ddf..28290ce3c 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -4,12 +4,14 @@ const countChar = require("./count"); // 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"; @@ -17,8 +19,16 @@ test("should count multiple occurrences of a character", () => { 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", () => { + const str = "hello"; + const char = "z"; + const count = countChar(str, char); + expect(count).toEqual(0); +}); From 9d4dd77d137bc1e306d2f3361d8d331aa7e31cb4 Mon Sep 17 00:00:00 2001 From: Ihor Taradaiko Date: Tue, 24 Feb 2026 10:06:38 +0000 Subject: [PATCH 2/3] repeat-str jest --- Sprint-3/2-practice-tdd/repeat-str.test.js | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Sprint-3/2-practice-tdd/repeat-str.test.js b/Sprint-3/2-practice-tdd/repeat-str.test.js index a3fc1196c..a4066eaa3 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.test.js +++ b/Sprint-3/2-practice-tdd/repeat-str.test.js @@ -4,6 +4,7 @@ const repeatStr = require("./repeat-str"); // 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, @@ -16,17 +17,40 @@ test("should repeat the string count times", () => { 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. +test("should return the original string when count is 1", () => { + const str = "world"; + const count = 1; + const repeatedStr = repeatStr(str, count); + expect(repeatedStr).toEqual("world"); +}); + + // 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 = "test"; + 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 = "error"; + const count = -2; + expect(() => repeatStr(str, count)).toThrow(); +}); From 17ec43c04fb115dab5dd0681d21adcab384118d8 Mon Sep 17 00:00:00 2001 From: Ihor Taradaiko Date: Tue, 24 Feb 2026 10:13:00 +0000 Subject: [PATCH 3/3] get-ordinal-number-jest --- .../2-practice-tdd/get-ordinal-number.test.js | 45 +++++++++++++++++++ 1 file changed, 45 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 adfa58560..e15b5aad6 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -10,6 +10,7 @@ const getOrdinalNumber = require("./get-ordinal-number"); // 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. @@ -18,3 +19,47 @@ 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(22)).toEqual("22nd"); + expect(getOrdinalNumber(102)).toEqual("102nd"); +}); + + +// 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(23)).toEqual("23rd"); + expect(getOrdinalNumber(503)).toEqual("503rd"); +}); + + +// Case 4: Numbers ending with 11, 12, or 13 +// When the number ends with 11, 12, or 13, +// Then the function should return a string by appending "th" to the number. +test("should append 'th' for numbers ending with 11, 12, or 13", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); + expect(getOrdinalNumber(111)).toEqual("111th"); + expect(getOrdinalNumber(112)).toEqual("112th"); + expect(getOrdinalNumber(113)).toEqual("113th"); +}); + + +// Case 5: All other numbers +// For numbers not ending in 1, 2, or 3 (and not 11–13), +// The function should return a string by appending "th". +test("should append 'th' for all other numbers", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(10)).toEqual("10th"); + expect(getOrdinalNumber(25)).toEqual("25th"); + expect(getOrdinalNumber(100)).toEqual("100th"); +});