Skip to content

Commit 99eba02

Browse files
committed
practice tdd count
1 parent ec3f79f commit 99eba02

File tree

3 files changed

+3405
-1
lines changed

3 files changed

+3405
-1
lines changed

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

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

512
module.exports = countChar;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const countChar = require("./count");
1010
// When the function is called with these inputs,
1111
// Then it should correctly count overlapping occurrences of char (e.g., 'a' appears five times in 'aaaaa').
1212

13+
1314
test("should count multiple occurrences of a character", () => {
1415
const str = "aaaaa";
1516
const char = "a";
@@ -22,3 +23,17 @@ test("should count multiple occurrences of a character", () => {
2223
// And a character char that does not exist within the case-sensitive str,
2324
// When the function is called with these inputs,
2425
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.
26+
27+
test("should return 0 when character does not exist in the string", () => {
28+
const str = "hello world";
29+
const char = "z";
30+
const count = countChar(str, char);
31+
expect(count).toEqual(0);
32+
});
33+
34+
35+
// Add case sensitivity tests
36+
test("should be case-sensitive", () => {
37+
expect(countChar("AaAa", "A")).toEqual(2);
38+
expect(countChar("AaAa", "a")).toEqual(2);
39+
});

0 commit comments

Comments
 (0)