11// Implement a function repeat
22const repeat = require ( "./repeat" ) ;
3+
34// Given a target string str and a positive integer count,
45// When the repeat function is called with these inputs,
56// Then it should:
@@ -20,13 +21,32 @@ test("should repeat the string count times", () => {
2021// Given a target string str and a count equal to 1,
2122// When the repeat function is called with these inputs,
2223// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition.
24+ test ( "should return the original string when count is 1" , ( ) => {
25+ const str = "hello" ;
26+ const count = 1 ;
27+ const repeatedStr = repeat ( str , count ) ;
28+ expect ( repeatedStr ) . toEqual ( "hello" ) ;
29+ } ) ;
2330
2431// case: Handle Count of 0:
2532// Given a target string str and a count equal to 0,
2633// When the repeat function is called with these inputs,
2734// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
35+ test ( "should return an empty string when count is 0" , ( ) => {
36+ const str = "hello" ;
37+ const count = 0 ;
38+ const repeatedStr = repeat ( str , count ) ;
39+ expect ( repeatedStr ) . toEqual ( "" ) ;
40+ } ) ;
2841
2942// case: Negative Count:
3043// Given a target string str and a negative integer count,
3144// When the repeat function is called with these inputs,
3245// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
46+ test ( "should throw an error for negative count" , ( ) => {
47+ const str = "hello" ;
48+ const count = - 2 ;
49+ expect ( ( ) => {
50+ repeat ( str , count ) ;
51+ } ) . toThrow ( "Invalid count value" ) ;
52+ } ) ;
0 commit comments