|
| 1 | +// implement a function countChar that counts the number of times a character occurs in a string |
| 2 | +import { countChar } from "./count.js"; |
| 3 | +// Given a string `str` and a single character `char` to search for, |
| 4 | +// When the countChar function is called with these inputs, |
| 5 | +// Then it should: |
| 6 | + |
| 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`. |
| 12 | + |
| 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 |
| 21 | +// Given the input string `str`, |
| 22 | +// And a character `char` that does not exist within `str`. |
| 23 | +// When the function is called with these inputs, |
| 24 | +// Then it should return 0, indicating that no occurrences of `char` were found. |
| 25 | +test("should return 0 when there is not repeated char in str", () => { |
| 26 | + const str = "hello"; |
| 27 | + const char = "a"; |
| 28 | + const count = countChar(str, char); |
| 29 | + expect(count).toEqual(0); |
| 30 | +}); |
0 commit comments