-
-
Notifications
You must be signed in to change notification settings - Fork 337
Sheffield | 26-ITP-Jan | Martha Ogunbiyi | Sprint 3 | coursework/sprint-3-implement-and-rewrite #1240
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 | 26-ITP-Jan | Martha Ogunbiyi | Sprint 3 | coursework/sprint-3-implement-and-rewrite #1240
Changes from all commits
0cbad6b
1b26097
0db8451
4f46450
4b897f5
5eb49c7
06520c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| // We will use the same function, but write tests for it using Jest in this file. | ||
| const getCardValue = require("../implement/3-get-card-value"); | ||
|
|
||
| // TODO: Write tests in Jest syntax to cover all possible outcomes. | ||
| // Write tests in Jest syntax to cover all possible outcomes. | ||
|
|
||
| // Case 1: Ace (A) | ||
| test(`Should return 11 when given an ace card`, () => { | ||
|
|
@@ -11,8 +11,24 @@ test(`Should return 11 when given an ace card`, () => { | |
|
|
||
| // Suggestion: Group the remaining test data into these categories: | ||
| // Number Cards (2-10) | ||
| test(`Should return should return its numeric value`, () => { | ||
| expect(getCardValue("9♠")).toEqual(9); | ||
| }); | ||
| // Face Cards (J, Q, K) | ||
| test(`Should return 10`, () => { | ||
| expect(getCardValue("K♠")).toEqual(10); | ||
| }); | ||
| // Invalid Cards | ||
| test(`Should throw an error`, () => { | ||
| expect(() => { | ||
| getCardValue("♠9"); | ||
| }).toThrow(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is good. To take it further, add a test to see if the returned error message is what you are expecting.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the feedback . Would add further test to see what error messages they return. |
||
| }); | ||
| test(`Should throw an error`, () => { | ||
| expect(() => { | ||
| getCardValue("♠"); | ||
| }).toThrow(); | ||
| }); | ||
|
|
||
| // To learn how to test whether a function throws an error as expected in Jest, | ||
| // please refer to the Jest documentation: | ||
|
|
||
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 you should check the definition of a proper fraction again and see if your test case for negative numbers is correct expecially -3/8. I will advise you to use Match.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.
Thanks for the feedback! My implementation checks whether the value of the fraction is between 0 and 1, which is the standard mathematical definition of a proper fraction. Based on that definition:
-3/8 → -0.375 → not proper
-8/-3 → 2.66… → not proper
-3/-8 → 0.375 → proper
Using Math.abs() would treat negative fractions like -3/8 as proper, even though their value is negative. That’s why I didn’t use Math.abs(), and why my tests reflect the “between 0 and 1” definition. Happy to adjust if a different definition is expected.
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 first rule of a proper fraction is that the numerator is less than the denominator. Your solution will fail on most negative numbers. Reason why a proper fraction is when the absolute value of the numerator is less than the absolute value of the denominator. A proper fraction is always less than 1
Based on your code, let's consider the following examples
you are returning
properFraction > 0 && properFraction < 1-1/2 will return false because the division is -0.5, and it is not greater than 0. But this is wrong as the result is less than 1 and the first rule of numerator < denominator stands.
Same thing with -3/8.
You can check this for further info https://www.splashlearn.com/math-vocabulary/proper-fraction
Math.abs() helps you work with negative numbers.
You can do more research on 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.
Thanks for explaining! I understand now that you're using the definition based on absolute values. I’ll update my code and tests to use Math.abs() so it matches that approach.