Skip to content

Commit 19452c4

Browse files
committed
test: add cases for no occurrences and case sensitivity in countChar function
1 parent 3372770 commit 19452c4

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,41 @@ const countChar = require("./count");
44
// When the countChar function is called with these inputs,
55
// Then it should:
66

7+
// Scenario: No Occurrences
8+
// Given the input string `str`,
9+
// And a character `char` that does not exist within `str`.
10+
// When the function is called with these inputs,
11+
// Then it should return 0, indicating that no occurrences of `char` were found.
12+
test("should return no occurrences if no found character", () => {
13+
const str = "jhhfdd";
14+
const char = "r";
15+
const count = countChar(str, char);
16+
expect(count).toEqual(0);
17+
});
18+
719
// Scenario: Multiple Occurrences
820
// Given the input string `str`,
921
// And a character `char` that occurs one or more times in `str` (e.g., 'a' in 'aaaaa'),
1022
// When the function is called with these inputs,
1123
// Then it should correctly count occurrences of `char`.
12-
1324
test("should count multiple occurrences of a character", () => {
1425
const str = "aaaaa";
1526
const char = "a";
1627
const count = countChar(str, char);
1728
expect(count).toEqual(5);
1829
});
1930

20-
// Scenario: No Occurrences
21-
// Given the input string `str`,
22-
// And a character `char` that does not exist within `str`.
23-
// When the function is called with these inputs,
24-
// Then it should return 0, indicating that no occurrences of `char` were found.
31+
// case 2
32+
test("should return 1 when the character appears only once", () => {
33+
expect(countChar("hello", "h")).toEqual(1);
34+
});
35+
36+
// case 3
37+
test("Should return 0 for empty string", () => {
38+
expect(countChar("", "a")).toEqual(0)
39+
})
40+
41+
// case 4
42+
test("should be case sensitive", () => {
43+
expect(countChar("aA", "a")).toEqual(1);
44+
});

0 commit comments

Comments
 (0)