Skip to content

Commit f6115be

Browse files
committed
Update test descriptions and expected output values in test cases
1 parent adb9421 commit f6115be

File tree

1 file changed

+49
-19
lines changed

1 file changed

+49
-19
lines changed

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

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test("should return the original input with no repetition", () => {
2525
const count = 1;
2626
const repeatedStr = repeat(str, count);
2727
expect(repeatedStr).toEqual(str);
28-
})
28+
});
2929

3030
// case: Handle Count of 0:
3131
// Given a target string str and a count equal to 0,
@@ -36,82 +36,112 @@ test("should return an empty string for zero count times", () => {
3636
const count = 0;
3737
const repeatedStr = repeat(str, count);
3838
expect(repeatedStr).toEqual("");
39-
})
39+
});
4040

4141
// case: Negative Count:
4242
// Given a target string str and a negative integer count,
4343
// When the repeat function is called with these inputs,
4444
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
45-
test("should return an error message", () => {
45+
test("should return an error message when negative number count is passed", () => {
4646
const str = "food";
4747
const count = -2;
4848
const repeatedStr = repeat(str, count);
4949
expect(repeatedStr).toEqual("Negative number invalid");
50-
})
50+
});
5151

5252
test("should return an empty string when empty string is expected count number of times", () => {
5353
const str = "";
5454
const count = 23;
5555
const repeatedStr = repeat(str, count);
5656
expect(repeatedStr).toEqual("");
57-
})
57+
});
5858

59-
test("should repeat the number count times as a string", () => {
59+
test("should return an error message when a number is passed as input", () => {
6060
const str = 1;
6161
const count = 3;
6262
const repeatedStr = repeat(str, count);
63-
expect(repeatedStr).toEqual("111");
63+
expect(repeatedStr).toEqual(
64+
"Invalid input: valueToRepeat should be a string"
65+
);
6466
});
6567

66-
test("should repeat boolean count times as a string", () => {
68+
test("should return an error message when 'true' is passed as input", () => {
6769
const str = true;
6870
const count = 2;
6971
const repeatedStr = repeat(str, count);
70-
expect(repeatedStr).toEqual("truetrue");
72+
expect(repeatedStr).toEqual(
73+
"Invalid input: valueToRepeat should be a string"
74+
);
7175
});
7276

73-
test("should repeat null count times as a string", () => {
77+
test("should return an error message for 'null' as input", () => {
7478
const str = null;
7579
const count = 2;
7680
const repeatedStr = repeat(str, count);
77-
expect(repeatedStr).toEqual("nullnull");
81+
expect(repeatedStr).toEqual(
82+
"Invalid input: valueToRepeat should be a string"
83+
);
7884
});
7985

80-
test("should repeat undefined count times as a string", () => {
86+
test("should return an error message for 'undefined' as input", () => {
8187
const str = undefined;
8288
const count = 2;
8389
const repeatedStr = repeat(str, count);
84-
expect(repeatedStr).toEqual("undefinedundefined");
90+
expect(repeatedStr).toEqual(
91+
"Invalid input: valueToRepeat should be a string"
92+
);
8593
});
8694

8795
// case: array input
88-
test("should repeat [] count times as a string", () => {
96+
test("should return an error message for 'array' as input", () => {
8997
const str = [];
9098
const count = 2;
9199
const repeatedStr = repeat(str, count);
92-
expect(repeatedStr).toEqual("");
100+
expect(repeatedStr).toEqual(
101+
"Invalid input: valueToRepeat should be a string"
102+
);
93103
});
94104

95105
// case: Non-integer positive count
96106
test("should return an error message for non-integer positive count", () => {
97107
const str = "apple";
98108
const count = 2.5;
99109
const repeatedStr = repeat(str, count);
100-
expect(repeatedStr).toEqual("Invalid count: count should be an integer");
110+
expect(repeatedStr).toEqual("Invalid input: numOfTimes should be an integer");
101111
});
102112

103113
// case: Non-integer negative count
104114
test("should return an error message for non-integer negative count", () => {
105115
const str = "banana";
106116
const count = -1.7;
107117
const repeatedStr = repeat(str, count);
108-
expect(repeatedStr).toEqual("Invalid count: count should be an integer");
118+
expect(repeatedStr).toEqual("Invalid input: numOfTimes should be an integer");
109119
});
110120

111121
// case: Object input
112-
test("should repeat an object count times as a string", () => {
122+
test("should return an error message when object is passed as input", () => {
113123
const str = {};
114124
const count = 2;
115125
const repeatedStr = repeat(str, count);
116-
expect(repeatedStr).toEqual("[object Object][object Object]");
126+
expect(repeatedStr).toEqual(
127+
"Invalid input: valueToRepeat should be a string"
128+
);
129+
});
130+
131+
test("should return an error message when input is not a string and count is not a number", () => {
132+
const str = {};
133+
const count = -2.2;
134+
const repeatedStr = repeat(str, count);
135+
expect(repeatedStr).toEqual(
136+
"Invalid input: valueToRepeat should be a string"
137+
);
138+
});
139+
140+
test("should return an error message when input is not a string and count is not a number", () => {
141+
const str = {};
142+
const count = -2;
143+
const repeatedStr = repeat(str, count);
144+
expect(repeatedStr).toEqual(
145+
"Invalid input: valueToRepeat should be a string"
146+
);
117147
});

0 commit comments

Comments
 (0)