Skip to content

Commit 3248c54

Browse files
committed
Implement countChar function to pass TDD tests
1 parent 01bed15 commit 3248c54

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Sprint-3/2-practice-tdd/count.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,24 @@ test("should count multiple occurrences of a character", () => {
2222
// And a character char that does not exist within the case-sensitive str,
2323
// When the function is called with these inputs,
2424
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.
25+
26+
test("returns 0 if the character is not in the string", () => {
27+
const str = "bread";
28+
const char = "z";
29+
const count = countChar(str, char);
30+
expect(count).toBe(0);
31+
});
32+
33+
test("counts a character that appears once", () => {
34+
const str = "bread";
35+
const char = "d";
36+
const count = countChar(str, char);
37+
expect(count).toBe(1);
38+
});
39+
40+
test("counts how many times a character appears", () => {
41+
const str = "breadboard";
42+
const char = "b";
43+
const count = countChar(str, char);
44+
expect(count).toBe(2);
45+
});

0 commit comments

Comments
 (0)