@@ -20,13 +20,23 @@ 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-
23+ test ( "should repeat the string count times" , ( ) => {
24+ const str = "hello" ;
25+ const count = 1 ;
26+ const repeatedStr = repeat ( str , count ) ;
27+ expect ( repeatedStr ) . toEqual ( "hello" ) ;
28+ } ) ;
2429// case: Handle Count of 0:
2530// Given a target string str and a count equal to 0,
2631// When the repeat function is called with these inputs,
2732// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
28-
33+ test ( "should return empty string when times is 0" , ( ) => {
34+ expect ( repeat ( "hello" , 0 ) ) . toEqual ( "" ) ;
35+ } ) ;
2936// case: Negative Count:
3037// Given a target string str and a negative integer count,
3138// When the repeat function is called with these inputs,
3239// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
40+ test ( "should throw an error when count is negative" , ( ) => {
41+ expect ( ( ) => repeat ( "hello" , - 3 ) ) . toThrow ( "Count must be a non-negative number" ) ;
42+ } ) ;
0 commit comments