@@ -16,6 +16,13 @@ test("should repeat the string count times", () => {
1616 expect ( repeatedStr ) . toEqual ( "hellohellohello" ) ;
1717} ) ;
1818
19+ test ( "should return an empty string when repeating an empty string multiple times" , ( ) => {
20+ const str = "" ;
21+ const count = 3 ;
22+ const repeatedStr = repeatStr ( str , count ) ;
23+ expect ( repeatedStr ) . toEqual ( "" ) ;
24+ } ) ;
25+
1926// Case: handle count of 1:
2027// Given a target string `str` and a `count` equal to 1,
2128// When the repeatStr function is called with these inputs,
@@ -27,6 +34,13 @@ test("should return the original string when count equals 1", () => {
2734 expect ( repeatedStr ) . toEqual ( "hello" ) ;
2835} ) ;
2936
37+ test ( "should return an empty string when count equals 1 and the string is empty" , ( ) => {
38+ const str = "" ;
39+ const count = 1 ;
40+ const repeatedStr = repeatStr ( str , count ) ;
41+ expect ( repeatedStr ) . toEqual ( "" ) ;
42+ } ) ;
43+
3044// Case: Handle count of 0:
3145// Given a target string `str` and a `count` equal to 0,
3246// When the repeatStr function is called with these inputs,
@@ -37,6 +51,12 @@ test("should return an empty string when count equals 0", () => {
3751 const repeatedStr = repeatStr ( str , count ) ;
3852 expect ( repeatedStr ) . toEqual ( "" ) ;
3953} ) ;
54+ test ( "should return an empty string when count equals 0 and the string is empty" , ( ) => {
55+ const str = "" ;
56+ const count = 0 ;
57+ const repeatedStr = repeatStr ( str , count ) ;
58+ expect ( repeatedStr ) . toEqual ( "" ) ;
59+ } ) ;
4060
4161// Case: Handle negative count:
4262// Given a target string `str` and a negative integer `count`,
@@ -47,3 +67,9 @@ test("should throw an error when count is a negative number", () => {
4767 const count = - 2 ;
4868 expect ( ( ) => repeatStr ( str , count ) ) . toThrow ( ) ;
4969} ) ;
70+
71+ test ( "should throw an error when count is negative and the string is empty" , ( ) => {
72+ const str = "" ;
73+ const count = - 2 ;
74+ expect ( ( ) => repeatStr ( str , count ) ) . toThrow ( ) ;
75+ } ) ;
0 commit comments