Skip to content

Commit b125726

Browse files
committed
Update isProperFraction logic for denominator checks
1 parent 258f3f7 commit b125726

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15-
if (denominator === 0) {
15+
if (denominator <= 0) {
1616
return false;
1717
}
1818
return numerator < denominator;

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,37 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
88
test(`should return false when denominator is zero`, () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
1010
});
11+
12+
// Denominator zero
13+
test("should return false when denominator is zero", () => {
14+
expect(isProperFraction(1, 0)).toEqual(false);
15+
});
16+
17+
// Proper fractions
18+
test("should return true for proper fractions (numerator < denominator)", () => {
19+
expect(isProperFraction(1, 2)).toEqual(true);
20+
expect(isProperFraction(2, 3)).toEqual(true);
21+
expect(isProperFraction(3, 4)).toEqual(true);
22+
expect(isProperFraction(0, 5)).toEqual(true); // zero numerator is allowed
23+
});
24+
25+
// Improper fractions
26+
test("should return false for improper fractions (numerator >= denominator)", () => {
27+
expect(isProperFraction(5, 5)).toEqual(false);
28+
expect(isProperFraction(7, 3)).toEqual(false);
29+
});
30+
31+
// Negative numerators
32+
test("should return true when numerator is negative and denominator is positive", () => {
33+
expect(isProperFraction(-1, 2)).toEqual(true);
34+
});
35+
36+
// Negative denominators
37+
test("should return false when denominator is negative", () => {
38+
expect(isProperFraction(1, -2)).toEqual(false);
39+
});
40+
41+
// Both negative
42+
test("should return false when both numerator and denominator are negative", () => {
43+
expect(isProperFraction(-3, -2)).toEqual(false);
44+
});

0 commit comments

Comments
 (0)