@@ -23,9 +23,48 @@ test("should count multiple occurrences of a character", () => {
2323// When the function is called with these inputs,
2424// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.
2525
26- test ( "should count no occurences of z characters" , ( ) => {
26+ test ( "should count no occurrences of z characters" , ( ) => {
2727 const str = "aaaaa" ;
2828 const char = "z" ;
2929 const count = countChar ( str , char ) ;
3030 expect ( count ) . toEqual ( 0 ) ;
3131} ) ;
32+
33+ test ( "should return 0 for an empty string and a non-empty character" , ( ) => {
34+ const str = "" ;
35+ const char = "z" ;
36+ const count = countChar ( str , char ) ;
37+ expect ( count ) . toEqual ( 0 ) ;
38+ } ) ;
39+
40+ test ( "should return 0 for an empty string and a whitespace character" , ( ) => {
41+ const str = "" ;
42+ const char = " " ;
43+ const count = countChar ( str , char ) ;
44+ expect ( count ) . toEqual ( 0 ) ;
45+ } ) ;
46+
47+ test ( "should return 0 when the string contains the character in a different case" , ( ) => {
48+ const str = "aBcDeF" ;
49+ const char = "A" ;
50+ const count = countChar ( str , char ) ;
51+ expect ( count ) . toEqual ( 0 ) ;
52+ } ) ;
53+
54+ test ( "throws error when the first argument is not a string" , ( ) => {
55+ expect ( ( ) => countChar ( 1234 , "1" ) ) . toThrow (
56+ "The argument for parameter stringOfCharacters is not a String type"
57+ ) ;
58+ } ) ;
59+
60+ test ( "throws error when the second argument is not a string" , ( ) => {
61+ expect ( ( ) => countChar ( "1234" , 1 ) ) . toThrow (
62+ "The argument for parameter findCharacter is not a String type"
63+ ) ;
64+ } ) ;
65+
66+ test ( "throws error when second argument is longer than one character" , ( ) => {
67+ expect ( ( ) => countChar ( "1234" , "12" ) ) . toThrow (
68+ "Parameter findCharacter is must contain a single character"
69+ ) ;
70+ } ) ;
0 commit comments