Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
return stringOfCharacters.split(findCharacter).length-1
}

module.exports = countChar;
25 changes: 25 additions & 0 deletions Sprint-3/2-practice-tdd/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,34 @@ test("should count multiple occurrences of a character", () => {
const count = countChar(str, char);
expect(count).toEqual(5);
});
test("should count multiple occurrences of a character", () => {
const str = "pneumonoultramicroscopicsilicovolcanoconoisis";
const char = "o";
const count = countChar(str, char);
expect(count).toEqual(9);
});
test("should count multiple occurrences of a character", () => {
const str = "pneumonoultramicroscopicsilicovolcanoconoisis";
const char = "i";
const count = countChar(str, char);
expect(count).toEqual(6);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The test descriptions suggest that these tests belong to the same category. If they are testing the same behavior with different input values, consider grouping them into a single test suite.

Also, the string "pneumonoultramicroscopicsilicovolcanoconoisis" is long and difficult to read, making it hard for someone reviewing the test to verify that there are actually nine o's or six i's.



// Scenario: No Occurrences
// Given the input string `str`,
// And a character `char` that does not exist within `str`.
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of `char` were found.
test("should count multiple occurrences of a character", () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do these test descriptions match what is being tested?

const str = "interesting";
const char = "b";
const count = countChar(str, char);
expect(count).toEqual(0);
});
test("should count multiple occurrences of a character", () => {
Comment on lines +38 to +44

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If these tests are testing different behavior, they should have a different description.

Also, do look up

  • How to prepare test descriptions in TDD?
  • What characteristics the test descriptions should have?

const str = "future";
const char = "m";
const count = countChar(str, char);
expect(count).toEqual(0);
});
16 changes: 15 additions & 1 deletion Sprint-3/2-practice-tdd/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
function getOrdinalNumber(num) {
return "1st";
if ([11, 12, 13].includes(num % 100)){
return num + "th"
}
if (String(num).at(-1)=== "1"){
return num + "st"
}
if (String(num).at(-1) === "2"){
return num + "nd"
}
if (String(num).at(-1) === "3"){
return num + "rd"
}
else{
return num + "th"
}
}

module.exports = getOrdinalNumber;
26 changes: 26 additions & 0 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,30 @@ test("should append 'st' for numbers ending with 1, except those ending with 11"
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(21)).toEqual("21st");
expect(getOrdinalNumber(131)).toEqual("131st");
expect(getOrdinalNumber(1021)).toEqual("1021st");
});
//case 2; Numbers ending with 4,5,6,7,8,9 and 0
test("should append 'th' for numbers ending with 4,5,6,7,8,9,0", () => {
expect(getOrdinalNumber(104)).toEqual("104th");
expect(getOrdinalNumber(2000)).toEqual("2000th");
expect(getOrdinalNumber(167)).toEqual("167th");
expect(getOrdinalNumber(19)).toEqual("19th");
Comment on lines +24 to +27

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To make the test coverage more comprehensive, consider using arrays and loops (or other suitable Jest patterns) to test multiple values, ideally covering numbers that end with every possible digit in this category.

});
//case 3; Numbers ending with 11,12,13
test("should append 'th' for numbers ending with 11,12,13", () => {
expect(getOrdinalNumber(1013313)).toEqual("1013313th");
expect(getOrdinalNumber(2012)).toEqual("2012th");
expect(getOrdinalNumber(16711)).toEqual("16711th");
});
//case 4;Numbers ending with 2
test("should append 'nd' for numbers ending with 2", () => {
expect(getOrdinalNumber(102)).toEqual("102nd");
expect(getOrdinalNumber(2022)).toEqual("2022nd");
expect(getOrdinalNumber(16732)).toEqual("16732nd");
});
//case 4;Numbers ending with 3
test("should append 'nd' for numbers ending with 3", () => {
Comment on lines +36 to +42

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Better to clarify these scenarios do not include numbers ending with 12 and 13.

expect(getOrdinalNumber(3)).toEqual("3rd");
expect(getOrdinalNumber(2023)).toEqual("2023rd");
expect(getOrdinalNumber(16733)).toEqual("16733rd");
});
9 changes: 7 additions & 2 deletions Sprint-3/2-practice-tdd/repeat-str.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
function repeatStr() {
function repeatStr(str, count) {
// Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat).
// The goal is to re-implement that function, not to use it.
return "hellohellohello";
if(count >= 0){
return str.repeat(count);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you re-read the task description and make sure you have done everything?

}
Comment on lines 2 to +6

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You missed the comment on line 2.

else{
throw new Error("Invalid count");
}
}

module.exports = repeatStr;
42 changes: 40 additions & 2 deletions Sprint-3/2-practice-tdd/repeat-str.test.js

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Having identical test descriptions in all tests would make TDD difficult. Could you make the test descriptions more informative and distinctive? Perhaps also group similar tests into the same test category?

Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,56 @@ test("should repeat the string count times", () => {
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("hellohellohello");
});
test("should repeat the string count times", () => {
const str = "codeyourfuture";
const count = 2;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("codeyourfuturecodeyourfuture");
});

// Case: handle count of 1:
// Given a target string `str` and a `count` equal to 1,
// When the repeatStr function is called with these inputs,
// Then it should return the original `str` without repetition.

test("should repeat the string count times", () => {
const str = "hello";
const count = 1;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("hello");
});
test("should repeat the string count times", () => {
const str = "codeyourfuture";
const count = 1;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("codeyourfuture");
});
// Case: Handle count of 0:
// Given a target string `str` and a `count` equal to 0,
// When the repeatStr function is called with these inputs,
// Then it should return an empty string.

test("should repeat the string count times", () => {
const str = "hello";
const count = 0;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("");
});
test("should repeat the string count times", () => {
const str = "codeyourfuture";
const count = 0;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("");
});
// Case: Handle negative count:
// Given a target string `str` and a negative integer `count`,
// When the repeatStr function is called with these inputs,
// Then it should throw an error, as negative counts are not valid.
test("should repeat the string count times", () => {
const str = "hello";
const count = -4;
expect(() => repeatStr(str, count)).toThrow("Invalid count");
});
test("should repeat the string count times", () => {
const str = "codeyourfuture";
const count = -1;
expect(() => repeatStr(str, count)).toThrow("Invalid count");
});
Loading