|
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) { |
12 | | - return true; |
13 | | - } |
| 11 | + return numerator < denominator; |
14 | 12 | } |
15 | 13 |
|
16 | 14 | // The line below allows us to load the isProperFraction function into tests in other files. |
@@ -46,14 +44,18 @@ assertEquals(improperFraction, false); |
46 | 44 | // target output: true |
47 | 45 | // 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 | 46 | const negativeFraction = isProperFraction(-4, 7); |
49 | | -// ====> complete with your assertion |
| 47 | +assertEquals(negativeFraction, true); |
50 | 48 |
|
51 | 49 | // Equal Numerator and Denominator check: |
52 | 50 | // Input: numerator = 3, denominator = 3 |
53 | 51 | // target output: false |
54 | 52 | // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. |
55 | 53 | const equalFraction = isProperFraction(3, 3); |
56 | | -// ====> complete with your assertion |
| 54 | +assertEquals(equalFraction, false); |
57 | 55 |
|
58 | 56 | // Stretch: |
59 | 57 | // What other scenarios could you test for? |
| 58 | + |
| 59 | +// Explanation: Should return true when numerator is zero |
| 60 | +const zeroFraction = isProperFraction(0, 5); |
| 61 | +assertEquals(zeroFraction, true); |
0 commit comments