Skip to content

Commit 989855e

Browse files
committed
2-is proper-fraction test with jest
1 parent 4d61885 commit 989855e

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11-
if (numerator < denominator) {
12-
return true;
13-
}
14-
if (numerator >= denominator) {
11+
// First check: both numerator and denominator should be positive
12+
if (numerator < 0 || denominator < 0) {
1513
return false;
1614
}
17-
if (Math.abs(numerator) < Math.abs(denominator)) {
15+
16+
// Second check: numerator should be less than denominator
17+
if (numerator < denominator) {
1818
return true;
19-
}
20-
if (Math.abs(numerator) >= Math.abs(denominator)) {
19+
} else {
2120
return false;
2221
}
2322
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ test("should return true for a proper fraction", () => {
77
});
88

99
// Case 2: Identify Improper Fractions:
10+
test("should return false for an improper fraction", () => {
11+
expect(isProperFraction(5, 3)).toEqual(false);
12+
});
1013

1114
// Case 3: Identify Negative Fractions:
15+
test("should return false for a negative fraction", () => {
16+
expect(isProperFraction(-2, 3)).toEqual(false);
17+
});
1218

1319
// Case 4: Identify Equal Numerator and Denominator:
20+
test("should return false for equal numerator and denominator", () => {
21+
expect(isProperFraction(3, 3)).toEqual(false);
22+
});

0 commit comments

Comments
 (0)