-
-
Notifications
You must be signed in to change notification settings - Fork 245
London | 25-ITP-Sep | Payman Issa Baiglu | sprint 3 | 2-practice-tdd #883
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 | Payman Issa Baiglu | sprint 3 | 2-practice-tdd #883
Conversation
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Wrong number of parts separated by |s If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
1 similar comment
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Wrong number of parts separated by |s If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (courseworksprint-3) doesn't match expected format (example: 'Sprint 2', without quotes) If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (coursework-sprint-3) doesn't match expected format (example: 'Sprint 2', without quotes) If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (sprint-3) doesn't match expected format (example: 'Sprint 2', without quotes) If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
| const v = num % 100; | ||
| console.log(v); |
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.
- It's best practice to give variables meaningful names. Can you think of a more meaningful name to replace
v? - Can you keep the code clean by removing all debugging code?
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.
Thanks @cjyuan. I updated the V variable to date to make it more meaningful. also removed the console.logs to make it more clean.
| test("should return '1st' for 1", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| }); | ||
|
|
||
| test("should return '2nd' for 2", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| }); | ||
|
|
||
| test("should return '3rd' for 3", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| }); | ||
| test("should return '24th' for 24", () => { | ||
| expect(getOrdinalNumber(24)).toEqual("24th"); | ||
| }); | ||
| test("should return '11th' for 11", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| }); |
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.
To ensure thorough testing, we need broad scenarios that cover all possible cases.
Listing individual values, however, can quickly lead to an unmanageable number of test cases.
Instead of writing tests for individual numbers, consider grouping all possible input values into meaningful categories.
Then, select representative samples from each category to test. This approach improves coverage and makes our tests easier to maintain.
For example, we can prepare a test for numbers 2, 22, 132, etc. as
test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
expect( getOrdinalNumber(2) ).toEqual("2nd");
expect( getOrdinalNumber(22) ).toEqual("22nd");
expect( getOrdinalNumber(132) ).toEqual("132nd");
});
Can you update the tests in this script to make it comprehensive so that the test categories can cover all valid numbers?
| if (count < 0) { | ||
| return "Count must be a non-negative integer"; | ||
| } |
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.
How would the caller distinguish the result of the following two function calls?
repeat("Count must be a non-negative integer", 1)repeat("", -1)
Both function calls return the same value.
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.
Thanks, I see your point. I changed it so it throw error.
Sprint-3/2-practice-tdd/repeat.js
Outdated
| for (let i = 0; i < count; i++) { | ||
| return str.repeat(count); | ||
| } |
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 loop will always iterate exactly once. Do you know why?
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.
Good point. That's because return is inside the loop. so I changed it.
| test("should return a message for negative count", () => { | ||
| const str = "error"; | ||
| const count = -2; | ||
| const repeatedStr = repeat(str, count); | ||
| expect(repeatedStr).toEqual("Count must be a non-negative integer"); | ||
| }); |
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 you modified repeat() to throw an error when count is negative, and you wanted to test if the function can throw an error as expected, you can use .toThrow(). You can find out more about how to use .toThrow() here: https://jestjs.io/docs/expect#tothrowerror (Note: Pay close attention to the syntax of the example)
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.
Thanks for bring this up. I changed it so it will throw error.
…ove unnecessary console logs
…n and enhance ordinal number tests with clearer descriptions and additional cases
…returning a message
…intain error handling for negative counts
…turning a message
|
Hi @cjyuan , thanks for reviewing my PR. I changed the the code so it covers the points that you mentioned can you please check if they are OK? Thanks and regards. |
cjyuan
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.
Can you also revert the changes made to
Sprint-2/1-key-erros/0.jsSprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
and remove Project-CLI-Treasure-Hunt?
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const suffixes = ["th", "st", "nd", "rd"]; | ||
| const date = num % 100; |
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.
Why named the variable date? The last two digits do not represent a date.
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.
Thanks for pointing that out. yes you are absolutely right! I was in class yesterday and couldn't focus enough. I changed it to a proper Variable name.
| test("append 'th' to numbers ending in 4, except those ending in 14", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| expect( getOrdinalNumber(24) ).toEqual("24th"); | ||
| expect( getOrdinalNumber(134) ).toEqual("134th"); | ||
| }); | ||
| test("should return '11th' for 11", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| }); |
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.
The tests on lines 11-26 are good.
Can you improve the tests on 27-34?
- Why differentiate numbers ending in 4 from numbers that ending in 14?
- What about numbers ending in other digits?
- Why prepare a test just for 11?
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.
Thanks, I tried to improve the tests on line 27-34. also added a test for other numbers.
11 is exception as it ends with 1 but will get "th", so tested separately.
… for better coverage
|
Hi @cjyuan , Many thanks for reviewing my PR. I tried a lot yesterday with the help of 3 volunteers to remove the extras which I don't know how got there in the first place. the best we could do was to made anew branch, which apparently didn't fix the problem. However, as I see those files are all from sprint-3. |
| test("append 'th' to numbers ending in 4", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| expect( getOrdinalNumber(24) ).toEqual("24th"); | ||
| expect( getOrdinalNumber(134) ).toEqual("134th"); | ||
| }); | ||
| test("should return '11th' for 11", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| }); | ||
| test("append 'th' to numbers which are not ending in 1, 2, 3", () => { | ||
| expect(getOrdinalNumber(5)).toEqual("5th"); | ||
| expect( getOrdinalNumber(29) ).toEqual("29th"); | ||
| expect( getOrdinalNumber(138) ).toEqual("138th"); | ||
| }); |
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.
-
Isn't the test categories on 35-39 include numbers ending in 4?
-
If 11 is a special case, then what about 12, 13, 111, 212, etc.?
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.
Now I got it! Thanks for pointing me that way. 11 is already covered and don't need a separate test, as all other numbers do.
…t tests for 4 and 11
| test("append 'th' to numbers which are not ending in 1, 2, 3", () => { | ||
| expect(getOrdinalNumber(5)).toEqual("5th"); | ||
| expect( getOrdinalNumber(29) ).toEqual("29th"); | ||
| expect( getOrdinalNumber(24) ).toEqual("24th"); | ||
| expect( getOrdinalNumber(138) ).toEqual("138th"); | ||
| }); |
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.
All the test categories now cover all numbers, but within this category, the samples being used are not very comprehensive. Can you think of what numbers you could have also tested?
Tests and functions implemented and tested.