@@ -9,24 +9,41 @@ const repeat = require("./repeat");
99// When the repeat function is called with these inputs,
1010// Then it should repeat the str count times and return a new string containing the repeated str values.
1111
12+ // Case 1: Repeats String coun times.
13+
1214test ( "should repeat the string count times" , ( ) => {
1315 const str = "hello" ;
1416 const count = 3 ;
1517 const repeatedStr = repeat ( str , count ) ;
1618 expect ( repeatedStr ) . toEqual ( "hellohellohello" ) ;
1719} ) ;
1820
19- // case: handle Count of 1:
20- // Given a target string str and a count equal to 1,
21- // When the repeat 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.
21+ // case 2: handle Count of 1:
2322
24- // case: Handle Count of 0:
25- // Given a target string str and a count equal to 0,
26- // When the repeat 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.
23+ test ( "should return the original string when count is 1" , ( ) => {
24+ const str = "hello" ;
25+ const count = 1 ;
26+ expect ( repeat ( str , count ) ) . toEqual ( "hello" ) ;
27+ } ) ;
28+ // Returns the original str without repetition, ensuring that a count of 1 results in no repetition.
2829
29- // case: Negative Count:
30- // Given a target string str and a negative integer count,
31- // When the repeat 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.
30+ // case 3: Handle Count of 0:
31+
32+ test ( "should return an empty string when count is 0" , ( ) => {
33+ const str = "hello" ;
34+ const count = 0 ;
35+ expect ( repeat ( str , count ) ) . toEqual ( "" ) ;
36+ } ) ;
37+
38+ // Returns an empty string, ensuring that a count of 0 results in an empty output.
39+
40+ // Case 4: Negative count
41+
42+ test ( "should throw an error when count is negative" , ( ) => {
43+ const str = "hello" ;
44+ const count = - 2 ;
45+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Count must be a non-negative integer" ) ;
46+ } ) ;
47+ // Throws an error or return an appropriate error message, as negative counts are not valid.
48+
49+ // Tested for all case using npx jest
0 commit comments