Skip to content

Commit 5b755ba

Browse files
committed
Sprint 3 - rewrite tests with jest - 2 is proper fraction
Put in code for .js and testing for .jest
1 parent fa101ab commit 5b755ba

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

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

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

1313
function isProperFraction(numerator, denominator) {
14-
// TODO: Implement this function
14+
if (denominator === 0) {
15+
return false
16+
}
17+
18+
if (numerator === denominator) {
19+
return false
20+
}
21+
22+
if (numerator > denominator) {
23+
return false
24+
}
25+
26+
if (numerator < denominator) {
27+
return true
28+
}
1529
}
1630

31+
// function isProperFraction(numerator, denominator) {
32+
// if (denominator === 0) {
33+
// return false
34+
// } else if (Math.abs(numerator) < Math.abs(denominator)) {
35+
// return true
36+
// };
37+
// }
1738
// The line below allows us to load the isProperFraction function into tests in other files.
1839
// This will be useful in the "rewrite tests with jest" step.
1940
module.exports = isProperFraction;

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,20 @@ 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+
// numerator is higher than denominator
13+
test(`should return false when numerator is higher value than denominator`, () => {
14+
expect(isProperFraction(2, 1)).toEqual(false);
15+
});
16+
17+
// numerator is lower than denominator
18+
test(`should return true when numerator is lower value than denominator`, () => {
19+
expect(isProperFraction(1, 2)).toEqual(true);
20+
expect(isProperFraction(-1, 2 )).toEqual(true);
21+
expect(isProperFraction(0, 2 )).toEqual(true);
22+
})
23+
24+
// numerator is equal to denominator
25+
test(`should return false when numerator is equal to denominator`, () => {
26+
expect(isProperFraction(1, 1)).toEqual(false);
27+
});

0 commit comments

Comments
 (0)