-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount.test.js
More file actions
29 lines (24 loc) · 1.06 KB
/
Copy pathcount.test.js
File metadata and controls
29 lines (24 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// implement a function countChar that counts the number of times a character occurs in a string
const countChar = require("./count");
// Given a string `str` and a single character `char` to search for,
// When the countChar function is called with these inputs,
// Then it should:
// Scenario: Multiple Occurrences
// Given the input string `str`,
// And a character `char` that occurs one or more times in `str` (e.g., 'a' in 'aaaaa'),
// When the function is called with these inputs,
// Then it should correctly count occurrences of `char`.
test("should count multiple occurrences of a character", () => {
expect(countChar("aaaaa","a")).toEqual(5);
});
// Scenario: No Occurrences
test(`should return 0 in the instance of no char counted`,() =>{
expect(countChar("","a")).toEqual(0);
});
//});
// Given the input string `str`,
test(` character char that does not exist within str`,()=>{
expect(countChar("aaaaa","b")).toEqual(0);
});
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of `char` were found.