@@ -16,17 +16,23 @@ test("should repeat the string count times", () => {
1616 expect ( repeatedStr ) . toEqual ( "hellohellohello" ) ;
1717} ) ;
1818
19- // case: handle Count of 1:
20- // Given a target string str and a count equal to 1,
21- // When the repeatStr function is called with these inputs,
22- // Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition.
19+ test ( "should return the original string without repetition" , ( ) => {
20+ const str = "hello" ;
21+ const count = 1 ;
22+ const repeatedStr = repeatStr ( str , count ) ;
23+ expect ( repeatedStr ) . toEqual ( "hello" ) ;
24+ } ) ;
2325
24- // case: Handle Count of 0:
25- // Given a target string str and a count equal to 0,
26- // When the repeatStr function is called with these inputs,
27- // Then it should return an empty string, ensuring that a count of 0 results in an empty output.
26+ test ( "should return an empty string if count is 0" , ( ) => {
27+ const str = "hello" ;
28+ const count = 0 ;
29+ const repeatedStr = repeatStr ( str , count ) ;
30+ expect ( repeatedStr ) . toEqual ( "" ) ;
31+ } ) ;
2832
29- // case: Negative Count:
30- // Given a target string str and a negative integer count,
31- // When the repeatStr function is called with these inputs,
32- // Then it should throw an error or return an appropriate error message, as negative counts are not valid.
33+ test ( "should throw an error if count is negative" , ( ) => {
34+ const str = "hello" ;
35+ const count = - 1 ;
36+ const repeatedStr = repeatStr ( str , count ) ;
37+ expect ( repeatedStr ) . toEqual ( "Error, negative integer" ) ;
38+ } ) ;
0 commit comments