-
-
Notifications
You must be signed in to change notification settings - Fork 245
West Midlands | ITP-Sept-25 | Mustaf Asani | Sprint 3 | Coursework/sprint 3 implement and rewrite #795
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?
West Midlands | ITP-Sept-25 | Mustaf Asani | Sprint 3 | Coursework/sprint 3 implement and rewrite #795
Conversation
|
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). |
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.
The files in the Sprint-2 folder are not related to Sprint-3 exercise. Can you revert the changes made in the Sprint-2 folder?
Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js
Outdated
Show resolved
Hide resolved
| // just make one change at a time -- don't rush -- programmers are deep and careful thinkers | ||
| function getCardValue(card) { | ||
| if (rank === "A") { | ||
| const rank = card[0]; |
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.
card[0] yields only a string with the first character -- not necessary the whole rank.
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.
thank you for pointing this out, I do need to make my tests more robust. I managed to get the correct rank for single digit and multiple digit cards.
Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
Outdated
Show resolved
Hide resolved
Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
Outdated
Show resolved
Hide resolved
| test("should return true for a proper fraction based on the absolute values of the numerator and denominator", () => { | ||
| expect(isProperFraction(-3, 8)).toEqual(true); | ||
| }); |
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 make the test more comprehensive, we could test multiple samples like this:
test("should return true for a proper fraction based on the absolute values of the numerator and denominator", () => {
expect(isProperFraction(-3, 8)).toEqual(true);
expect(isProperFraction(-3, -8)).toEqual(true);
expect(isProperFraction(3, -8)).toEqual(true);
expect(isProperFraction(3, 8)).toEqual(true);
})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.
added multiple test samples for this and other lines as well.
| test("should return 11 for Ace of Spades", () => { | ||
| const invalidCard = getCardValue("1♥"); | ||
| expect(invalidCard).toEqual("Invalid card rank."); | ||
| }); |
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 test description does not quite match what is being tested.
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.
corrected the test description.
| test("should return a number matchig the rank value for given card", () => { | ||
| const numberCard = getCardValue("5♠"); | ||
| expect(numberCard).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.
- I think "... for number cards (2-10)" would be more informative than "... for given card")
- Could test multiple values, especially the boundary cases like "2♠" and "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.
added a more informative description. also tested the edge cases.
…orrected test description for invalid cards, used more informative descriptions
… for cards with more than 1 digit, removed check for negative value since im using maths.abs
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.
There are still three modified files in the "Sprint-2" folder. Can you revert the changes made to them?
Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js
Outdated
Show resolved
Hide resolved
| let rank = ""; | ||
|
|
||
| if (card === "A♠") { | ||
| return 11; | ||
| } else if (Number(rank) > 1 && Number(rank) < 10) { | ||
| for (let i = 0; i < card.length - 1; i++) { | ||
| rank += card[i]; | ||
| } |
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 approach work.
You could also consider using built-in functions (methods) of String. Mastering these String's methods can simplify a lot of string processing tasks.
| if (Number.isInteger(Number(rank)) && Number(rank) > 1 && Number(rank) < 10) { | ||
| return Number(rank); |
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.
In JavaScript, strings that represent valid numeric literals in the language can be safely
converted to equivalent numbers or parsed into a valid integers.
Do you want to recognize these string values as valid ranks?
To find out what these strings are, you can ask AI
What kinds of string values would make
Number(rank)evaluate to2in JS?
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 added a regex to only allow specific numeric literals that convert to numbers which would be in our range 2 -10 and ignore all others.
| expect(isProperFraction(7, 4)).toEqual(false); | ||
| expect(isProperFraction(35, 8)).toEqual(false); |
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.
Could also test some negative improper fractions in this test.
| test("should return 10 for Face Cards", () => { | ||
| const faceCard = getCardValue("K♠"); | ||
| const faceCard = getCardValue("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.
Face cards are J, Q, K. 10 is consider a number card.
| const numberCard = getCardValue("5♠"); | ||
| expect(numberCard).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.
We could test multiple samples (especially the boundary cases, "2♠" and "10♠") to make the test more robust.
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.
added a suite of tests for different values to make the test more robust
| test("should return invalid card rank for cards that are not in the suite", () => { | ||
| const invalidCard = getCardValue("100♥"); | ||
| expect(invalidCard).toEqual("Invalid card rank."); | ||
| }); | ||
|
|
||
| test("should return invalid card rank for cards that are not in the suite", () => { | ||
| const invalidCard = getCardValue("3.1416♥"); | ||
| expect(invalidCard).toEqual("Invalid card rank."); | ||
| }); |
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.
They both test "invalid case". Consider combine them into one test but using multiple samples.
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.
combined the tests and added more tests for different values
…nnecessary if statements
…be converted to numbers.
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.
-
The tests are now very solid. Well done.
-
This PR branch still contains unrelated changes in "Sprint-2" folder. Can you revert the changes made in the "Sprint-2" folder to make the PR branch clean?
Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
Outdated
Show resolved
Hide resolved
Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
Outdated
Show resolved
Hide resolved
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.
Changes look good. Well done.
| if (strictNumber(rank)) { | ||
| if (pattern.test(Number(rank))) { | ||
| return Number(rank); | ||
| } | ||
| } |
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.
Is the outer if statement necessary?
|
|
||
| if (faceCardPattern.test(rank)) { | ||
| return 10; | ||
| } else if (/^A$/.test(rank)) { |
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.
Could also just write rank == 'A'.
Learners, PR Template
Self checklist
Changelist
created functions and practiced test driven development by making tests for the functions.