@@ -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