Skip to content

Commit 90a9885

Browse files
author
Payman IB
committed
Refactor isProperFraction function to use absolute values for proper fraction checks and add missing assertions for test cases
1 parent 696a379 commit 90a9885

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
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+
if (Math.abs(numerator) < Math.abs(denominator)) {
1212
return true;
1313
}
14+
else if (numerator >= denominator) {
15+
return false;
16+
}
1417
}
1518

1619
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,29 +34,38 @@ function assertEquals(actualOutput, targetOutput) {
3134
// Input: numerator = 2, denominator = 3
3235
// target output: true
3336
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
37+
3438
const properFraction = isProperFraction(2, 3);
3539
assertEquals(properFraction, true);
3640

3741
// Improper Fraction check:
3842
// Input: numerator = 5, denominator = 2
3943
// target output: false
4044
// 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.
45+
46+
4147
const improperFraction = isProperFraction(5, 2);
4248
assertEquals(improperFraction, false);
4349

4450
// Negative Fraction check:
4551
// Input: numerator = -4, denominator = 7
4652
// target output: true
4753
// 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.
54+
55+
4856
const negativeFraction = isProperFraction(-4, 7);
49-
// ====> complete with your assertion
57+
assertEquals(negativeFraction, true);
5058

5159
// Equal Numerator and Denominator check:
5260
// Input: numerator = 3, denominator = 3
5361
// target output: false
5462
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
63+
5564
const equalFraction = isProperFraction(3, 3);
56-
// ====> complete with your assertion
65+
assertEquals(equalFraction, false);
5766

5867
// Stretch:
5968
// What other scenarios could you test for?
69+
70+
const invalidFraction = isProperFraction(0, 5);
71+
assertEquals(invalidFraction, true);

0 commit comments

Comments
 (0)