@@ -20,13 +20,30 @@ test("should repeat the string count times", () => {
2020// Given a target string `str` and a `count` equal to 1,
2121// When the repeatStr function is called with these inputs,
2222// Then it should return the original `str` without repetition.
23+ test ( "should return the original string when count is 1" , ( ) => {
24+ const str = "hello" ;
25+ const count = 1 ;
26+ const repeatedStr = repeatStr ( str , count ) ;
27+ expect ( repeatedStr ) . toEqual ( "hello" ) ;
28+ } ) ;
2329
2430// Case: Handle count of 0:
2531// Given a target string `str` and a `count` equal to 0,
2632// When the repeatStr function is called with these inputs,
2733// Then it should return an empty string.
34+ test ( "should return an empty string when count is 0" , ( ) => {
35+ const str = "hello" ;
36+ const count = 0 ;
37+ const repeatedStr = repeatStr ( str , count ) ;
38+ expect ( repeatedStr ) . toEqual ( "" ) ;
39+ } ) ;
2840
2941// Case: Handle negative count:
3042// Given a target string `str` and a negative integer `count`,
3143// When the repeatStr function is called with these inputs,
3244// Then it should throw an error, as negative counts are not valid.
45+ test ( "should throw an error when count is negative" , ( ) => {
46+ const str = "hello" ;
47+ const count = - 1 ;
48+ expect ( ( ) => repeatStr ( str , count ) ) . toThrow ( "Count must be a non-negative integer" ) ;
49+ } ) ;
0 commit comments