@@ -9,13 +9,18 @@ import { repeatStr } from "./repeat-str.js";
99// When the repeatStr function is called with these inputs,
1010// Then it should return a string that contains the original `str` repeated `count` times.
1111
12- // Case: handle count of 1, 2, 3, 4:
12+ // Case: handle count of 1:
13+ // Given a target string `str` and a `count` equal to 1,
14+ // When the repeatStr function is called with these inputs,
15+ // Then it should return the original `str` without repetition.
16+
1317test ( "should repeat the string 1 times" , ( ) => {
1418 const str = "hello" ;
1519 const count = 1 ;
1620 const repeatedStr = repeatStr ( str , count ) ;
1721 expect ( repeatedStr ) . toEqual ( "hello" ) ;
1822} ) ;
23+ // Case: handle count of 2, 3, 4:
1924test ( "should repeat the string 2 times" , ( ) => {
2025 const str = "hello" ;
2126 const count = 2 ;
@@ -35,14 +40,17 @@ test("should repeat the string 4 times", () => {
3540 expect ( repeatedStr ) . toEqual ( "hellohellohellohello" ) ;
3641} ) ;
3742// Case: Handle count of 0:
43+ // Given a target string `str` and a `count` equal to 0,
44+ // When the repeatStr function is called with these inputs,
45+ // Then it should return an empty string.
3846test ( "should repeat the string 0 times" , ( ) => {
3947 const str = "hello" ;
4048 const count = 0 ;
4149 const repeatedStr = repeatStr ( str , count ) ;
4250 expect ( repeatedStr ) . toEqual ( "" ) ;
4351} ) ;
4452//case: Handle decimal count:
45- test ( "should repeat the stringthe whole number in the count times " , ( ) => {
53+ test ( "should repeat the string rounded down times when decimal count is given " , ( ) => {
4654 const str = "hello" ;
4755 const count = 2.5 ;
4856 const repeatedStr = repeatStr ( str , count ) ;
@@ -56,5 +64,5 @@ test("should throw an error when -1 count is given", () => {
5664 expect ( ( ) => repeatStr ( "hello" , - 1 ) ) . toThrow ( "Negative counts are not valid" ) ;
5765} ) ;
5866test ( `should throw an error when string is empty` , ( ) => {
59- expect ( ( ) => repeatStr ( " " , 1 ) ) . toThrow ( "String shoild not be empty" ) ;
67+ expect ( ( ) => repeatStr ( "" , 1 ) ) . toThrow ( "String should not be empty" ) ;
6068} ) ;
0 commit comments