-
-
Notifications
You must be signed in to change notification settings - Fork 239
Glasgow | 25-ITP-Sep | Fares Bakhet | Sprint 3 | coursework/sprint-3-practice-tdd #757
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?
Glasgow | 25-ITP-Sep | Fares Bakhet | Sprint 3 | coursework/sprint-3-practice-tdd #757
Conversation
| num = num.toString(); | ||
| if ( | ||
| num.slice(-2) === "11" || | ||
| num.slice(-2) === "12" || | ||
| num.slice(-2) === "13" | ||
| ) { | ||
| return num + "th"; | ||
| } else if (num.slice(-1) === "1") { | ||
| return num + "st"; | ||
| return num + "st"; | ||
| } else if (num.slice(-1) === "2") { | ||
| return num + "nd"; | ||
| } else if (num.slice(-1) === "3") { | ||
| return num + "rd"; | ||
| } else { | ||
| return num + "th"; | ||
| } | ||
| } |
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.
-
There is an unreachable statement (dead code).
-
Note: because of the
returnstatements, usingelseis optional.
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.
@cjyuan, Found it 😅😅😅
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 scenario coverage. 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");
});
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.
@cjyuan, Done 🫡
Sprint-3/2-practice-tdd/repeat.js
Outdated
| const str = arguments[0]; | ||
| const count = arguments[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.
Why not just declare them as parameters?
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.
@cjyuan , Okay 👌
|
|
||
| test("should return '101st' for 101", () => { | ||
| expect(getOrdinalNumber(101)).toEqual("101st"); | ||
| test("should return 'th' for the rest numbers", () => { |
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 rest [of the] numbers" is not very informative by itself; the developer would need to read all the test descriptions to find out what "the rest ..." mean. Can you make this test description more informative?
Sprint-3/2-practice-tdd/repeat.js
Outdated
| //const str = arguments[0]; | ||
| //const count = arguments[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.
Why keep the unused code?
| } | ||
| return num + "th"; |
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.
Since you have decided to remove the optional else, why only remove the last else?
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.
@cjyuan, Okay
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.
Changes look good! Well done.
Learners, PR Template
Self checklist
Changelist
Questions
No questions.