Repository navigation
Conversation
hackertainment
left a comment
There was a problem hiding this comment.
The code looks good and you are almost there. Please keep it up :-)
| test("should return 0 when character doesn't occur", () => { | ||
| const str = "salam"; | ||
| const char = "b"; | ||
|
|
||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); No newline at end of file |
There was a problem hiding this comment.
There should be another valid boundary case that returns 0. Can you think of it? Please add it back. Thank you.
There was a problem hiding this comment.
Added another boundary case when the string is empty.
Thank you.
| // Case 4: Numbers ending with "th" including the special case (11,12,13) | ||
| test(`Numbers ending with "th" including the special case (11,12,13)`, () => { | ||
| expect(getOrdinalNumber(10)).toEqual("10th"); | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| expect(getOrdinalNumber(12)).toEqual("12th"); | ||
| expect(getOrdinalNumber(13)).toEqual("13th"); | ||
| expect(getOrdinalNumber(14)).toEqual("14th"); | ||
| expect(getOrdinalNumber(5)).toEqual("5th"); | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| }); No newline at end of file |
There was a problem hiding this comment.
This test suite should include more test cases that is greater than 100 and still ended in th. Please add them back. Thank you.
There was a problem hiding this comment.
Included numbers greater than 100 ending with "th" & with the special case (111, 112, 113).
Thank you.
There was a problem hiding this comment.
Your answers are correct. Just to give you a bit more thinking, besides const str = "hello"; , what special string should also be tested in each of the test suites?
There was a problem hiding this comment.
Added an empty string tests for repeatStr.
Thank you.
| // 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 return an error, as negative counts are not valid", () => { | ||
| const str = "hello"; | ||
| const count = -1; | ||
| const repeatedStr = repeatStr(str, count); | ||
| expect(repeatedStr).toEqual("negative counts are not valid"); | ||
| }); |
There was a problem hiding this comment.
Just not sure whether you have learnt this topic already or it will be covered in the later modules... When the question mentioned that "it should throw an error", it does not mean return an error but using throw new Error() in line 5 of your practice-tdd/repeat-str.js and using the Jest function .toThrow() (but not .toEqual()) for this particular test case. Since this programming concept may be quite new to you, if you need help on understanding what I commented here, please feel free to ask a volunteer in Saturday workshop or book a mentored coding session with a volunteer, and try to fix this last issue (which I have missed in the first review) in both practice-tdd/repeat-str.js and practice-tdd/repeat-str.test.js when count is a negative number. Thank you for your effort and you have done a very good job.
Self checklist
Task code
CYF-1060
Changelist
Practice TDD