Skip to content

Commit c5b9e52

Browse files
added additional tests to check for a properr fraction and implemented the function accordingly
1 parent c17f6c3 commit c5b9e52

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11-
if (numerator < denominator) {
11+
if (Math.abs(numerator) < Math.abs(denominator)) {
1212
return true;
1313
}
14+
if (
15+
Math.abs(numerator) > Math.abs(denominator) ||
16+
numerator === denominator
17+
) {
18+
return false;
19+
}
20+
if(Number.isNaN(numerator) || Number.isNaN(denominator)){
21+
throw new Error("Not a number")
22+
}
1423
}
1524

1625
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -46,14 +55,38 @@ assertEquals(improperFraction, false);
4655
// target output: true
4756
// 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.
4857
const negativeFraction = isProperFraction(-4, 7);
58+
assertEquals(negativeFraction, true);
4959
// ====> complete with your assertion
5060

5161
// Equal Numerator and Denominator check:
5262
// Input: numerator = 3, denominator = 3
5363
// target output: false
5464
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5565
const equalFraction = isProperFraction(3, 3);
66+
assertEquals(equalFraction, false);
5667
// ====> complete with your assertion
5768

5869
// Stretch:
5970
// What other scenarios could you test for?
71+
72+
//Both Numerator and Denominator are negative check:
73+
// Input: numerator = -4, denominator = -3
74+
// target output: false
75+
// Explanation:The fraction -4/-3 is not a proper fraction because the absolute value o the numerator is bigger than the absolute value of the denominator
76+
const bothNegativeFraction = isProperFraction(-4, -3);
77+
assertEquals(bothNegativeFraction, false);
78+
79+
//Numerator is bigger than the negative Denominator's absolute value:
80+
// Input: numerator = 4, denominator = -9
81+
// target output: true
82+
// Explanation:The fraction 4/-9 is a proper fraction because the absolute value of the denominator is smaller than the the value of the numerator
83+
const negativeDenominator=isProperFraction(4,-9)
84+
assertEquals(negativeDenominator,true)
85+
86+
87+
88+
89+
90+
//got stuck on this one, don't know how to test
91+
// const notANumber=isProperFraction("a",2)
92+
// assertEquals(negativeFraction, "Not a number");

0 commit comments

Comments
 (0)