File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 1+ // implement a function countChar that counts the number of times a character occurs in a string
12const countChar = require ( "./count" ) ;
23// Given a string `str` and a single character `char` to search for,
34// When the countChar function is called with these inputs,
@@ -9,6 +10,19 @@ test("should count occurrences of a character", () => {
910
1011// Scenario: Multiple Occurrences
1112// Given the input string `str`,
13+ // And a character `char` that occurs one or more times in `str` (e.g., 'a' in 'aaaaa'),
14+ // When the function is called with these inputs,
15+ // Then it should correctly count occurrences of `char`.
16+
17+ test ( "should count multiple occurrences of a character" , ( ) => {
18+ const str = "aaaaa" ;
19+ const char = "a" ;
20+ const count = countChar ( str , char ) ;
21+ expect ( count ) . toEqual ( 5 ) ;
22+ } ) ;
23+
24+ // Scenario: No Occurrences
25+ // Given the input string `str`,
1226// And a character `char` that does not exist within `str`.
1327// When the function is called with these inputs,
1428// Then it should return 0, indicating that no occurrences of `char` were found.
You can’t perform that action at this time.
0 commit comments