Skip to content

Commit 878d49e

Browse files
committed
Refactor isProperFraction function to handle absolute values and complete assertions for all test cases
1 parent d75ebfb commit 878d49e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11-
if (numerator < denominator) {
11+
// Proper fraction if absolute numerator is less than denominator
12+
if (Math.abs(numerator) < denominator) {
1213
return true;
14+
} else {
15+
return false;
1316
}
1417
}
1518

@@ -46,14 +49,19 @@ assertEquals(improperFraction, false);
4649
// target output: true
4750
// 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.
4851
const negativeFraction = isProperFraction(-4, 7);
49-
// ====> complete with your assertion
52+
assertEquals(negativeFraction, true);
5053

5154
// Equal Numerator and Denominator check:
5255
// Input: numerator = 3, denominator = 3
5356
// target output: false
5457
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5558
const equalFraction = isProperFraction(3, 3);
56-
// ====> complete with your assertion
59+
assertEquals(equalFraction, false);
5760

5861
// Stretch:
5962
// What other scenarios could you test for?
63+
// Example: numerator = 0, denominator = 5 (0/5 is a proper fraction)
64+
const zeroNumerator = isProperFraction(0, 5);
65+
assertEquals(zeroNumerator, true);
66+
67+
console.log("All tests ran! If no errors, all passed.");

0 commit comments

Comments
 (0)