Skip to content

Commit 77a27dc

Browse files
committed
count tests
1 parent 41fc857 commit 77a27dc

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

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

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

511
module.exports = countChar;

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,21 @@ test("should count multiple occurrences of a character", () => {
2222
// And a character `char` that does not exist within `str`.
2323
// When the function is called with these inputs,
2424
// Then it should return 0, indicating that no occurrences of `char` were found.
25+
test("should count zero occurrences of a character", () => {
26+
const str = "aaaaa";
27+
const char = "b";
28+
const count = countChar(str, char);
29+
expect(count).toEqual(0);
30+
});
31+
32+
// Scenario: Non-consecutive occurrances
33+
// Given the input string `str`,
34+
// And a character `char` that appears in more than one block within `str`.
35+
// When the function is called with these inputs,
36+
// Then it should return the number of total occurrances.
37+
test("should count non-contiguous occurrences of a character", () => {
38+
const str = "aaaaabba";
39+
const char = "a";
40+
const count = countChar(str, char);
41+
expect(count).toEqual(6);
42+
});

0 commit comments

Comments
 (0)