@@ -4,7 +4,7 @@ const countChar = require("./count");
44// When the countChar function is called with these inputs,
55// Then it should:
66
7- // Scenario: Multiple Occurrences
7+ // Scenario 1 : Multiple Occurrences
88// Given the input string `str`,
99// And a character `char` that occurs one or more times in `str` (e.g., 'a' in 'aaaaa'),
1010// When the function is called with these inputs,
@@ -17,8 +17,82 @@ test("should count multiple occurrences of a character", () => {
1717 expect ( count ) . toEqual ( 5 ) ;
1818} ) ;
1919
20- // Scenario: No Occurrences
20+ // Scenario 2 : No Occurrences
2121// Given the input string `str`,
2222// And a character `char` that does not exist within `str`.
2323// When the function is called with these inputs,
2424// Then it should return 0, indicating that no occurrences of `char` were found.
25+
26+ test ( "should return 0 if there are no occurrences of a character" , ( ) => {
27+ const str = "there is no two number here" ;
28+ const char = "2" ;
29+ const count = countChar ( str , char ) ;
30+ expect ( count ) . toEqual ( 0 ) ;
31+ } ) ;
32+
33+
34+ // Scenario 3: Single Occurrence
35+ // Given the input string `str`,
36+ // And a character `char` that exists only once within `str`.
37+ // When the function is called with these inputs,
38+ // Then it should return 1, indicating that single occurrence of `char` were found.
39+
40+ test ( "should return 1 if there is single occurrence of a character" , ( ) => {
41+ const str = " let's find if we got what you are looking for" ;
42+ const char = "'" ;
43+ const count = countChar ( str , char ) ;
44+ expect ( count ) . toEqual ( 1 ) ;
45+ } ) ;
46+
47+ // Scenario 4: Zero occurrence when the string is empty
48+ // Given the input string `str` which is empty,
49+ // And a character `char` that can't be existed in the `str` as it is empty.
50+ // When the function is called with these inputs,
51+ // Then it should return 0, indicating that empty string can't hold that char.
52+
53+ test ( "should return 0 as the string is empty" , ( ) => {
54+ const str = "" ;
55+ const char = "2" ;
56+ const count = countChar ( str , char ) ;
57+ expect ( count ) . toEqual ( 0 ) ;
58+ } ) ;
59+
60+ // Scenario 5: Multiple occurrences if the string contains single empty spaces and our char is an empty space
61+ // Given the input string `str` that contains ' ' empty spaces,
62+ // And a character `char` which is just single empty space ' '.
63+ // When the function is called with these inputs,
64+ // Then it should return the number of occurrences of single empty spaces in the string.
65+
66+ test ( "should return multiple occurrences of empty spaces in the string" , ( ) => {
67+ const str = "Hi I have got ten single empty spaces in this string." ;
68+ const char = " " ;
69+ const count = countChar ( str , char ) ;
70+ expect ( count ) . toEqual ( 10 ) ;
71+ } ) ;
72+
73+
74+ // Scenario 6: No occurrences if the char is just an empty char
75+ // Given the input string `str` that contains any number of characters or no characters at all,
76+ // And a character `char` which is empty ''.
77+ // When the function is called with these inputs,
78+ // Then it should return 0 as there is nothing to count as the char is just empty.
79+
80+ test ( "should return 0 as the char is just empty" , ( ) => {
81+ const str = "Hi I am a string that can be empty or not empty but I can't count empty characters." ;
82+ const char = "" ;
83+ const count = countChar ( str , char ) ;
84+ expect ( count ) . toEqual ( 0 ) ;
85+ } ) ;
86+
87+ // Scenario 7: Multiple Occurrences at different places
88+ // Given the input string `str`,
89+ // And a character `char` that occurs more than one times in `str` (e.g., 'a' in 'add the angle to the antenna'),
90+ // When the function is called with these inputs,
91+ // Then it should correctly count occurrences of `char` a in the string.
92+
93+ test ( "should count multiple occurrences of a character" , ( ) => {
94+ const str = "add the angle to the antenna" ;
95+ const char = "a" ;
96+ const count = countChar ( str , char ) ;
97+ expect ( count ) . toEqual ( 4 ) ;
98+ } ) ;
0 commit comments