Skip to content

Commit e739388

Browse files
committed
fix: accept negative numerators and denominators in proper fraction tests
1 parent ab9acf2 commit e739388

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
// execute the code to ensure all tests pass.
1212

1313
function isProperFraction(numerator, denominator) {
14-
// TODO: Implement this function
15-
if (denominator <= 0) {
16-
return false; // not a valid fraction
14+
// Denominator cannot be zero
15+
if (denominator === 0) {
16+
return false;
1717
}
18-
if (numerator < denominator && numerator >= 0) {
19-
return true;
20-
}
21-
return false;
18+
// A proper fraction satisfies: numerator < denominator
19+
// This correctly handles all sign combinations
20+
return Math.abs(numerator) < Math.abs(denominator);
2221
}
2322

2423
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -63,15 +62,15 @@ assertEquals(numeratorLarger, false);
6362
const zeroDenominator = isProperFraction(5, 0);
6463
assertEquals(zeroDenominator, false);
6564

66-
// Example: 2/-6 is an invalid fraction
67-
// Negative denominator makes fraction invalid
65+
// Example: 2/-6 is a proper fraction
66+
// Negative denominator is now allowed
6867
const negativeDenominator = isProperFraction(2, -6);
69-
assertEquals(negativeDenominator, false);
68+
assertEquals(negativeDenominator, true);
7069

7170
// Example: -1/4 is an invalid fraction
72-
// Negative numerator makes fraction negative
71+
// Negative numerator is now allowed
7372
const negativeNumerator = isProperFraction(-1, 4);
74-
assertEquals(negativeNumerator, false);
73+
assertEquals(negativeNumerator, true);
7574

7675
// Example: 1/100 is a positive fraction
7776
// Small numerator with large denominator

0 commit comments

Comments
 (0)