diff --git a/.gitignore b/.gitignore index bde36e530..e7509451d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,39 @@ -node_modules +# Generated .gitignore file for: Node, JavaScript +# Created with FOSSA's DevOps Tools + +# Node +node_modules/ +npm-debug.log +yarn-error.log +.env .DS_Store -.vscode -**/.DS_Store \ No newline at end of file +dist/ +.cache/ +coverage/ + +# JavaScript +# Add JavaScript-specific ignores here +package-lock.json + +# Notebooks and documentation +docs/ + +# Common +.DS_Store +Thumbs.db +*.log +*.bak +*.tmp +*.swp +*~ + +# IDE and editor generated files +.idea/ +*.sublime-* +.vscode/ +.devcontainer/ + +# Local environment files +.env +.env.local +.env.*.local 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 ca1dfe7f2..e00bb9264 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 @@ -8,19 +8,15 @@ // Then, write the next test! :) Go through this process until all the cases are implemented function getAngleType(angle) { - if (angle === 90) { - return "Right angle"; - } - // Run the tests, work out what Case 2 is testing, and implement the required code here. - // Then keep going for the other cases, one at a time. + if (angle === 90) return "Right angle"; + if (angle < 90) return "Acute angle"; + if (angle > 90 && angle < 180) return "Obtuse angle"; + if (angle === 180) return "Straight angle"; + if (angle > 180 && angle < 360) return "Reflex 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; -// we're going to use this helper function 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, @@ -28,36 +24,19 @@ function assertEquals(actualOutput, targetOutput) { ); } -// Acceptance criteria: - -// Given an angle in degrees, -// When the function getAngleType is called with this angle, -// Then it should: - -// Case 1: Identify Right Angles: -// When the angle is exactly 90 degrees, -// Then the function should return "Right angle" -const right = getAngleType(90); -assertEquals(right, "Right angle"); - -// Case 2: Identify Acute Angles: -// When the angle is less than 90 degrees, -// Then the function should return "Acute angle" -const acute = getAngleType(45); -assertEquals(acute, "Acute angle"); - -// Case 3: Identify Obtuse Angles: -// When the angle is greater than 90 degrees and less than 180 degrees, -// Then the function should return "Obtuse angle" -const obtuse = getAngleType(120); -// ====> write your test here, and then add a line to pass the test in the function above - -// Case 4: Identify Straight Angles: -// When the angle is exactly 180 degrees, -// Then the function should return "Straight angle" -// ====> write your test here, and then add a line to pass the test in the function above - -// Case 5: Identify Reflex Angles: -// When the angle is greater than 180 degrees and less than 360 degrees, -// Then the function should return "Reflex angle" -// ====> write your test here, and then add a line to pass the test in the function above \ No newline at end of file +// Case 1: Identify Right Angles (90°) +assertEquals(getAngleType(90), "Right angle"); + +// Case 2: Identify Acute Angles (< 90°) +assertEquals(getAngleType(45), "Acute angle"); + +// Case 3: Identify Obtuse Angles (> 90° and < 180°) +assertEquals(getAngleType(120), "Obtuse angle"); + +// Case 4: Identify Straight Angles (180°) +assertEquals(getAngleType(180), "Straight angle"); + +// Case 5: Identify Reflex Angles (> 180° and < 360°) +assertEquals(getAngleType(270), "Reflex angle"); + +console.log("✅ All tests passed!"); 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 a4739af77..ec97f948b 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 @@ -8,16 +8,11 @@ // write one test at a time, and make it pass, build your solution up methodically function isProperFraction(numerator, denominator) { - if (numerator < denominator) { - return true; - } + return Math.abs(numerator) < 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 function assertEquals(actualOutput, targetOutput) { console.assert( actualOutput === targetOutput, @@ -25,35 +20,16 @@ function assertEquals(actualOutput, targetOutput) { ); } -// Acceptance criteria: - -// Proper Fraction check: -// Input: numerator = 2, denominator = 3 -// target output: true -// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true. -const properFraction = isProperFraction(2, 3); -assertEquals(properFraction, true); - -// Improper Fraction check: -// Input: numerator = 5, denominator = 2 -// target output: false -// Explanation: The fraction 5/2 is an improper fraction, where the numerator is greater than or equal to the denominator. The function should return false. -const improperFraction = isProperFraction(5, 2); -assertEquals(improperFraction, false); - -// Negative Fraction check: -// Input: numerator = -4, denominator = 7 -// target output: true -// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. -const negativeFraction = isProperFraction(-4, 7); -// ====> complete with your assertion - -// Equal Numerator and Denominator check: -// Input: numerator = 3, denominator = 3 -// target output: false -// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. -const equalFraction = isProperFraction(3, 3); -// ====> complete with your assertion - -// Stretch: -// What other scenarios could you test for? +// Proper Fraction: 2/3 → true +assertEquals(isProperFraction(2, 3), true); + +// Improper Fraction: 5/2 → false +assertEquals(isProperFraction(5, 2), false); + +// Negative Fraction: -4/7 → true (absolute value < denominator) +assertEquals(isProperFraction(-4, 7), true); + +// Equal Numerator and Denominator: 3/3 → false +assertEquals(isProperFraction(3, 3), false); + +console.log("✅ All tests passed!"); 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 266525d1b..588c711bf 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 @@ -8,50 +8,46 @@ // write one test at a time, and make it pass, build your solution up methodically // just make one change at a time -- don't rush -- programmers are deep and careful thinkers function getCardValue(card) { - if (rank === "A") { - return 11; - } + const rank = card.slice(0, -1); + if (rank === "A") return 11; + if (rank === "J" || rank === "Q" || rank === "K" || rank === "10") return 10; + const numValue = parseInt(rank); + if (numValue >= 2 && numValue <= 9) return numValue; + 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; -// You need to write assertions for your function to check it works in different cases -// we're going to use this helper function 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}` ); } -// Acceptance criteria: - -// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A), -// When the function getCardValue is called with this card string as input, -// Then it should return the numerical card value -const aceofSpades = getCardValue("A♠"); -assertEquals(aceofSpades, 11); - -// Handle Number Cards (2-10): -// Given a card with a rank between "2" and "9", -// When the function is called with such a card, -// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). -const fiveofHearts = getCardValue("5♥"); -// ====> write your test here, and then add a line to pass the test in the function above - -// Handle Face Cards (J, Q, K): -// Given a card with a rank of "10," "J," "Q," or "K", -// When the function is called with such a card, -// Then it should return the value 10, as these cards are worth 10 points each in blackjack. - -// Handle Ace (A): -// Given a card with a rank of "A", -// When the function is called with an Ace, -// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. - -// Handle Invalid Cards: -// Given a card with an invalid rank (neither a number nor a recognized face card), -// When the function is called with such a card, -// Then it should throw an error indicating "Invalid card rank." + +// Ace → 11 +assertEquals(getCardValue("A♠"), 11); + +// Number Cards → numeric value +assertEquals(getCardValue("5♥"), 5); +assertEquals(getCardValue("2♦"), 2); +assertEquals(getCardValue("9♣"), 9); + +// Face Cards (J, Q, K, 10) → 10 +assertEquals(getCardValue("K♥"), 10); +assertEquals(getCardValue("Q♠"), 10); +assertEquals(getCardValue("J♦"), 10); +assertEquals(getCardValue("10♣"), 10); + +// Ace (all suits) → 11 +assertEquals(getCardValue("A♥"), 11); + +// Invalid Card → throw error +try { + getCardValue("X♠"); + console.assert(false, "Should have thrown an error for invalid card"); +} catch (error) { + assertEquals(error.message, "Invalid card rank"); +} + +console.log("✅ All tests passed!"); 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 4a92a3e82..96ad9df58 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 @@ -1,26 +1,30 @@ -// This statement loads the getAngleType function you wrote in the implement directory. -// We will use the same function, but write tests for it using Jest in this file. const getAngleType = require("../implement/1-get-angle-type"); test("should identify right angle (90°)", () => { expect(getAngleType(90)).toEqual("Right angle"); }); -// REPLACE the comments with the tests -// make your test descriptions as clear and readable as possible - -// Case 2: Identify Acute Angles: -// When the angle is less than 90 degrees, -// Then the function should return "Acute angle" +test("should identify acute angle (< 90°)", () => { + expect(getAngleType(45)).toEqual("Acute angle"); + expect(getAngleType(30)).toEqual("Acute angle"); + expect(getAngleType(1)).toEqual("Acute angle"); + expect(getAngleType(89)).toEqual("Acute angle"); +}); -// Case 3: Identify Obtuse Angles: -// When the angle is greater than 90 degrees and less than 180 degrees, -// Then the function should return "Obtuse angle" +test("should identify obtuse angle (> 90° and < 180°)", () => { + expect(getAngleType(120)).toEqual("Obtuse angle"); + expect(getAngleType(135)).toEqual("Obtuse angle"); + expect(getAngleType(91)).toEqual("Obtuse angle"); + expect(getAngleType(179)).toEqual("Obtuse angle"); +}); -// Case 4: Identify Straight Angles: -// When the angle is exactly 180 degrees, -// Then the function should return "Straight angle" +test("should identify straight angle (180°)", () => { + expect(getAngleType(180)).toEqual("Straight angle"); +}); -// Case 5: Identify Reflex Angles: -// When the angle is greater than 180 degrees and less than 360 degrees, -// Then the function should return "Reflex angle" +test("should identify reflex angle (> 180° and < 360°)", () => { + expect(getAngleType(270)).toEqual("Reflex angle"); + expect(getAngleType(181)).toEqual("Reflex angle"); + expect(getAngleType(359)).toEqual("Reflex angle"); + expect(getAngleType(200)).toEqual("Reflex 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 caf08d15b..521391d2b 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,13 +1,23 @@ -// 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 for a proper fraction", () => { expect(isProperFraction(2, 3)).toEqual(true); }); -// Case 2: Identify Improper Fractions: +test("should return false for an improper fraction (numerator >= denominator)", () => { + expect(isProperFraction(5, 2)).toEqual(false); + expect(isProperFraction(10, 3)).toEqual(false); + expect(isProperFraction(7, 7)).toEqual(false); +}); -// Case 3: Identify Negative Fractions: +test("should return true for a negative proper fraction (|numerator| < denominator)", () => { + expect(isProperFraction(-4, 7)).toEqual(true); + expect(isProperFraction(-2, 5)).toEqual(true); + expect(isProperFraction(-1, 10)).toEqual(true); +}); -// Case 4: Identify Equal Numerator and Denominator: +test("should return false when numerator equals denominator", () => { + expect(isProperFraction(3, 3)).toEqual(false); + expect(isProperFraction(1, 1)).toEqual(false); + expect(isProperFraction(100, 100)).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 04418ff72..74ecdd270 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,13 +1,37 @@ -// 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. const getCardValue = require("../implement/3-get-card-value"); test("should return 11 for Ace of Spades", () => { - const aceofSpades = getCardValue("A♠"); - expect(aceofSpades).toEqual(11); + expect(getCardValue("A♠")).toEqual(11); }); -// Case 2: Handle Number Cards (2-10): -// Case 3: Handle Face Cards (J, Q, K): -// Case 4: Handle Ace (A): -// Case 5: Handle Invalid Cards: +test("should return correct value for number cards (2-9)", () => { + expect(getCardValue("2♦")).toEqual(2); + expect(getCardValue("3♣")).toEqual(3); + expect(getCardValue("4♥")).toEqual(4); + expect(getCardValue("5♥")).toEqual(5); + expect(getCardValue("6♠")).toEqual(6); + expect(getCardValue("7♦")).toEqual(7); + expect(getCardValue("8♣")).toEqual(8); + expect(getCardValue("9♥")).toEqual(9); +}); + +test("should return 10 for face cards (J, Q, K, 10)", () => { + expect(getCardValue("10♣")).toEqual(10); + expect(getCardValue("J♦")).toEqual(10); + expect(getCardValue("Q♠")).toEqual(10); + expect(getCardValue("K♥")).toEqual(10); +}); + +test("should return 11 for all Aces", () => { + expect(getCardValue("A♠")).toEqual(11); + expect(getCardValue("A♥")).toEqual(11); + expect(getCardValue("A♦")).toEqual(11); + expect(getCardValue("A♣")).toEqual(11); +}); + +test("should throw an error for invalid card rank", () => { + expect(() => getCardValue("X♠")).toThrow("Invalid card rank"); + expect(() => getCardValue("Z♥")).toThrow("Invalid card rank"); + expect(() => getCardValue("11♦")).toThrow("Invalid card rank"); + expect(() => getCardValue("0♣")).toThrow("Invalid card rank"); +}); diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..d4894bf16 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,9 @@ 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 42baf4b4b..17da1e6d8 100644 --- a/Sprint-3/2-practice-tdd/count.test.js +++ b/Sprint-3/2-practice-tdd/count.test.js @@ -1,24 +1,25 @@ -// implement a function countChar that counts the number of times a character occurs in a string const countChar = require("./count"); -// 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 may occur multiple times with overlaps within str (e.g., 'a' in 'aaaaa'), -// When the function is called with these inputs, -// Then it should correctly count overlapping occurrences of char (e.g., 'a' appears five times in 'aaaaa'). test("should count multiple occurrences of a character", () => { - const str = "aaaaa"; - const char = "a"; - const count = countChar(str, char); - expect(count).toEqual(5); + expect(countChar("aaaaa", "a")).toEqual(5); +}); + +test("should return 0 when character is not found", () => { + expect(countChar("hello", "z")).toEqual(0); +}); + +test("should count a single occurrence of a character", () => { + expect(countChar("hello", "h")).toEqual(1); }); -// Scenario: No Occurrences -// Given the input string str, -// And a character char that does not exist within the case-sensitive str, -// When the function is called with these inputs, -// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. +test("should be case-sensitive", () => { + expect(countChar("Hello", "h")).toEqual(0); +}); + +test("should count uppercase characters separately", () => { + expect(countChar("Hello", "H")).toEqual(1); +}); + +test("should count character occurring multiple times in different positions", () => { + expect(countChar("banana", "a")).toEqual(3); +}); diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db1..185b4ff1e 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,14 @@ function getOrdinalNumber(num) { - return "1st"; + const lastDigit = num % 10; + const lastTwoDigits = num % 100; + + if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13) { + return `${num}th`; + } + if (lastDigit === 1) return `${num}st`; + if (lastDigit === 2) return `${num}nd`; + if (lastDigit === 3) return `${num}rd`; + return `${num}th`; } 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 dfe4b6091..ba25d1796 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.test.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.test.js @@ -1,13 +1,61 @@ const getOrdinalNumber = require("./get-ordinal-number"); -// 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 - -// Case 1: Identify the ordinal number for 1 -// When the number is 1, -// Then the function should return "1st" test("should return '1st' for 1", () => { expect(getOrdinalNumber(1)).toEqual("1st"); }); + +test("should return '2nd' for 2", () => { + expect(getOrdinalNumber(2)).toEqual("2nd"); +}); + +test("should return '3rd' for 3", () => { + expect(getOrdinalNumber(3)).toEqual("3rd"); +}); + +test("should handle numbers ending in 1 (except 11)", () => { + expect(getOrdinalNumber(21)).toEqual("21st"); + expect(getOrdinalNumber(31)).toEqual("31st"); + expect(getOrdinalNumber(101)).toEqual("101st"); +}); + +test("should handle numbers ending in 2 (except 12)", () => { + expect(getOrdinalNumber(22)).toEqual("22nd"); + expect(getOrdinalNumber(42)).toEqual("42nd"); +}); + +test("should handle numbers ending in 3 (except 13)", () => { + expect(getOrdinalNumber(23)).toEqual("23rd"); + expect(getOrdinalNumber(33)).toEqual("33rd"); +}); + +test("should handle special cases 11, 12, 13", () => { + expect(getOrdinalNumber(11)).toEqual("11th"); + expect(getOrdinalNumber(12)).toEqual("12th"); + expect(getOrdinalNumber(13)).toEqual("13th"); +}); + +test("should handle numbers ending in 4-9, 0", () => { + expect(getOrdinalNumber(4)).toEqual("4th"); + expect(getOrdinalNumber(5)).toEqual("5th"); + expect(getOrdinalNumber(10)).toEqual("10th"); +}); + +test("should return '100th' for 100", () => { + expect(getOrdinalNumber(100)).toEqual("100th"); +}); + +test("should return '24th' for 24", () => { + expect(getOrdinalNumber(24)).toEqual("24th"); +}); + +test("should return '111th' for 111", () => { + expect(getOrdinalNumber(111)).toEqual("111th"); +}); + +test("should return '112th' for 112", () => { + expect(getOrdinalNumber(112)).toEqual("112th"); +}); + +test("should return '113th' for 113", () => { + expect(getOrdinalNumber(113)).toEqual("113th"); +}); diff --git a/Sprint-3/2-practice-tdd/repeat.js b/Sprint-3/2-practice-tdd/repeat.js index 00e60d7f3..57f8c10e6 100644 --- a/Sprint-3/2-practice-tdd/repeat.js +++ b/Sprint-3/2-practice-tdd/repeat.js @@ -1,5 +1,12 @@ -function repeat() { - return "hellohellohello"; +function repeat(str, count) { + if (count < 0) throw new Error("Count cannot be negative"); + if (count === 0) return ""; + + let result = ""; + for (let i = 0; i < count; i++) { + result += str; + } + return result; } module.exports = repeat; diff --git a/Sprint-3/2-practice-tdd/repeat.test.js b/Sprint-3/2-practice-tdd/repeat.test.js index 34097b09c..6fef52760 100644 --- a/Sprint-3/2-practice-tdd/repeat.test.js +++ b/Sprint-3/2-practice-tdd/repeat.test.js @@ -1,32 +1,29 @@ -// Implement a function repeat const repeat = require("./repeat"); -// Given a target string str and a positive integer count, -// When the repeat function is called with these inputs, -// Then it should: - -// case: repeat String: -// Given a target string str and a positive integer count, -// When the repeat function is called with these inputs, -// Then it should repeat the str count times and return a new string containing the repeated str values. test("should repeat the string count times", () => { - const str = "hello"; - const count = 3; - const repeatedStr = repeat(str, count); - expect(repeatedStr).toEqual("hellohellohello"); + expect(repeat("hello", 3)).toEqual("hellohellohello"); +}); + +test("should return the original string when count is 1", () => { + expect(repeat("hello", 1)).toEqual("hello"); +}); + +test("should return an empty string when count is 0", () => { + expect(repeat("hello", 0)).toEqual(""); }); -// case: handle Count of 1: -// Given a target string str and a count equal to 1, -// When the repeat function is called with these inputs, -// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. +test("should throw an error when count is negative", () => { + expect(() => repeat("hello", -1)).toThrow("Count cannot be negative"); +}); -// case: Handle Count of 0: -// Given a target string str and a count equal to 0, -// When the repeat function is called with these inputs, -// Then it should return an empty string, ensuring that a count of 0 results in an empty output. +test("should repeat string multiple times", () => { + expect(repeat("abc", 4)).toEqual("abcabcabcabc"); +}); -// case: Negative Count: -// Given a target string str and a negative integer count, -// When the repeat function is called with these inputs, -// Then it should throw an error or return an appropriate error message, as negative counts are not valid. +test("should handle empty string", () => { + expect(repeat("", 5)).toEqual(""); +}); + +test("should handle single character", () => { + expect(repeat("x", 5)).toEqual("xxxxx"); +});