Skip to content

Commit ffb9851

Browse files
BrianY315Copilot
andcommitted
Add empty-string and partial-match tests
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 26e6bc9 commit ffb9851

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎practice-tdd/count.test.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ test("should count multiple occurrences of a character", () => {
1717
expect(count).toEqual(5);
1818
});
1919

20+
test("should count occurrences when the character appears within the string", () => {
21+
const str = "hello";
22+
const char = "l";
23+
const count = countChar(str, char);
24+
expect(count).toEqual(2);
25+
});
26+
2027
// Scenario: No Occurrences
2128
// Given the input string `str`,
2229
// And a character `char` that does not exist within `str`.
@@ -29,3 +36,10 @@ test("should return 0 when the character does not occur", () => {
2936
const count = countChar(str, char);
3037
expect(count).toEqual(0);
3138
});
39+
40+
test("should return 0 when the string is empty", () => {
41+
const str = "";
42+
const char = "z";
43+
const count = countChar(str, char);
44+
expect(count).toEqual(0);
45+
});

‎practice-tdd/repeat-str.test.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ test("should repeat the string count times", () => {
1414
const count = 3;
1515
const repeatedStr = repeatStr(str, count);
1616
expect(repeatedStr).toEqual("hellohellohello");
17+
expect(repeatStr("", count)).toEqual("");
1718
});
1819

1920
// Case: handle count of 1:
@@ -26,6 +27,7 @@ test("should return the original string when count is 1", () => {
2627
const count = 1;
2728
const repeatedStr = repeatStr(str, count);
2829
expect(repeatedStr).toEqual("hello");
30+
expect(repeatStr("", count)).toEqual("");
2931
});
3032

3133
// Case: Handle count of 0:
@@ -38,6 +40,7 @@ test("should return an empty string when count is 0", () => {
3840
const count = 0;
3941
const repeatedStr = repeatStr(str, count);
4042
expect(repeatedStr).toEqual("");
43+
expect(repeatStr("", count)).toEqual("");
4144
});
4245

4346
// Case: Handle negative count:
@@ -49,4 +52,5 @@ test("should throw an error when count is negative", () => {
4952
const str = "hello";
5053
const count = -1;
5154
expect(() => repeatStr(str, count)).toThrow();
55+
expect(() => repeatStr("", count)).toThrow();
5256
});

0 commit comments

Comments
 (0)