Skip to content

Commit 08c4184

Browse files
Add count tests for partial matches and empty string
1 parent bdcd308 commit 08c4184

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎practice-tdd/count.test.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,32 @@ test("should return 0 when the character does not occur in the string", () => {
2727
const char = "z";
2828
const count = countChar(str, char);
2929
expect(count).toEqual(0);
30+
});
31+
32+
test("should count correctly when the character appears in only part of the string", () => {
33+
const str = "hello";
34+
const char = "l";
35+
const count = countChar(str, char);
36+
expect(count).toEqual(2);
37+
});
38+
39+
test("should count a character that appears once in the middle of the string", () => {
40+
const str = "abc";
41+
const char = "b";
42+
const count = countChar(str, char);
43+
expect(count).toEqual(1);
44+
});
45+
46+
test("should count a character that appears in separate parts of the string", () => {
47+
const str = "banana";
48+
const char = "a";
49+
const count = countChar(str, char);
50+
expect(count).toEqual(3);
51+
});
52+
53+
test("should return 0 when the string is empty", () => {
54+
const str = "";
55+
const char = "a";
56+
const count = countChar(str, char);
57+
expect(count).toEqual(0);
3058
});

0 commit comments

Comments
 (0)