Skip to content

Commit 6366b00

Browse files
Add countChar edge case tests
1 parent e5baf35 commit 6366b00

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎practice-tdd/count.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
export function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
let count = 0;
3+
4+
for (const character of stringOfCharacters) {
5+
if (character === findCharacter) {
6+
count++;
7+
}
8+
}
9+
return count;
310
}

‎practice-tdd/count.test.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ test("should count multiple occurrences of a character", () => {
1717
expect(count).toEqual(5);
1818
});
1919

20+
test("should count occurrences in a mixed string", () => {
21+
const count = countChar("banana", "a");
22+
expect(count).toEqual(3);
23+
});
24+
25+
test("should return 0 for an empty string", () => {
26+
const count = countChar("", "a");
27+
expect(count).toEqual(0);
28+
});
2029
// Scenario: No Occurrences
2130
// Given the input string `str`,
2231
// And a character `char` that does not exist within `str`.

0 commit comments

Comments
 (0)