Skip to content

Commit 5218dc7

Browse files
committed
Updated isProperFraction implementation and correct tests for negative fractions
1 parent 62f2bc9 commit 5218dc7

File tree

2 files changed

+49
-13
lines changed

2 files changed

+49
-13
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,20 @@
1111
// execute the code to ensure all tests pass.
1212

1313
function isProperFraction(numerator, denominator) {
14-
// TODO: Implement this function
1514
if (denominator === 0) {
1615
return false;
1716
}
18-
if (numerator < 0 && denominator < 0) {
19-
return Math.abs(numerator) < Math.abs(denominator);
20-
}
21-
if (numerator < 0 || denominator < 0) {
22-
return false;
23-
}
24-
return numerator < denominator;
17+
18+
return Math.abs(numerator) < Math.abs(denominator);
2519
}
2620

21+
module.exports = isProperFraction;
22+
2723
// The line below allows us to load the isProperFraction function into tests in other files.
2824
// This will be useful in the "rewrite tests with jest" step.
29-
module.exports = isProperFraction;
25+
//module.exports = isProperFraction;
3026

31-
// Here's our helper again
27+
/* Here's our helper again
3228
function assertEquals(actualOutput, targetOutput) {
3329
console.assert(
3430
actualOutput === targetOutput,
@@ -40,11 +36,14 @@ function assertEquals(actualOutput, targetOutput) {
4036
// What combinations of numerators and denominators should you test?
4137
4238
// Example: 1/2 is a proper fraction
39+
/*
4340
assertEquals(isProperFraction(1, 2), true);
4441
assertEquals(isProperFraction(2, 1), false);
4542
assertEquals(isProperFraction(0, 1), true);
4643
assertEquals(isProperFraction(-1, 2), false);
4744
assertEquals(isProperFraction(1, -2), false);
4845
assertEquals(isProperFraction(-1, -2), false);
4946
assertEquals(isProperFraction(3, 4), true);
50-
assertEquals(isProperFraction(4, 3), false);
47+
assertEquals(isProperFraction(4, 3), false);
48+
49+
*/

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,43 @@ test(`should return true when numerator is zero and denominator is positive`, ()
1313
expect(isProperFraction(0, 1)).toEqual(true);
1414
});
1515

16-
test(`should return false when numerator is zero and denominator is negative`, () => {
17-
expect(isProperFraction(0, -1)).toEqual(false);
16+
test(`should return true when numerator is zero and denominator is negative`, () => {
17+
expect(isProperFraction(0, -1)).toEqual(true);
18+
});
19+
20+
21+
test("1/2 is proper", () => {
22+
expect(isProperFraction(1, 2)).toBe(true);
23+
});
24+
25+
test("2/1 is improper", () => {
26+
expect(isProperFraction(2, 1)).toBe(false);
27+
});
28+
29+
test("0/1 is proper", () => {
30+
expect(isProperFraction(0, 1)).toBe(true);
31+
});
32+
33+
test("-1/2 is proper", () => {
34+
expect(isProperFraction(-1, 2)).toBe(true);
35+
});
36+
37+
test("1/-2 is proper", () => {
38+
expect(isProperFraction(1, -2)).toBe(true);
39+
});
40+
41+
test("-1/-2 is proper", () => {
42+
expect(isProperFraction(-1, -2)).toBe(true);
43+
});
44+
45+
test("3/4 is proper", () => {
46+
expect(isProperFraction(3, 4)).toBe(true);
47+
});
48+
49+
test("4/3 is improper", () => {
50+
expect(isProperFraction(4, 3)).toBe(false);
51+
});
52+
53+
test("denominator 0 returns false", () => {
54+
expect(isProperFraction(1, 0)).toBe(false);
1855
});

0 commit comments

Comments
 (0)