1- // implement a function countChar that counts the number of times a character occurs in a string
21const countChar = require ( "./count" ) ;
32// Given a string `str` and a single character `char` to search for,
43// When the countChar function is called with these inputs,
5- // Then it should:
4+ // Then it should:
5+ test ( "should count occurrences of a character" , ( ) => {
6+ expect ( countChar ( "tired" , "d" ) ) . toEqual ( 1 )
7+ } )
68
7- // Scenario: Multiple Occurrences
8- // Given the input string `str`,
9- // And a character `char` that occurs one or more times in `str` (e.g., 'a' in 'aaaaa'),
10- // When the function is called with these inputs,
11- // Then it should correctly count occurrences of `char`.
129
13- test ( "should count multiple occurrences of a character" , ( ) => {
14- const str = "aaaaa" ;
15- const char = "a" ;
16- const count = countChar ( str , char ) ;
17- expect ( count ) . toEqual ( 5 ) ;
18- } ) ;
19-
20- // Scenario: No Occurrences
10+ // Scenario: Multiple Occurrences
2111// Given the input string `str`,
2212// And a character `char` that does not exist within `str`.
2313// When the function is called with these inputs,
2414// Then it should return 0, indicating that no occurrences of `char` were found.
15+ test ( "should count no occurrences of a character" , ( ) => {
16+ expect ( countChar ( "bananataste" , "w" ) ) . toEqual ( 0 )
17+ } )
0 commit comments