Skip to content

Commit bd7847f

Browse files
committed
Add test cases for countChar to check expected outputs in various scenarios
1 parent 86311c7 commit bd7847f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,37 @@ test("should throw an error when more than one string is passed as char", () =>
5656
expect(count).toEqual("invalid input: Input just one character");
5757
});
5858

59+
test("should count characters regardless of case (treat 'a' and 'A' as equal)", () => {
60+
const str = "JUMP";
61+
const char = "m";
62+
const count = countChar(str, char);
63+
expect(count).toEqual(1);
64+
});
65+
66+
test("should return correct count of space characters", () => {
67+
const str = "F r o NT";
68+
const char = " ";
69+
const count = countChar(str, char);
70+
expect(count).toEqual(3);
71+
});
5972

73+
test("should count numeric characters correctly in the string", () => {
74+
const str = "2Languages6";
75+
const char = "2";
76+
const count = countChar(str, char);
77+
expect(count).toEqual(1);
78+
});
79+
80+
test("should correctly count characters in a very long string", () => {
81+
const str = "b".repeat(500) + "abB";
82+
const char = "b";
83+
const count = countChar(str, char);
84+
expect(count).toEqual(502);
85+
});
86+
87+
test("should count numeric characters correctly in the string", () => {
88+
const str = "2Languages6";
89+
const char = 2;
90+
const count = countChar(str, char);
91+
expect(count).toEqual("Invalid input: input should be a string");
92+
});

0 commit comments

Comments
 (0)