Skip to content

Commit 7daf16b

Browse files
committed
added tests for most fraction types and conditions for them as well
1 parent 2038048 commit 7daf16b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11+
if (Math.sign(numerator) === -1 || Math.sign(denominator) === -1) {
12+
if (Math.abs(numerator) < Math.abs(denominator)) {
13+
return true;
14+
}
15+
} else if (numerator === 0) {
16+
return false;
17+
}
18+
1119
if (numerator < denominator) {
1220
return true;
21+
} else if (numerator > denominator) {
22+
return false;
23+
} else if (numerator === denominator) {
24+
return false;
1325
}
1426
}
1527

1628
// The line below allows us to load the isProperFraction function into tests in other files.
1729
// This will be useful in the "rewrite tests with jest" step.
18-
module.exports = isProperFraction;
30+
//module.exports = isProperFraction;
1931

2032
// here's our helper again
2133
function assertEquals(actualOutput, targetOutput) {
@@ -45,15 +57,20 @@ assertEquals(improperFraction, false);
4557
// Input: numerator = -4, denominator = 7
4658
// target output: true
4759
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
48-
const negativeFraction = isProperFraction(-4, 7);
60+
const negativeFraction = isProperFraction(-4, -7);
4961
// ====> complete with your assertion
62+
assertEquals(negativeFraction, true);
5063

5164
// Equal Numerator and Denominator check:
5265
// Input: numerator = 3, denominator = 3
5366
// target output: false
5467
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5568
const equalFraction = isProperFraction(3, 3);
5669
// ====> complete with your assertion
70+
assertEquals(equalFraction, false);
5771

5872
// Stretch:
5973
// What other scenarios could you test for?
74+
//we can test if the numerator is 0
75+
const zeroFraction = isProperFraction(0, 4);
76+
assertEquals(zeroFraction, false);

0 commit comments

Comments
 (0)