Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sprint-3/2-practice-tdd/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test("should count multiple occurrences of a character", () => {
// And a character char that does not exist within the case-sensitive str,
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.
test("should count multiple occurrences of a character", () => {
test("should count no occurrence of a character", () => {
const str = "hello";
const char = "a";
const count = countChar(str, char);
Expand Down
17 changes: 1 addition & 16 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,9 @@ const getOrdinalNumber = require("./get-ordinal-number");
// Case 1: Identify the ordinal number for 1
// When the number is 1,
// Then the function should return "1st"
test("append 'st' to numbers ending in 1, except those ending in 11 which is 11th", () => {
test("append 'st' to numbers ending in 1, except those ending in 11", () => {
expect( getOrdinalNumber(1) ).toEqual("1st");
expect( getOrdinalNumber(11) ).toEqual("11th");
expect( getOrdinalNumber(21) ).toEqual("21st");
expect( getOrdinalNumber(221) ).toEqual("221st");
});
Comment on lines 9 to 38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the test in this script more comprehensive? Ideally the test should include categories that can cover all valid numbers.


test("append 'nd' to numbers ending in 2, except those ending in 12 which is 12th", () => {
expect( getOrdinalNumber(2) ).toEqual("2nd");
expect( getOrdinalNumber(12) ).toEqual("12th");
expect( getOrdinalNumber(22) ).toEqual("22nd");
expect( getOrdinalNumber(132) ).toEqual("132nd");
});

test("append 'rd' to numbers ending in 3, except those ending in 13 which is 13th", () => {
expect( getOrdinalNumber(3) ).toEqual("3rd");
expect( getOrdinalNumber(13) ).toEqual("13th");
expect( getOrdinalNumber(33) ).toEqual("33rd");
expect( getOrdinalNumber(133) ).toEqual("133rd");
});

8 changes: 5 additions & 3 deletions Sprint-3/2-practice-tdd/repeat.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
function repeat(word, n) {
if (typeof n !== 'number' || n < 0) {
return "Count must be a non-negative integer";
}
throw new Error("Count must be a non-negative integer");
}
if (n === 0) {
return " ";
return "";
}
return word.repeat(n);
}

module.exports = repeat;


8 changes: 4 additions & 4 deletions Sprint-3/2-practice-tdd/repeat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ test("should repeat the string count times", () => {
const str = "hello";
const count = 0;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual(" ");
expect(repeatedStr).toEqual("");
});

// case: Negative Count:
// Given a target string str and a negative integer count,
// When the repeat function is called with these inputs,
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.

test("should repeat the string count times", () => {
const str = "hello";
const count = -1;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("Count must be a non-negative integer");
});
expect(() => repeat(str, count)).toThrow("Count must be a non-negative integer");
});