-
-
Notifications
You must be signed in to change notification settings - Fork 268
Sheffield | 25-ITP-SEP | Declan Williams | Sprint 3 | Coursework #878
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?
Sheffield | 25-ITP-SEP | Declan Williams | Sprint 3 | Coursework #878
Conversation
…add corresponding test case
…d corresponding test case
…CardValue function with comments explaining function and updated tests
…ction and add corresponding test cases
…d by making sure they always end in "th"
…test for special ordinal numbers
…omments detailing.
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 pretty solid.
-
You missed implementing the Jest tests in
Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest.
| function isProperFraction(numerator, denominator) { | ||
| if (numerator < denominator) { | ||
| return true; | ||
| } | ||
| if (numerator < denominator) return true; | ||
| else 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.
According to the definition of proper fraction in mathematics:
isProperFraction(-4, 3)should returnfalseisProperFraction(-2, 5)should returntrueisProperFraction(-2, 0)should returnfalseisProperFraction(-1, 1)should returnfalseisProperFraction(-2, -3)should returntrue
Can you look up the definition of proper fraction and update your function accordingly?
| if (rank === "A") { | ||
| return 11; | ||
| } | ||
| var rank = card.slice(0, -1); // get the rank of the card by removing the last character. (the suit is the last character) |
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 use let to declare the variable?
| if (rank === "A") return 11; // this checks for Aces | ||
| // Handle Number Cards (2-9) | ||
| if (rank === "2") return 2; // this checks for the twos | ||
| if (rank === "3") return 3; // this checks for the threes | ||
| if (rank === "4") return 4; // this checks for the fours | ||
| if (rank === "5") return 5; // this should check for fives | ||
| if (rank === "6") return 6; // this checks for the sixes | ||
| if (rank === "7") return 7; // this checks for the sevens | ||
| if (rank === "8") return 8; // this checks for the eights | ||
| if (rank === "9") return 9; // this checks for the nines | ||
| // Handle Face Cards (J, Q, K) And 10's | ||
| if (rank === "J") return 10; // this checks for Jacks | ||
| if (rank === "Q") return 10; // this checks for Queens | ||
| if (rank === "K") return 10; // this checks for Kings | ||
| if (rank === "10") return 10; // this checks for Tens | ||
| // if none of the above its an invalid card and throw an error |
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 very solid. As a stretch exercise, can you figure out a way to simplify these code (e.g., reduce the number of if statements involved)?
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.
by mapping each of the card ranks directly to values so instead of using if statements and using an object to make it more scalable and cleaner.
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.
by mapping each of the card ranks directly to values so instead of using if statements and using an object to make it more scalable and cleaner.
How would you express them in JS? And what do you mean by "scalable"?
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.
by making a lookup object by making a const of the card values and then using the key to pull each of the ranks and this would make it have no if-statements. and its more scalable in the sence of if needing to add cards
| // Case 2: Identify the ordinal number for 2 | ||
| // When the number is 2, | ||
| // The function should then return "2nd". | ||
|
|
||
| test("Should return `2nd` for 2", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| }); | ||
|
|
||
| // Case 3: Identify the ordinal number for 3 | ||
| // When the number is 3, | ||
| // The Function should the return "3rd" | ||
|
|
||
| test("Should return `3rd` for 3", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| }); |
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 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");
});
Can you update the tests in this script to make them more comprehensive? That is, create few test categories that can cover all possible cases?
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.
have updated them to have more tests to cover more possible cases
…tead of throwing an error
…ardValue function
…cases and improve formatting
| if (denominator === 0) return false; // avoid division by zero | ||
| return Math.abs(numerator) < Math.abs(denominator); |
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 no "division by zero" needs to be prevented though.
Will the function still work equally well without this 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.
yes it would still work because it would return false implicitly with out the if-statement, as im currently explicitly looking for the error having the if-statement in.
| if (rank === "A") return 11; // this checks for Aces | ||
| // Handle Number Cards (2-9) | ||
| if (rank === "2") return 2; // this checks for the twos | ||
| if (rank === "3") return 3; // this checks for the threes | ||
| if (rank === "4") return 4; // this checks for the fours | ||
| if (rank === "5") return 5; // this should check for fives | ||
| if (rank === "6") return 6; // this checks for the sixes | ||
| if (rank === "7") return 7; // this checks for the sevens | ||
| if (rank === "8") return 8; // this checks for the eights | ||
| if (rank === "9") return 9; // this checks for the nines | ||
| // Handle Face Cards (J, Q, K) And 10's | ||
| if (rank === "J") return 10; // this checks for Jacks | ||
| if (rank === "Q") return 10; // this checks for Queens | ||
| if (rank === "K") return 10; // this checks for Kings | ||
| if (rank === "10") return 10; // this checks for Tens | ||
| // if none of the above its an invalid card and throw an error |
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.
by mapping each of the card ranks directly to values so instead of using if statements and using an object to make it more scalable and cleaner.
How would you express them in JS? And what do you mean by "scalable"?
| test("should return true for a negative proper fraction", () => { | ||
| expect(isproperFraction(-4, 7)).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.
Could consider introduce a test for negative improper fraction to make the test more complete.
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.
have implemented the test for negative improper fractions.
Added test cases for negative improper fractions.
|
Looks good. Well done. |
Learners, PR Template
Self checklist
Changelist