Skip to content

Commit 0eef99b

Browse files
committed
Solved task 1-implement/2-is-proper-fraction.js
1 parent 47782ce commit 0eef99b

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ function isProperFraction(numerator, denominator) {
1111
if (numerator < denominator) {
1212
return true;
1313
}
14+
if (numerator > denominator) {
15+
return false;
16+
}
17+
if (numerator === denominator) {
18+
return false;
19+
}
1420
}
1521

1622
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -46,14 +52,35 @@ assertEquals(improperFraction, false);
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.
4854
const negativeFraction = isProperFraction(-4, 7);
49-
// ====> complete with your assertion
55+
assertEquals(negativeFraction, true);
5056

5157
// Equal Numerator and Denominator check:
5258
// Input: numerator = 3, denominator = 3
5359
// target output: false
5460
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5561
const equalFraction = isProperFraction(3, 3);
56-
// ====> complete with your assertion
62+
assertEquals(equalFraction, false);
5763

5864
// Stretch:
5965
// What other scenarios could you test for?
66+
67+
// Both Numerator and Denominator Negative check:
68+
// Input: numerator = -4, denominator = -9
69+
// target output: false
70+
// Explanation: The fraction -4/-9 is equivalent to 4/9, which is a proper fraction. Function should return false.
71+
const bothNegative = isProperFraction(-4, -9);
72+
assertEquals(bothNegative, false);
73+
74+
// Zero Numerator check:
75+
// Input: numerator = 0, denominator = 7
76+
// target output: true
77+
// Explanation: The fraction 0/7 is a proper fraction because the numerator is less than the denominator. The function should return true.
78+
const zeroNumerator = isProperFraction(0, 7);
79+
assertEquals(zeroNumerator, true);
80+
81+
// Zero Denominator check:
82+
// Input: numerator = 2, denominator = 0
83+
// target output: false
84+
// Explanation: The fraction 2/0 is undefined because division by zero is not allowed. The function should return false.
85+
const zeroDenominator = isProperFraction(2, 0);
86+
assertEquals(zeroDenominator, false);

0 commit comments

Comments
 (0)