1- // Implement a function repeat
2- const repeat = require ( "./repeat" ) ;
1+ // Implement a function repeatStr
2+ const repeatStr = require ( "./repeat-str " ) ;
33// Given a target string str and a positive integer count,
4- // When the repeat function is called with these inputs,
4+ // When the repeatStr function is called with these inputs,
55// Then it should:
66
77// case: repeat String:
88// Given a target string str and a positive integer count,
9- // When the repeat function is called with these inputs,
9+ // When the repeatStr 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
1212test ( "should repeat the string count times" , ( ) => {
1313 const str = "hello" ;
1414 const count = 3 ;
15- const repeatedStr = repeat ( str , count ) ;
15+ const repeatedStr = repeatStr ( str , count ) ;
1616 expect ( repeatedStr ) . toEqual ( "hellohellohello" ) ;
1717} ) ;
1818
1919// case: handle Count of 1:
2020// Given a target string str and a count equal to 1,
21- // When the repeat function is called with these inputs,
21+ // When the repeatStr 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.
2323
2424test ( "should return the original string when count is 1" , ( ) => {
2525 const str = "hello" ;
2626 const count = 1 ;
27- const repeatedStr = repeat ( str , count ) ;
27+ const repeatedStr = repeatStr ( str , count ) ;
2828 expect ( repeatedStr ) . toEqual ( "hello" ) ;
2929} ) ;
3030
3131// case: Handle Count of 0:
3232// Given a target string str and a count equal to 0,
33- // When the repeat function is called with these inputs,
33+ // When the repeatStr function is called with these inputs,
3434// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
3535
3636test ( "should return an empty string when count is 0" , ( ) => {
3737 const str = "hello" ;
3838 const count = 0 ;
39- const repeatedStr = repeat ( str , count ) ;
39+ const repeatedStr = repeatStr ( str , count ) ;
4040 expect ( repeatedStr ) . toEqual ( "" ) ;
4141} ) ;
4242
4343// case: Negative Count:
4444// Given a target string str and a negative integer count,
45- // When the repeat function is called with these inputs,
45+ // When the repeatStr function is called with these inputs,
4646// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
4747
4848test ( "should throw an error for negative count" , ( ) => {
4949 const str = "hello" ;
5050 const count = - 3 ;
51- expect ( ( ) => repeat ( str , count ) ) . toThrow ( "count cannot be negative" ) ;
51+ expect ( ( ) => repeatStr ( str , count ) ) . toThrow ( "count cannot be negative" ) ;
5252} ) ;
0 commit comments