@@ -20,13 +20,37 @@ test("should repeat the string count times", () => {
2020// Given a target string `str` and a `count` equal to 1,
2121// When the repeatStr function is called with these inputs,
2222// Then it should return the original `str` without repetition.
23+ test ( "should return the original string when count is 1" , ( ) => {
24+ expect ( repeatStr ( "hello" , 1 ) ) . toEqual ( "hello" ) ;
25+ expect ( repeatStr ( "a" , 1 ) ) . toEqual ( "a" ) ;
26+ expect ( repeatStr ( "" , 1 ) ) . toEqual ( "" ) ;
27+ } ) ;
2328
2429// Case: Handle count of 0:
2530// Given a target string `str` and a `count` equal to 0,
2631// When the repeatStr function is called with these inputs,
2732// Then it should return an empty string.
33+ test ( "should return empty string when count is 0" , ( ) => {
34+ expect ( repeatStr ( "hello" , 0 ) ) . toEqual ( "" ) ;
35+ expect ( repeatStr ( "anything" , 0 ) ) . toEqual ( "" ) ;
36+ expect ( repeatStr ( "" , 0 ) ) . toEqual ( "" ) ;
37+ } ) ;
2838
2939// Case: Handle negative count:
3040// Given a target string `str` and a negative integer `count`,
3141// When the repeatStr function is called with these inputs,
3242// Then it should throw an error, as negative counts are not valid.
43+ test ( "should throw error when count is negative" , ( ) => {
44+ expect ( ( ) => repeatStr ( "hello" , - 1 ) ) . toThrow ( ) ;
45+ expect ( ( ) => repeatStr ( "test" , - 5 ) ) . toThrow ( ) ;
46+ expect ( ( ) => repeatStr ( "" , - 3 ) ) . toThrow ( ) ;
47+ } ) ;
48+
49+ // Case: Handle positive count:
50+ // Given an empty string `str`and a positive integer `count`,
51+ // When the repeatStr function is called,
52+ // Then it should return an empty string
53+ test ( "should return empty string when input string is empty" , ( ) => {
54+ expect ( repeatStr ( "" , 5 ) ) . toEqual ( "" ) ;
55+ expect ( repeatStr ( "" , 1 ) ) . toEqual ( "" ) ;
56+ } ) ;
0 commit comments