@@ -20,14 +20,33 @@ test("should repeat the string count times", () => {
2020// Given a target string str and a count equal to 1,
2121// When the repeat function is called with these inputs,
2222// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition.
23+ test ( "should repeat the string count 1 times" , ( ) => {
24+ const str = "str" ;
25+ const count = 1 ;
26+ const repeatedStr = repeat ( str , count ) ;
27+ expect ( repeatedStr ) . toEqual ( "str" ) ;
28+ } ) ;
2329console . log ( repeat ( "str" , 1 ) ) ; // Expected: "str"
2430// case: Handle Count of 0:
2531// Given a target string str and a count equal to 0,
2632// When the repeat function is called with these inputs,
2733// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
2834console . log ( repeat ( "hello" , 0 ) ) ; // Expected: " "
35+
36+ test ( "should repeat the string count 0 times" , ( ) => {
37+ const str = "hello" ;
38+ const count = 0 ;
39+ const repeatedStr = repeat ( str , count ) ;
40+ expect ( repeatedStr ) . toEqual ( "" ) ;
41+ } ) ;
2942// case: Negative Count:
3043// Given a target string str and a negative integer count,
3144// When the repeat function is called with these inputs,
3245// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
3346console . log ( repeat ( "hello" , - 3 ) ) ; // Expected: "Error: Count must be a non-negative integer"
47+ test ( "should repeat the string count -3 times" , ( ) => {
48+ const str = "hello" ;
49+ const count = - 3 ;
50+ const repeatedStr = repeat ( str , count ) ;
51+ expect ( repeatedStr ) . toEqual ( "Error: Count must be a non-negative integer" ) ;
52+ } ) ;
0 commit comments