|
8 | 8 | // write one test at a time, and make it pass, build your solution up methodically |
9 | 9 |
|
10 | 10 | function isProperFraction(numerator, denominator) { |
11 | | - if (numerator < denominator) { |
| 11 | + if (Math.abs(numerator) < Math.abs(denominator)) { |
12 | 12 | return true; |
13 | | - } |
| 13 | + } else { |
| 14 | + return false; |
| 15 | + } |
14 | 16 | } |
15 | 17 |
|
| 18 | + |
16 | 19 | // The line below allows us to load the isProperFraction function into tests in other files. |
17 | 20 | // This will be useful in the "rewrite tests with jest" step. |
18 | 21 | module.exports = isProperFraction; |
@@ -46,14 +49,26 @@ assertEquals(improperFraction, false); |
46 | 49 | // target output: true |
47 | 50 | // 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. |
48 | 51 | const negativeFraction = isProperFraction(-4, 7); |
| 52 | +assertEquals(negativeFraction, true); |
49 | 53 | // ====> complete with your assertion |
50 | 54 |
|
51 | 55 | // Equal Numerator and Denominator check: |
52 | 56 | // Input: numerator = 3, denominator = 3 |
53 | 57 | // target output: false |
54 | 58 | // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. |
55 | 59 | const equalFraction = isProperFraction(3, 3); |
| 60 | +assertEquals(equalFraction, false); |
56 | 61 | // ====> complete with your assertion |
57 | 62 |
|
58 | 63 | // Stretch: |
59 | 64 | // What other scenarios could you test for? |
| 65 | +const zeroNumerator = isProperFraction(0, 5); |
| 66 | +assertEquals(zeroNumerator, true); |
| 67 | + |
| 68 | +const negativeDenominator = isProperFraction(4, -7); |
| 69 | +assertEquals(negativeDenominator, true); |
| 70 | + |
| 71 | +const bothNegative = isProperFraction(-4, -7); |
| 72 | +assertEquals(bothNegative, true); |
| 73 | + |
| 74 | + |
0 commit comments