Skip to content

Commit acbe93e

Browse files
committed
Fix proper fraction logic and tests
1 parent 5a89c66 commit acbe93e

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

‎implement-and-rewrite-tests/implement/2-is-proper-fraction.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
// execute the code to ensure all tests pass.
1515

1616
export function isProperFraction(numerator, denominator) {
17-
return numerator < denominator;
17+
return Math.abs(numerator) < Math.abs(denominator);
1818
}
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
import { isProperFraction } from "../implement/2-is-proper-fraction.js";
22

3-
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
4-
5-
// Special case: numerator is zero
6-
test(`should return false when denominator is zero`, () => {
3+
test("should return false when the denominator is zero", () => {
74
expect(isProperFraction(1, 0)).toEqual(false);
5+
expect(isProperFraction(0, 0)).toEqual(false);
86
});
7+
98
test("should return true for a proper fraction", () => {
109
expect(isProperFraction(1, 2)).toEqual(true);
1110
});
1211

13-
test("should return false when numerator equals denominator", () => {
12+
test("should return false when the numerator and denominator have equal magnitudes", () => {
1413
expect(isProperFraction(5, 5)).toEqual(false);
14+
expect(isProperFraction(-5, -5)).toEqual(false);
1515
});
1616

17-
test("should return false when numerator is greater than denominator", () => {
17+
test("should return false when the numerator's magnitude exceeds the denominator's", () => {
1818
expect(isProperFraction(7, 3)).toEqual(false);
19+
expect(isProperFraction(-7, 3)).toEqual(false);
1920
});
2021

2122
test("should return true when numerator is zero", () => {
2223
expect(isProperFraction(0, 5)).toEqual(true);
24+
expect(isProperFraction(0, -5)).toEqual(true);
2325
});
2426

2527
test("should return true when both numerator and denominator are negative and form a proper fraction", () => {
@@ -30,6 +32,10 @@ test("should return true for negative numerator and positive denominator", () =>
3032
expect(isProperFraction(-1, 2)).toEqual(true);
3133
});
3234

33-
test("should return false for positive numerator and negative denominator", () => {
34-
expect(isProperFraction(1, -2)).toEqual(false);
35+
test("should return true for positive numerator and negative denominator when the numerator is smaller", () => {
36+
expect(isProperFraction(1, -2)).toEqual(true);
37+
});
38+
39+
test("should return false for negative numerator and positive denominator when the numerator is larger", () => {
40+
expect(isProperFraction(-3, 2)).toEqual(false);
3541
});

0 commit comments

Comments
 (0)