Skip to content

Commit 62bf3a9

Browse files
authored
Editing jest code
1 parent d269acc commit 62bf3a9

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,76 @@ test("should return 0 for no occurrences", () => {
3131
const count = countChar(str, char);
3232
expect(count).toEqual(0);
3333
});
34+
35+
36+
// Scenario: Multiple occurrences
37+
test("should count multiple occurrences of a character", () => {
38+
const str = "aaaaa";
39+
const char = "a";
40+
const count = countChar(str, char);
41+
expect(count).toEqual(5);
42+
});
43+
44+
// Scenario: No occurrences
45+
test("should return 0 for no occurrences", () => {
46+
const str = "hello";
47+
const char = "z";
48+
const count = countChar(str, char);
49+
expect(count).toEqual(0);
50+
});
51+
52+
// Scenario: Empty string
53+
test("should return 0 when input string is empty", () => {
54+
const str = "";
55+
const char = "a";
56+
const count = countChar(str, char);
57+
expect(count).toEqual(0);
58+
});
59+
60+
// Scenario: Empty character
61+
test("should return 0 when character input is empty", () => {
62+
const str = "hello";
63+
const char = "";
64+
const count = countChar(str, char);
65+
expect(count).toEqual(0);
66+
});
67+
68+
// Scenario: Character longer than 1
69+
test("should return 0 when character input is longer than one character", () => {
70+
const str = "hello";
71+
const char = "ll";
72+
const count = countChar(str, char);
73+
expect(count).toEqual(0);
74+
});
75+
76+
// Scenario: char string longer than str string
77+
test("should return 0 when char is longer than the input string", () => {
78+
const str = "a";
79+
const char = "abc";
80+
const count = countChar(str, char);
81+
expect(count).toEqual(0);
82+
});
83+
84+
// Scenario: Non-string inputs
85+
test("should return 0 when inputs are not strings", () => {
86+
expect(countChar(12345, "1")).toEqual(0);
87+
expect(countChar("12345", 1)).toEqual(0);
88+
expect(countChar(null, "a")).toEqual(0);
89+
expect(countChar("hello", undefined)).toEqual(0);
90+
});
91+
92+
// Scenario: Case sensitivity
93+
test("should count only exact case matches", () => {
94+
const str = "AaAaA";
95+
const char = "a";
96+
const count = countChar(str, char);
97+
expect(count).toEqual(2);
98+
});
99+
100+
// Scenario: Spaces and special characters
101+
test("should correctly count spaces and symbols", () => {
102+
const str = "a b c d e ! !";
103+
const char = " ";
104+
const count = countChar(str, char);
105+
expect(count).toEqual(6);
106+
});

0 commit comments

Comments
 (0)