Birmingham | 25-ITP-Sept | Khor Biel | Sprint 3 | coursework/sprint-3-practice-tdd#801
Birmingham | 25-ITP-Sept | Khor Biel | Sprint 3 | coursework/sprint-3-practice-tdd#801wankoak wants to merge 3 commits intoCodeYourFuture:mainfrom
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
Why not include a brief description of the changes made in this PR in the PR description?
Sprint-3/2-practice-tdd/count.js
Outdated
| typeof stringOfCharacters !== "string" || | ||
| typeof findCharacter !== "string" | ||
| ) { | ||
| return 0; |
There was a problem hiding this comment.
How should the caller distinguish the result of countChar(1234, 5) from the result of countChar("1234", "5")?
| if (typeof num !== "number" || isNaN(num)) { | ||
| return ""; | ||
| } |
There was a problem hiding this comment.
3.1416 and Infinity could pass this test.
| // Case 2: Identify the ordinal number for 2 | ||
| test("should return '2nd' for 2", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| }); | ||
|
|
There was a problem hiding this comment.
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");
});
| test("should return 'th' for numbers ending with 0, 4–9", () => { | ||
| expect(getOrdinalNumber(10)).toEqual("10th"); | ||
| expect(getOrdinalNumber(14)).toEqual("14th"); | ||
| expect(getOrdinalNumber(19)).toEqual("19th"); | ||
| }); No newline at end of file |
| test("should return '11th', '12th', '13th' for special cases", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| expect(getOrdinalNumber(12)).toEqual("12th"); | ||
| expect(getOrdinalNumber(13)).toEqual("13th"); | ||
| }); |
There was a problem hiding this comment.
When the person implementing the function see this test message, they may ask "what exactly are 'special cases'?".
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. 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 description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. 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 description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. 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 description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. 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). |
Sprint-3/2-practice-tdd/count.js
Outdated
| // Ensure valid inputs | ||
| if ( | ||
| typeof stringOfCharacters !== "string" || | ||
| typeof findCharacter !== "string" | ||
| ) { | ||
| return 0; | ||
| } | ||
|
|
There was a problem hiding this comment.
Why remove the check instead of strengthening it?
Sprint-3/2-practice-tdd/count.js
Outdated
| let count = 0; | ||
| for (let char of stringOfCharacters) { | ||
| if (char === findCharacter) { | ||
| count++; | ||
| let total = 0; | ||
| for (let i=0; i < stringOfCharacters.length; i++){ | ||
| if (findCharacter == stringOfCharacters[i]){ | ||
| total++; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Why replace the for-of loop with a for loop? The former is more compact.
There was a problem hiding this comment.
That does not answer my question.
| // Ensure the input is a valid number | ||
| if (typeof num !== "number" || isNaN(num)) { | ||
| return ""; | ||
| } | ||
|
|
There was a problem hiding this comment.
Why remove the check instead of strengthening it?
|
Your PR couldn't be matched to an assignment in this module. Please check its title is in the correct format, and that you only have one PR per assignment. 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 description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. 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). |
|
@cjyuan, just give me a few minutes. I'm in the market, I'll edit my code as soon as I get home. |
|
The functions work. Some of the code I commented remain unchanged, so I am not sure if you have addressed all my comments. Can you address all my previous comments? |
|
I was referring to the comment I left on I will mark this PR as complete first. You can improve the code when you have more time. |
|
@cjyuan thank you so much but I'm working on it now |

Self checklist