@@ -20,13 +20,99 @@ 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-
23+ test ( "should return the original string when count is 1" , ( ) => {
24+ const str = "world" ;
25+ const count = 1 ;
26+ const repeatedStr = repeatStr ( str , count ) ;
27+ expect ( repeatedStr ) . toEqual ( "world" ) ;
28+ } ) ;
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 an empty string when count is 0" , ( ) => {
34+ const str = "test" ;
35+ const count = 0 ;
36+ const repeatedStr = repeatStr ( str , count ) ;
37+ expect ( repeatedStr ) . toEqual ( "" ) ;
38+ } ) ;
2839
2940// Case: Handle negative count:
3041// Given a target string `str` and a negative integer `count`,
3142// When the repeatStr function is called with these inputs,
3243// Then it should throw an error, as negative counts are not valid.
44+ test ( "should throw an error for negative count" , ( ) => {
45+ const str = "error" ;
46+ const count = - 2 ;
47+ expect ( ( ) => repeatStr ( str , count ) ) . toThrow (
48+ "Count must be a non-negative integer"
49+ ) ;
50+ } ) ;
51+
52+ test ( "should throw an error for non-integer count" , ( ) => {
53+ const str = "error" ;
54+ const count = 2.5 ;
55+ expect ( ( ) => repeatStr ( str , count ) ) . toThrow (
56+ "Count must be a non-negative integer"
57+ ) ;
58+ } ) ;
59+
60+ test ( "should throw an error for non-string input" , ( ) => {
61+ const str = 123 ;
62+ const count = 3 ;
63+ expect ( ( ) => repeatStr ( str , count ) ) . toThrow (
64+ "First argument must be a string"
65+ ) ;
66+ } ) ;
67+
68+ test ( "should throw an error for null or undefined input" , ( ) => {
69+ const count = 3 ;
70+ expect ( ( ) => repeatStr ( null , count ) ) . toThrow (
71+ "First argument must be a string"
72+ ) ;
73+ expect ( ( ) => repeatStr ( undefined , count ) ) . toThrow (
74+ "First argument must be a string"
75+ ) ;
76+ } ) ;
77+
78+ test ( "handle empty string input" , ( ) => {
79+ const str = "" ;
80+ const count = 5 ;
81+ const repeatedStr = repeatStr ( str , count ) ;
82+ expect ( repeatedStr ) . toEqual ( "" ) ;
83+ } ) ;
84+
85+ test ( "handle large count input" , ( ) => {
86+ const str = "a" ;
87+ const count = 1000 ;
88+ const repeatedStr = repeatStr ( str , count ) ;
89+ expect ( repeatedStr ) . toEqual ( "a" . repeat ( count ) ) ;
90+ } ) ;
91+
92+ test ( "handle special characters in string" , ( ) => {
93+ const str = "!@#" ;
94+ const count = 4 ;
95+ const repeatedStr = repeatStr ( str , count ) ;
96+ expect ( repeatedStr ) . toEqual ( "!@#!@#!@#!@#" ) ;
97+ } ) ;
98+
99+ test ( "handle whitespace in string" , ( ) => {
100+ const str = " " ;
101+ const count = 3 ;
102+ const repeatedStr = repeatStr ( str , count ) ;
103+ expect ( repeatedStr ) . toEqual ( " " ) ;
104+ } ) ;
105+
106+ test ( "repeats unicode characters correctly" , ( ) => {
107+ const str = "π" ;
108+ const count = 5 ;
109+ const repeatedStr = repeatStr ( str , count ) ;
110+ expect ( repeatedStr ) . toEqual ( "πππππ" ) ;
111+ } ) ;
112+
113+ test ( "handles empty string" , ( ) => {
114+ const str = "" ;
115+ const count = 5 ;
116+ const repeatedStr = repeatStr ( str , count ) ;
117+ expect ( repeatedStr ) . toEqual ( "" ) ;
118+ } ) ;
0 commit comments