@@ -22,3 +22,37 @@ 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 when no occurrence of 'char' is found in 'str'" , ( ) => {
26+ const str = "cde" ;
27+ const char = "a" ;
28+ const count = countChar ( str , char ) ;
29+ expect ( count ) . toEqual ( 0 ) ;
30+ } ) ;
31+
32+ // Scenario: Empty string
33+ // Given an empty string `str`
34+ // And a single character `char`
35+ // When countChar is called
36+ // Then it should return 0
37+ test ( "should return 0 when the string is empty" , ( ) => {
38+ const str = "" ;
39+ const char = "a" ;
40+
41+ const count = countChar ( str , char ) ;
42+
43+ expect ( count ) . toEqual ( 0 ) ;
44+ } ) ;
45+
46+ // Scenario: One Occurrence
47+ // Given a string `str`
48+ // And a single character `char` that occurs once in `str`
49+ // When countChar is called
50+ // Then it should return 1
51+ test ( "should count one occurrence of a character" , ( ) => {
52+ const str = "abcde" ;
53+ const char = "a" ;
54+
55+ const count = countChar ( str , char ) ;
56+
57+ expect ( count ) . toEqual ( 1 ) ;
58+ } ) ;
0 commit comments