@@ -14,7 +14,7 @@ test("should count multiple occurrences of a character", () => {
1414 const str = "aaaaa" ;
1515 const char = "a" ;
1616 const count = countChar ( str , char ) ;
17- expect ( count ) . toEqual ( 5 ) ;
17+ expect ( parseInt ( count ) ) . toEqual ( 5 ) ;
1818} ) ;
1919
2020// Scenario: No Occurrences
@@ -27,5 +27,29 @@ test("should return 0 when character does not exist in the string", () => {
2727 const str = "abcdefg" ;
2828 const char = "h" ;
2929 const count = countChar ( str , char ) ;
30- expect ( count ) . toEqual ( 0 ) ;
30+ expect ( parseInt ( count ) ) . toEqual ( 0 ) ;
31+ } ) ;
32+
33+ // test for empty string
34+ test ( "should return 0 when string is empty" , ( ) => {
35+ const str = "" ;
36+ const char = "a" ;
37+ const count = countChar ( str , char ) ;
38+ expect ( parseInt ( count ) ) . toEqual ( 0 ) ;
39+ } ) ;
40+
41+ // test for str is an array
42+ test ( "should return 0 when str is an array" , ( ) => {
43+ const str = [ "a" , "b" , "c" ] ;
44+ const char = "a" ;
45+ const count = countChar ( str , char ) ;
46+ expect ( parseInt ( count ) ) . toEqual ( 1 ) ;
47+ } ) ;
48+
49+ // test for str is a number
50+ test ( "should return 0 when str is a number" , ( ) => {
51+ const str = 12345 ;
52+ const char = "3" ;
53+ const count = countChar ( str , char ) ;
54+ expect ( parseInt ( count ) ) . toEqual ( 1 ) ;
3155} ) ;
0 commit comments