Skip to content

Commit 9389561

Browse files
committed
Refactor isProperFraction function and enhance test cases for proper, improper, negative, and zero fractions
1 parent b837da8 commit 9389561

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
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) {
12-
return true;
11+
if (Math.abs(numerator) < Math.abs(denominator)) {
12+
return true; // <-- answer
1313
}
14+
return false; // <-- answer
1415
}
1516

1617
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -28,32 +29,23 @@ function assertEquals(actualOutput, targetOutput) {
2829
// Acceptance criteria:
2930

3031
// Proper Fraction check:
31-
// Input: numerator = 2, denominator = 3
32-
// target output: true
33-
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
3432
const properFraction = isProperFraction(2, 3);
3533
assertEquals(properFraction, true);
3634

3735
// Improper Fraction check:
38-
// Input: numerator = 5, denominator = 2
39-
// target output: false
40-
// Explanation: The fraction 5/2 is an improper fraction, where the numerator is greater than or equal to the denominator. The function should return false.
4136
const improperFraction = isProperFraction(5, 2);
4237
assertEquals(improperFraction, false);
4338

4439
// Negative Fraction check:
45-
// Input: numerator = -4, denominator = 7
46-
// target output: true
47-
// 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.
4840
const negativeFraction = isProperFraction(-4, 7);
49-
// ====> complete with your assertion
41+
assertEquals(negativeFraction, true); // <-- answer
5042

5143
// Equal Numerator and Denominator check:
52-
// Input: numerator = 3, denominator = 3
53-
// target output: false
54-
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5544
const equalFraction = isProperFraction(3, 3);
56-
// ====> complete with your assertion
45+
assertEquals(equalFraction, false); // <-- answer
5746

5847
// Stretch:
5948
// What other scenarios could you test for?
49+
// Example: zero numerator
50+
const zeroNumerator = isProperFraction(0, 5);
51+
assertEquals(zeroNumerator, true); // 0/5 is proper

0 commit comments

Comments
 (0)