Skip to content

Commit 060fc0d

Browse files
authored
Implement isProperFraction function with tests
Added checks for zero denominator and updated test cases for proper fractions.
1 parent f6b6ecb commit 060fc0d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15+
if (denominator === 0) {
16+
return false;
17+
}
18+
19+
return Math.abs(numerator) < Math.abs(denominator);
1520
}
1621

1722
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +36,23 @@ function assertEquals(actualOutput, targetOutput) {
3136

3237
// Example: 1/2 is a proper fraction
3338
assertEquals(isProperFraction(1, 2), true);
39+
40+
// Equal numbers → will not be proper
41+
assertEquals(isProperFraction(2, 2), false);
42+
43+
// Improper fractions
44+
assertEquals(isProperFraction(5, 4), false);
45+
assertEquals(isProperFraction(10, 3), false);
46+
47+
// Zero numerator → will be proper
48+
assertEquals(isProperFraction(0, 5), true);
49+
50+
// Negative numbers
51+
assertEquals(isProperFraction(-1, 2), true);
52+
assertEquals(isProperFraction(1, -2), true);
53+
assertEquals(isProperFraction(-3, -2), false);
54+
55+
// Denominator zero
56+
assertEquals(isProperFraction(1, 0), false);
57+
assertEquals(isProperFraction(0, 0), false);
58+

0 commit comments

Comments
 (0)