Skip to content

Commit f8f380c

Browse files
fix: update test names and improve formatting
1 parent 75dfc4b commit f8f380c

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ test("should count multiple occurrences of a character", () => {
1616
const count = countChar(str, char);
1717
expect(count).toEqual(5);
1818
});
19-
test("No Occurrences", () => {
20-
const str = "qwerty";
21-
const char = "k";
22-
const count = countChar(str, char);
23-
expect(count).toEqual(0);
24-
})
2519

2620
// Scenario: No Occurrences
2721
// Given the input string `str`,
2822
// And a character `char` that does not exist within `str`.
2923
// When the function is called with these inputs,
3024
// Then it should return 0, indicating that no occurrences of `char` were found.
25+
26+
test("should count 0 when character is not found", () => {
27+
const str = "qwerty";
28+
const char = "k";
29+
const count = countChar(str, char);
30+
expect(count).toEqual(0);
31+
})
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
function repeatStr(str, count) {
2-
if (count >= 0) {return str.repeat(count)}
3-
else throw new Error("Error")
2+
if (count >= 0) {
3+
return str.repeat(count)
4+
}
5+
else {
6+
throw new Error("Error")
7+
}
48
}
59

610
module.exports = repeatStr;

Sprint-3/2-practice-tdd/repeat-str.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test("should repeat the string count times", () => {
2121
// When the repeatStr function is called with these inputs,
2222
// Then it should return the original `str` without repetition.
2323

24-
test("should repeat the string count times", () => {
24+
test("should return the original string when count is 1", () => {
2525
const str = "hello";
2626
const count = 1;
2727
const repeatedStr = repeatStr(str, count);
@@ -33,7 +33,7 @@ test("should repeat the string count times", () => {
3333
// When the repeatStr function is called with these inputs,
3434
// Then it should return an empty string.
3535

36-
test("should repeat the string count times", () => {
36+
test("should return an empty string when count is 0", () => {
3737
const str = "hello";
3838
const count = 0;
3939
const repeatedStr = repeatStr(str, count);
@@ -45,7 +45,7 @@ test("should repeat the string count times", () => {
4545
// When the repeatStr function is called with these inputs,
4646
// Then it should throw an error, as negative counts are not valid.
4747

48-
test("should repeat the string count times", () => {
48+
test("should throw an error when count is negative", () => {
4949
const str = "hello";
5050
const count = -1;
5151
expect(function(){repeatStr(str, count)}).toThrow()

0 commit comments

Comments
 (0)