Skip to content

Commit 6a32e82

Browse files
committed
Add implementations for isProperFraction including boundary and invalid case tests
1 parent a74dbb7 commit 6a32e82

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

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,10 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15+
if (denominator === 0) {
16+
return false;
17+
}
18+
return numerator < denominator;
1519
}
1620

1721
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +35,24 @@ function assertEquals(actualOutput, targetOutput) {
3135

3236
// Example: 1/2 is a proper fraction
3337
assertEquals(isProperFraction(1, 2), true);
38+
// Proper fractions
39+
assertEquals(isProperFraction(2, 3), true);
40+
assertEquals(isProperFraction(3, 4), true);
41+
assertEquals(isProperFraction(0, 5), true);
42+
43+
// Improper fractions
44+
assertEquals(isProperFraction(5, 5), false);
45+
assertEquals(isProperFraction(7, 3), false);
46+
47+
// Denominator zero
48+
assertEquals(isProperFraction(5, 0), false);
49+
50+
// Negative numerators
51+
assertEquals(isProperFraction(-1, 2), true);
52+
53+
// Negative denominators
54+
assertEquals(isProperFraction(1, -2), false);
55+
56+
// Both negative
57+
assertEquals(isProperFraction(-3, -2), false);
58+

0 commit comments

Comments
 (0)