-
-
Notifications
You must be signed in to change notification settings - Fork 275
London | 25-ITP-Sep | Shaghayegh Shirinfar | Sprint 3 | Practice-tdd #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
London | 25-ITP-Sep | Shaghayegh Shirinfar | Sprint 3 | Practice-tdd #818
Conversation
jennethydyrova
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @shaghayeghfar ! Good start on this PR, I left some comments to address
| // 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 return 0 when the character does not exist in the string", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test suite is very slim, can you think of more test cases? You should try to cover as many scenarios as possible to test whether your function behaves right if something expected or unexpected passed to your function.
| @@ -1,5 +1,8 @@ | |||
| function getOrdinalNumber(num) { | |||
| return "1st"; | |||
| function getOrdinalNumber(number) { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this function is not passing the acceptance criteria. What if I pass, for example, 23 to it?
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| }); | ||
|
|
||
| // Case 2: Identify the ordinal number for 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good illustration why you need to write more versatile unit tests. Before fixing your function, add more unit tests (for different numbers) and see if they pass. You will see that they do not and this is a good sign that your function implementation is incorrect.
| // When the repeat function is called with these inputs, | ||
| // Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition. | ||
|
|
||
| test("should return the original string when count is 1", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These unit tests are correct but they are a bit limited. What if I pass undefined as str and count 2? What if I pass empty string? You should try to guard your function against these scenarios and unit tests help to think of different scenarios.
| @@ -1,5 +1,11 @@ | |||
| function countChar(stringOfCharacters, findCharacter) { | |||
| return 5 | |||
| let count = 0; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of for loop!
|
Dear Jennet, Thank you very much for reviewing my code. I have made the changes you suggested. I really appreciate your help, time, and effort. Best regards, |
jennethydyrova
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @shaghayeghfar! Very nice improvement since last iterations but there are couple of more things you will need to do before we can mark this PR as complete.
| expect(count).toEqual(0); | ||
| }); | ||
|
|
||
| test("should return 0 when the character does not exist in the string", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a duplicate of the test on L47
| expect(count).toEqual(5); | ||
| }); | ||
|
|
||
| test("should count multiple occurrences of a character", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, this is a good improvement on the previous iteration. Can you think of corner cases? What if length of stringOfCharacters is shorter than length of findCharacter? What either of them is an empty string or some other data type?
|
|
||
| // Case 2: Identify the ordinal number for 2 | ||
| // When the number is 2, | ||
| // Then the function should return "2nd" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the comment for countChar function's tests. If I pass undefined, I think your function will output undefinedth, is this a behaviour you expect? Can you think of other corner cases and how you can guard your function against them?
| if (str === undefined) { | ||
| throw new Error("String must be defined"); | ||
| } | ||
| if (str === null || typeof str !== "string") { | ||
| throw new Error("String must be a valid string"); | ||
| } | ||
|
|
||
| if (count === undefined || typeof count !== "number") { | ||
| throw new Error("Count must be a number"); | ||
| } | ||
|
|
||
| if (count < 0 || !Number.isInteger(count)) { | ||
| throw new Error("Count must be a non-negative integer"); | ||
| } | ||
|
|
||
| if (str === "" || count === 0) { | ||
| return ""; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is okay but it could be simplified by combining some of these if conditions and/or writing more general if condition that would catch most of the cases. You don't need to do anything, it's just something to think about and perhaps to implement on your spare time.
Sprint-3/2-practice-tdd/repeat.js
Outdated
| return ""; | ||
| } | ||
|
|
||
| // 5. Repeat the string count times |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment seems a remnant of the sequence of comments. Can you either add all or remove this?
|
Dear Jennet, Thank you so much for your feedback. I have made the changes you suggested and truly appreciate all your support and guidance .I am very grateful for it. |
jennethydyrova
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @shaghayeghfar! Very good improvement but there are couple of things I would like you fix before we complete this PR. Also, can you please remove any unrelated files from this PR?
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| if ( | ||
| typeof stringOfCharacters !== "string" || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If either or both arguments are not strings, does it really make sense to return 0? Think of it this way, you call the countChar(2, 3), what would you expect your function to return? I would suggest you to check this link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
| ) { | ||
| return 0; | ||
| } | ||
| if (findCharacter.length !== 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good check! As an extension, what if stringOfCharacters.length is 0 and findCharacter.length is 1? I see you now return just 0 but would it perhaps make more sense to throw an error because there is nothing to search character in?
| // When the function is called, | ||
| // Then it should return 0 because a multi-character string cannot match a single character position. | ||
|
|
||
| test("should return 0 when findCharacter is longer than the input string", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a bit incorrect. This is related to my earlier comment for the countChar function. If str length is shorter than char length, the function should return an error. Returning 0 should be reserved only for the case when character is not found. Otherwise, you function logic becomes convoluted, you wouldn't know if it returned 0 because character is not found or because arguments were invalid. Do you see the problem with it?
| function getOrdinalNumber(number) { | ||
| // Handle invalid inputs | ||
| if (typeof number !== "number" || !Number.isFinite(number)) { | ||
| return "Invalid input"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is okay but it would be cleaner to mention what you expect as a valid input.
| // Case NaN input : | ||
| // When the nymber is NaN , | ||
| // Then the function should return "Invalid input" | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice test cases, very comprehensive!
|
Dear Jennet, Thank you for your feedback! I’ve made all the changes you requested. However, I’m not entirely sure what you meant regarding removing the unrelated files. Could you please provide a bit more guidance on that? Thanks so much for your help! |
|
Hi @shaghayeghfar! You have some files that are not related to this pull request, such as package.json and package.lock. You shouldn't commit those files if they are not relevant. Also, you have some conflicts in your PR. Could you please double check?
|
|
Ah, maybe merge conflicts are due to the changes to the main branch. You can ignore it |
2f117e1 to
29a4b36
Compare
|
ear Jennet, Thank you so much for your help and advice. I have deleted the files as you suggested. |
jennethydyrova
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @shaghayeghfar ! I am marking this PR as complete but consider fixing typos
| //stringOfCharacters shoud not be empty | ||
| if (stringOfCharacters.length === 0) { | ||
| return "stringOfCharacters can not be empty"; | ||
| } | ||
|
|
||
| //findCharacter should not be empty | ||
| if (findCharacter.length === 0) { | ||
| return "findCharacter can not be empty"; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These could be combined.
| stringOfCharacters.length !== 0 && | ||
| findCharacter.length > stringOfCharacters.length | ||
| ) { | ||
| return "the stringOfCharacters MUST be lonegr than findingcharacter"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in longer and findingcharacter

Learners, PR Template
Self checklist