Skip to content

Commit 7f9d151

Browse files
add additional tests for countChar function to handle empty character cases and various scenarios
1 parent cf3d5cd commit 7f9d151

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,44 @@ 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-
test("should return 0 if the character doesn't appear in the string",()=>{
26-
const str ="aaaaa";
25+
test("should return 0 if the character doesn't appear in the string", () => {
26+
const str = "aaaaa";
2727
const char = "s";
2828
const count = countChar(str, char);
2929
expect(count).toEqual(0);
30-
})
30+
});
31+
32+
test("should return 0 if the character is empty", () => {
33+
const str = "aaaaa";
34+
const char = "";
35+
const count = countChar(str, char);
36+
expect(count).toEqual(0);
37+
});
38+
39+
test("should return 0 if the character doesn't appear in the string", () => {
40+
const str = "aaca";
41+
const char = "ab";
42+
const count = countChar(str, char);
43+
expect(count).toEqual(0);
44+
});
45+
46+
test("should return 0 if the character doesn't appear in the string", () => {
47+
const str = "";
48+
const char = "a";
49+
const count = countChar(str, char);
50+
expect(count).toEqual(0);
51+
});
52+
53+
test("should return 0 if the character doesn't appear in the string", () => {
54+
const str = "aaca";
55+
const char = "ac";
56+
const count = countChar(str, char);
57+
expect(count).toEqual(1);
58+
});
59+
60+
test("should return 0 if the character doesn't appear in the string", () => {
61+
const str = "a";
62+
const char = "aa";
63+
const count = countChar(str, char);
64+
expect(count).toEqual(0);
65+
});

0 commit comments

Comments
 (0)