@@ -33,23 +33,35 @@ expect(repeatedStr).toEqual("hello")
3333// When the repeat 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
36- // test("should return an empty string", ()=>{
37- // const str = "hello";
38- // const count = 0;
39- // const repeatedStr = repeat(str, count);
40- // expect(repeatedStr).toEqual("");
41- // })
36+ test ( "should return an empty string" , ( ) => {
37+ const str = "hello" ;
38+ const count = 0 ;
39+ const repeatedStr = repeat ( str , count ) ;
40+ expect ( repeatedStr ) . toEqual ( "" ) ;
41+ } )
42+
43+ // case: Handle Count of Undefined:
44+ // Given a target string str and a count equal to Undefined,
45+ // When the repeat function is called with these inputs,
46+ // Then it should return an error message.
47+
48+ test ( "should return an error message" , ( ) => {
49+ const str = "hello" ;
50+ const count = undefined ;
51+ const repeatedStr = repeat ( str , count ) ;
52+ expect ( repeatedStr ) . toEqual ( "Error : count must be a positive integer" ) ;
53+ } )
4254
4355// case: Negative Count:
4456// Given a target string str and a negative integer count,
4557// When the repeat function is called with these inputs,
4658// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
4759
48- test ( "should return error" , ( ) => {
60+ test ( "should return an error message " , ( ) => {
4961 const str = "hello" ;
5062 const count = - 1 ;
5163 const repeatedStr = repeat ( str , count ) ;
52- expect ( repeatedStr ) . toEqual ( "Error: negative numbers are not valid " ) ;
64+ expect ( repeatedStr ) . toEqual ( "Error : count must be a positive integer " ) ;
5365} )
5466
5567// case: Handle empty string:
@@ -69,19 +81,19 @@ test("should return an empty string", () => {
6981// When the repeat function is called with these inputs,
7082// Then it should repeat the str count times and return a new string containing the repeated str values.
7183
72- test ( "should return an empty string" , ( ) => {
84+ test ( "should repeat the string count times " , ( ) => {
7385 const str = "a b" ;
7486 const count = 2 ;
7587 const repeatedStr = repeat ( str , count ) ;
7688 expect ( repeatedStr ) . toEqual ( "a ba b" ) ;
7789} ) ;
7890
7991// case: Handle long string :
80- // Given a target string str and a count equal to1 ,
92+ // Given a target string str and a count equal to 1 ,
8193// When the repeat function is called with these inputs,
8294// Then it should repeat the str count times and return a new string containing the repeated str values.
8395
84- test ( "should return an empty string" , ( ) => {
96+ test ( "should not repeat the string" , ( ) => {
8597 const str = "xvg56756yrhfghe5ujdfh45657tjrtg6yrthrty" ;
8698 const count = 1 ;
8799 const repeatedStr = repeat ( str , count ) ;
@@ -93,7 +105,7 @@ test("should return an empty string", () => {
93105// When the repeat function is called with these inputs,
94106// Then it should repeat the str count times and return a new string containing the repeated str values.
95107
96- test ( "should return an empty string " , ( ) => {
108+ test ( "should repeat str 18 times " , ( ) => {
97109 const str = "x" ;
98110 const count = 18 ;
99111 const repeatedStr = repeat ( str , count ) ;
0 commit comments