-
-
Couldn't load subscription status.
- Fork 240
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). |
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?
| // write one test at a time, and make it pass, build your solution up methodically | ||
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| if (Math.sign(numerator) === -1 || Math.sign(denominator) === -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.
-
There is an easier syntax to check if a number is negative.
-
And since you are using
Math.abs(), checking for negatives is optional. -
This function can be further simplified. If you are up to the challenge, go for a solution that uses at most one if-statement.
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.
removed the check for negative and took off the first if else block, not quite sure how to reduce it to one if statement without making risky assumptions. since the function only returns true for a proper fraction and false for everything else, would it be appropriate to have an if statement that checks for a proper fraction and else that gives false for any other scenario?
| // 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
| } else if (Number(rank) > 1 && Number(rank) < 10) { | ||
| return Number(rank); | ||
| } else if (rank === "10" || rank === "J" || rank === "Q" || rank === "K") { |
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.
Does your function return the value you expected from each of the following function calls?
getCardValue("10♠");
getCardValue("100♠");
getCardValue("3.1416♠");
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 last function with 3.1416 showed that my condition for number cards was not checking that we have only a positive integer. I added an extra rule to check for an integer that way any decimal vlues will be flagged as invalid.
| 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
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?
| if (Math.abs(numerator) < Math.abs(denominator)) { | ||
| return true; | ||
| } else if (numerator > denominator) { | ||
| return false; | ||
| } else if (numerator === denominator) { | ||
| return false; | ||
| } else if (numerator === 0) { | ||
| return 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.
This is a good opportunities to practice code tracing -- to evaluate how the code get executed step by step using some sample pairs of parameter values. For examples,
- -1, 2
- 1, 2
- 1, 0
- 1, 1
- 0, 1
Hopefully you can figure out why some of your code is not needed.
| 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?
| 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.
| 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.
Learners, PR Template
Self checklist
Changelist
created functions and practiced test driven development by making tests for the functions.