File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,3 +22,40 @@ 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+ test ( "should return 0 if no occurences of a character" , ( ) => {
26+ const str = "fruit" ;
27+ const char = "p" ;
28+ const count = countChar ( str , char ) ;
29+ expect ( count ) . toBe ( 0 ) ;
30+ } ) ;
31+
32+ // Scenario: Empty String
33+ test ( "should return 0 if the string is empty" , ( ) => {
34+ const str = "" ;
35+ const char = "a" ;
36+ const count = countChar ( str , char ) ;
37+ expect ( count ) . toBe ( 0 ) ;
38+ } ) ;
39+
40+ // Scenario: Empty character
41+ test ( "should return 0 if the character is empty" , ( ) => {
42+ const str = "fruit" ;
43+ const char = "" ;
44+ const count = countChar ( str , char ) ;
45+ expect ( count ) . toBe ( 0 ) ;
46+ } ) ;
47+
48+ // Scenario: Single character found
49+ test ( "should return 1 if single occurrence of a character" , ( ) => {
50+ const str = "fruit" ;
51+ const char = "r" ;
52+ const count = countChar ( str , char ) ;
53+ expect ( count ) . toBe ( 1 ) ;
54+ } ) ;
55+
56+ test ( "should be case sensitive" , ( ) => {
57+ const str = "coMmand" ;
58+ const char = "m" ;
59+ const count = countChar ( str , char ) ;
60+ expect ( count ) . toBe ( 1 ) ;
61+ } ) ;
You can’t perform that action at this time.
0 commit comments