@@ -22,3 +22,39 @@ test("should count multiple occurrences of a character", () => {
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+ test ( "should return 0 when character does not exist in string" , ( ) => {
26+ const str = "hello" ;
27+ const char = "z" ;
28+ const count = countChar ( str , char ) ;
29+ expect ( count ) . toEqual ( 0 ) ;
30+ } ) ;
31+
32+ // Scenario: Case Sensitivity
33+ test ( "should be case sensitive" , ( ) => {
34+ expect ( countChar ( "AaAa" , "a" ) ) . toBe ( 2 ) ;
35+ } ) ;
36+
37+ // Scenario: Empty String
38+ test ( "should return 0 for an empty string" , ( ) => {
39+ expect ( countChar ( "" , "a" ) ) . toBe ( 0 ) ;
40+ } ) ;
41+
42+ // Scenario: Special Characters
43+ test ( "should count special characters" , ( ) => {
44+ expect ( countChar ( "!@#$%^&*()!" , "!" ) ) . toBe ( 2 ) ;
45+ } ) ;
46+
47+ // Scenario: Non-String Inputs
48+ test ( "should handle non-string inputs gracefully" , ( ) => {
49+ expect ( countChar ( 12345 , "1" ) ) . toBe ( 0 ) ;
50+ expect ( countChar ( null , "a" ) ) . toBe ( 0 ) ;
51+ expect ( countChar ( undefined , "a" ) ) . toBe ( 0 ) ;
52+ } ) ;
53+ test ( "should count numeric characters in a string" , ( ) => {
54+
55+ expect ( countChar ( "12345" , "1" ) ) . toBe ( 1 ) ;
56+ } ) ;
57+ // Scenario: Space Character
58+ test ( "should count spaces correctly" , ( ) => {
59+ expect ( countChar ( "a a a" , " " ) ) . toBe ( 2 ) ;
60+ } ) ;
0 commit comments