-
-
Notifications
You must be signed in to change notification settings - Fork 219
NW | 25-ITP-Sep | TzeMing Ho | Sprint 3 | coursework/sprint-3-implement-and-rewrite #709
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?
Changes from 21 commits
9d43b8b
150a780
8fdb210
24f2d3c
96ebf89
b2f87c5
b73f73f
72112ca
a505558
6c1636f
401db2b
5733d12
096632e
b0fe035
7a2b0a1
096f9b6
5245e20
bc00dfc
bc1b331
51eedee
6c04424
3c8fe4f
6166064
4b1ad2d
892f63b
f14ee5c
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 |
---|---|---|
|
@@ -8,8 +8,10 @@ | |
// write one test at a time, and make it pass, build your solution up methodically | ||
|
||
function isProperFraction(numerator, denominator) { | ||
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. Your isProperFraction works well. However, if you wanted to simplify it even more, you could try:
|
||
if (numerator < denominator) { | ||
if (Math.abs(numerator) < Math.abs(denominator)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
|
@@ -47,13 +49,78 @@ assertEquals(improperFraction, false); | |
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. | ||
const negativeFraction = isProperFraction(-4, 7); | ||
// ====> complete with your assertion | ||
assertEquals(negativeFraction, true); | ||
|
||
// Equal Numerator and Denominator check: | ||
// Input: numerator = 3, denominator = 3 | ||
// target output: false | ||
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. | ||
const equalFraction = isProperFraction(3, 3); | ||
// ====> complete with your assertion | ||
assertEquals(equalFraction, false); | ||
|
||
// Stretch: | ||
// What other scenarios could you test for? | ||
|
||
// Stretch 1: negative denominator | ||
// Input: numerator = 2, denominator = -3 | ||
// target output: true | ||
// Explanation: The fraction 2/-3 is a proper fraction because the absolute value of denominator (3) is larger than the numerator (2). | ||
const negativeDenominator = isProperFraction(2, -3); | ||
assertEquals(negativeDenominator, true); | ||
|
||
// Stretch 2: zero numerator | ||
// Input: numerator = 0, denominator = 5 | ||
// target output: true | ||
// Explanation: The fraction 0/5 is a proper fraction because the absolute value of numerator (0) is less than the denominator (5). | ||
const zeroNumerator = isProperFraction(0, 5); | ||
assertEquals(zeroNumerator, true); | ||
|
||
// Stretch 3: zero denominator - this is mathematically undefined but we can decide how we want to handle it | ||
// Input: numerator = 5, denominator = 0 | ||
// target output: false | ||
// Explanation: The fraction 5/0 is undefined in mathematics. In this implementation, we choose to return false. | ||
const zeroDenominator = isProperFraction(5, 0); | ||
assertEquals(zeroDenominator, false); | ||
|
||
// Stretch 4: both zero | ||
// Input: numerator = 0, denominator = 0 | ||
// target output: false | ||
// Explanation: The fraction 0/0 is indeterminate in mathematics. In this implementation, we choose to return false. | ||
const bothZero = isProperFraction(0, 0); | ||
assertEquals(bothZero, false); | ||
|
||
// Stretch 5: negative numerator and denominator | ||
// Input: numerator = -3, denominator = -5 | ||
// target output: true | ||
// Explanation: The fraction -3/-5 is a proper fraction because the absolute value of the numerator (3) is less than the absolute value of the denominator (5). The function should return true. | ||
const negativeNumeratorAndDenominator = isProperFraction(-3, -5); | ||
assertEquals(negativeNumeratorAndDenominator, true); | ||
|
||
// Stretch 6: improper negative numerator and denominator | ||
// Input: numerator = -3, denominator = -2 | ||
// target output: false | ||
// Explanation: The fraction -3/-2 is an improper fraction because the absolute value of the numerator (3) is greater than the absolute value of the denominator (2). The function should return false. | ||
const properNegativeNumeratorAndDenominator = isProperFraction(-3, -2); | ||
assertEquals(properNegativeNumeratorAndDenominator, false); | ||
|
||
// Stretch 7: decimal values | ||
// Input: numerator = 2.5, denominator = 3.5 | ||
// target output: true | ||
// Explanation: The fraction 2.5/3.5 is a proper fraction because the absolute value of the numerator (2.5) is less than the absolute value of the denominator (3.5). The function should return true. | ||
const decimalValues = isProperFraction(2.5, 3.5); | ||
assertEquals(decimalValues, true); | ||
|
||
// Stretch 8: improper decimal values | ||
// Input: numerator = 3.5, denominator = 2.5 | ||
// target output: false | ||
// Explanation: The fraction 3.5/2.5 is an improper fraction because the absolute value of the numerator (3.5) is greater than the absolute value of the denominator (2.5). The function should return false. | ||
const improperDecimalValues = isProperFraction(3.5, 2.5); | ||
assertEquals(improperDecimalValues, false); | ||
|
||
// Stretch 9: invalid inputs (non-numeric values) | ||
// Input: numerator = "a", denominator = 2 | ||
// target output: false | ||
// Explanation: The function should handle non-numeric inputs gracefully. In this case, we choose to return false. | ||
const invalidInputs = isProperFraction("a", 2); | ||
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. 👏 Good job making sure that 'unhappy path' is tested. |
||
assertEquals(invalidInputs, false); |
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. When I run your tests, I get this result: Can you take a look? |
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. I tried a few more 'unhappy path' tests:
I was expecting ('Error: 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.
What would happen if I run the test with: