Skip to content

Commit b8e36c4

Browse files
committed
I Covered 3 different countChar cases
1 parent 943e88e commit b8e36c4

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ const countChar = require("./count");
33
// Given a string str and a single character char to search for,
44
// When the countChar function is called with these inputs,
55
// Then it should:
6-
test("count how many times a character occurs a string", () => {
7-
const stringOfCharacters = "kiwi";
8-
const findCharacter = "w";
9-
10-
const result = countChar(stringOfCharacters, findCharacter);
11-
12-
expect(result).toBe(5);
13-
});
146

157
// Scenario: Multiple Occurrences
168
// Given the input string str,
@@ -30,3 +22,24 @@ test("should count multiple occurrences of a character", () => {
3022
// And a character char that does not exist within the case-sensitive str,
3123
// When the function is called with these inputs,
3224
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.
25+
26+
test("returns 0 if the character is not in the string", () => {
27+
const str = "bread";
28+
const char = "z";
29+
const count = countChar(str, char);
30+
expect(count).toBe(0);
31+
});
32+
33+
test("counts a character that appears once", () => {
34+
const str = "bread";
35+
const char = "d";
36+
const count = countChar(str, char);
37+
expect(count).toBe(1);
38+
});
39+
40+
test("counts how many times a character appears", () => {
41+
const str = "breadboard";
42+
const char = "b";
43+
const count = countChar(str, char);
44+
expect(count).toBe(2);
45+
});

0 commit comments

Comments
 (0)