Skip to content

Commit 98015f6

Browse files
committed
Implement isProperFraction function and add comprehensive tests for various cases
1 parent b9830f0 commit 98015f6

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

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

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

1313
function isProperFraction(numerator, denominator) {
14-
// TODO: Implement this function
14+
return numerator > 0 && denominator > 0 && numerator < denominator;
1515
}
1616

1717
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -28,6 +28,23 @@ function assertEquals(actualOutput, targetOutput) {
2828

2929
// TODO: Write tests to cover all cases.
3030
// What combinations of numerators and denominators should you test?
31+
const properFraction = isProperFraction(2, 3);
32+
assertEquals(properFraction, true);
3133

3234
// Example: 1/2 is a proper fraction
3335
assertEquals(isProperFraction(1, 2), true);
36+
37+
const improperFraction = isProperFraction(5, 2);
38+
assertEquals(improperFraction, false);
39+
40+
const negativeFraction = isProperFraction(-4, 7);
41+
assertEquals(negativeFraction, true);
42+
43+
const equalFraction = isProperFraction(3, 3);
44+
assertEquals(equalFraction, false);
45+
46+
const zeroNumerator = isProperFraction(0, 5);
47+
assertEquals(zeroNumerator, true);
48+
49+
const zeroDenominator = isProperFraction(5, 0);
50+
assertEquals(zeroDenominator, false);

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,28 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
77
// Special case: numerator is zero
88
test(`should return false when denominator is zero`, () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
10+
expect(isProperFraction(-5, 0)).toEqual(false);
11+
});
12+
13+
test(`should return true for positive proper fractions`, () => {
14+
expect(isProperFraction(1, 2)).toEqual(true);
15+
expect(isProperFraction(2, 5)).toEqual(true);
16+
});
17+
18+
test(`should return false for positive improper fractions or equal values`, () => {
19+
expect(isProperFraction(3, 2)).toEqual(false);
20+
expect(isProperFraction(5, 5)).toEqual(false);
21+
});
22+
23+
test(`should return true when numerator is zero`, () => {
24+
expect(isProperFraction(0, 5)).toEqual(true);
25+
expect(isProperFraction(0, -5)).toEqual(true);
26+
});
27+
28+
test(`should evaluate correctly with various negative number combinations`, () => {
29+
expect(isProperFraction(-1, 2)).toEqual(true);
30+
expect(isProperFraction(1, -2)).toEqual(true);
31+
expect(isProperFraction(-1, -2)).toEqual(true);
32+
expect(isProperFraction(-5, 2)).toEqual(false);
33+
expect(isProperFraction(5, -2)).toEqual(false);
1034
});

0 commit comments

Comments
 (0)