Skip to content

Commit c645294

Browse files
committed
Fix Proper Fraction
1 parent a39d158 commit c645294

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

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

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

1313
function isProperFraction(numerator, denominator) {
14-
if (numerator > 0 && denominator > 0 && numerator < denominator) {
15-
return true;
16-
} else {
17-
return false;
18-
}
14+
return Math.abs(numerator) < Math.abs(denominator) && denominator !== 0;
1915
}
2016

2117
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -37,7 +33,9 @@ function assertEquals(actualOutput, targetOutput) {
3733
assertEquals(isProperFraction(1, 2), true);
3834
assertEquals(isProperFraction(5, 10), true);
3935
assertEquals(isProperFraction(2, 3), true);
40-
assertEquals(isProperFraction(-2, 4), false);
36+
assertEquals(isProperFraction(-2, 4), true);
4137
assertEquals(isProperFraction(4, 4), false);
42-
assertEquals(isProperFraction(2, -5), false);
43-
assertEquals(isProperFraction(0, 2), false);
38+
assertEquals(isProperFraction(2, -5), true);
39+
assertEquals(isProperFraction(0, 2), true);
40+
assertEquals(isProperFraction(-8, 4), false);
41+
assertEquals(isProperFraction(4, 0), false);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ test("should return true when numerator < denominator and both positive", () =>
1616
expect(isProperFraction(3, 5)).toEqual(true);
1717
});
1818
test("should return false when numerator is negative", () => {
19-
expect(isProperFraction(-2, 5)).toEqual(false);
19+
expect(isProperFraction(-2, 5)).toEqual(true);
2020
});
2121
test("should return false when denominator is negative", () => {
22-
expect(isProperFraction(2, -5)).toEqual(false);
22+
expect(isProperFraction(2, -5)).toEqual(true);
2323
});
2424
test("should return false when numerator is greater than denominator", () => {
2525
expect(isProperFraction(4, 2)).toEqual(false);
2626
});
2727
test("should return false when numerator is zero", () => {
28-
expect(isProperFraction(0, 5)).toEqual(false);
28+
expect(isProperFraction(0, 5)).toEqual(true);
2929
});
3030
test("should return false when numerator equals denominator", () => {
3131
expect(isProperFraction(4, 4)).toEqual(false);

0 commit comments

Comments
 (0)