Skip to content

Commit e9983db

Browse files
Handle negative proper fractions and add tests
1 parent 0e71991 commit e9983db

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

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
@@ -13,11 +13,9 @@
1313
function isProperFraction(numerator, denominator) {
1414
if (denominator === 0) {
1515
return false;
16-
} else if (numerator < denominator) {
17-
return true;
18-
} else {
19-
return false;
20-
}
16+
} {
17+
return Math.abs(numerator) < Math.abs(denominator);
18+
}
2119
}
2220

2321
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -41,6 +39,6 @@ assertEquals(isProperFraction(5, 4), false);
4139
assertEquals(isProperFraction(3, 3), false);
4240
assertEquals(isProperFraction(0, 5), true);
4341
assertEquals(isProperFraction(1, 0), false);
44-
assertEquals(isProperFraction(-3, 2), true);
45-
assertEquals(isProperFraction(2, -5), false);
46-
assertEquals(isProperFraction(-2, -3), false);
42+
assertEquals(isProperFraction(-1, 2), true);
43+
assertEquals(isProperFraction(1, -2), true);
44+
assertEquals(isProperFraction(-1, -2), true);

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
@@ -21,11 +21,11 @@ test(`should return false when numerator is equals to denominator`, () => {
2121
expect(isProperFraction(3, 3)).toEqual(false);
2222
});
2323
test(`should return true when denominator is greater than negative numerator`, () => {
24-
expect(isProperFraction(-3, 2)).toEqual(true);
24+
expect(isProperFraction(-1, 2)).toEqual(true);
2525
});
2626
test(`should return false when numerator is greater than denominator`, () => {
27-
expect(isProperFraction(2, -5)).toEqual(false);
27+
expect(isProperFraction(1, -2)).toEqual(true);
2828
});
2929
test(`should return false when negative numerator is greater than negative denominator`, () => {
30-
expect(isProperFraction(-2, -3)).toEqual(false);
30+
expect(isProperFraction(-1, -2)).toEqual(true);
3131
});

0 commit comments

Comments
 (0)