@@ -22,3 +22,38 @@ test("should count multiple occurrences of a character", () => {
2222// And a character `char` that does not exist within `str`.
2323// When the function is called with these inputs,
2424// Then it should return 0, indicating that no occurrences of `char` were found.
25+
26+ test ( "should return 0 if the character in not in the given string" , ( ) => {
27+ const str = "aaaaa" ;
28+ const char = "b" ;
29+ const count = countChar ( str , char ) ;
30+ expect ( count ) . toEqual ( 0 ) ;
31+ } ) ;
32+
33+ test ( "should return 1 if the is 1 occurrence of the char in the string" , ( ) => {
34+ const str = "abc" ;
35+ const char = "c" ;
36+ const count = countChar ( str , char ) ;
37+ expect ( count ) . toEqual ( 1 ) ;
38+ } ) ;
39+
40+ test ( "should return 0 if there is a empty string " , ( ) => {
41+ const str = "" ;
42+ const char = "c" ;
43+ const count = countChar ( str , char ) ;
44+ expect ( count ) . toEqual ( 0 ) ;
45+ } ) ;
46+
47+ test ( "should return 0 if character is empty" , ( ) => {
48+ const str = "abcdefg" ;
49+ const char = "" ;
50+ const count = countChar ( str , char ) ;
51+ expect ( count ) . toEqual ( 0 ) ;
52+ } ) ;
53+
54+ test ( "should be case insensitive " , ( ) => {
55+ const str = "Successful" ;
56+ const char = "s" ;
57+ const count = countChar ( str , char ) ;
58+ expect ( count ) . toEqual ( 3 ) ;
59+ } ) ;
0 commit comments