Skip to content

Commit 8a750dd

Browse files
committed
write function is ProperFraction() to pass all tests
1 parent ad52844 commit 8a750dd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
// After you have implemented the function, write tests to cover all the cases, and
1111
// execute the code to ensure all tests pass.
1212

13-
function isProperFraction(numerator, denominator) {}
13+
function isProperFraction(numerator, denominator) {
14+
// console.log(numerator, denominator);
15+
// console.log(Math.abs(numerator), Math.abs(denominator));
16+
if (denominator !== 0 && Math.abs(numerator) < Math.abs(denominator)) {
17+
return true;
18+
} else {
19+
return false;
20+
}
21+
}
1422

1523
// The line below allows us to load the isProperFraction function into tests in other files.
1624
// This will be useful in the "rewrite tests with jest" step.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
88

99
test(`should return true when the absolute value of the numerator is less than the absolute value of the denominator and the denominator is not 0`, () => {
1010
expect(isProperFraction(1, 2)).toEqual(true);
11+
expect(isProperFraction(1, -3)).toEqual(true);
1112
expect(isProperFraction(3.5, 4)).toEqual(true);
1213
expect(isProperFraction(-99, -100)).toEqual(true);
1314
expect(isProperFraction(0, -5)).toEqual(true);
15+
expect(isProperFraction(0, 56)).toEqual(true);
1416
expect(isProperFraction(8, 12.5)).toEqual(true);
1517
expect(isProperFraction(-6, 12)).toEqual(true);
18+
expect(isProperFraction(0.03, 0.1)).toEqual(true);
1619
});
1720

1821
test(`should return false when the denominator is equal to zero`, () => {
@@ -29,6 +32,7 @@ test(`should return false when the absolute value of the numerator is greater th
2932
expect(isProperFraction(-15, -4)).toEqual(false);
3033
expect(isProperFraction(36, -5)).toEqual(false);
3134
expect(isProperFraction(3.8, 2.7)).toEqual(false);
35+
expect(isProperFraction(1, 0.7)).toEqual(false);
3236
});
3337

3438
test(`should return false when the absolute value of the numerator is equal to the absolute value of the denominator`, () => {

0 commit comments

Comments
 (0)