-
-
Notifications
You must be signed in to change notification settings - Fork 262
Glasgow | 25-ITP-Sep | Fares Bakhet | Sprint 3 | coursework/sprint-3-implement-and-rewrite #755
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-implement-and-rewrite #755
Conversation
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.
Code is good. I just have a few suggestions.
| if (angle < 90 && angle > 0) { | ||
| return "Acute angle"; | ||
| } | ||
| if (angle > 90 && angle < 180) { |
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.
Checking angle > 90 is optional because previous if-statements can guarantee angle is always more than 90.
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, Thanks for that. I have removed the unnecessary part.
| test("should return 10 for Jack of Diamonds", () => { | ||
| const jackofDiamonds = getCardValue("J♦"); | ||
| expect(jackofDiamonds).toEqual(10); | ||
| }); | ||
| test("should return 10 for Queen of Clubs", () => { | ||
| const queenofClubs = getCardValue("Q♣"); | ||
| expect(queenofClubs).toEqual(10); | ||
| }); | ||
| test("should return 10 for King of Hearts", () => { | ||
| const kingofHearts = getCardValue("K♥"); | ||
| expect(kingofHearts).toEqual(10); | ||
| }); |
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.
We could generalise these tests into one test to "should return 10 for face cards (J, Q, K)" and check all three ranks J, Q, K).
In addition, the function is not expected to check t the suit character. Indicating the suit character in the test description may send the developer the wrong message.
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, I have generalised the test. Could you explain what you mean by check t?
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.
Just a typo. Should be just "check the ..."
| test("should return 5 for Five of Hearts", () => { | ||
| const fiveofHearts = getCardValue("5♥"); | ||
| expect(fiveofHearts).toEqual(5); | ||
| }); |
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.
When preparing tests, we should ensure the tests cover all possible cases. If we specify a test for individual card, we will need about 53 tests to cover all possible cases. Instead, we could consider classifying all possible values into different categories, and then within each category we test some samples.
For example, one possible category for getCardValue() is, "should return the value of number cards (2-10)", and we can prepare the test as
test("should return the value of number cards (2-10)", () => {
expect(getCardValue("2♣︎")).toEqual(2);
expect(getCardValue("5♠")).toEqual(5);
expect(getCardValue("10♥")).toEqual(10);
// Note: We could also use a loop to check all values from 2 to 10.
});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, Do I need to redo my tests again in a better way? Or is it just for future knowledge?😅😅
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 practice it now?
| return "Acute angle"; | ||
| } | ||
| if (angle > 90 && angle < 180) { | ||
| if (angle < 180) { |
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 find all places where you can remove redundant checks and update the code accordingly?
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.
@cjyuan,
If I want to rearrange this again, I will end up in this way:
-
0 & < 90 >> covers 1-89
- ==90 >> covers 90
-
90 & <180 >>covers 91-179
- ==180>>covers 180
-
180 & <360 >> covers 181-359
- invalid if sth else
Right??
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 can't tell. 180 & < 360 is not exactly JS 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.
@cjyuan,
I was shortcutting
if( angle > 180 && angle <360)
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 still don't know wat you try to expressed:

I suspect part of the code is misinterpreted as Markdown code. Here is the GitHub Markdown guide:
https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax
| test("should return 10 for all face cards (J, Q, K)", () => { | ||
| const faceCards = ["J♦", "Q♣", "K♥"]; | ||
| faceCards.forEach((card) => { | ||
| const value = getCardValue(card); | ||
| expect(value).toEqual(10); | ||
| }); | ||
| }); |
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 looks great.
|
The updated Jest tests looks good. |
Learners, PR Template
Self checklist
Changelist
-Implementing cases and tests for each task.
-Test all the files using 'Jest'.
Questions
No questions.