Skip to content

Commit d90591a

Browse files
wrote assertions for extra cases and updated the function accordingly
1 parent 9dd422c commit d90591a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@
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 (Math.abs(numerator) > Math.abs(denominator)) {
15+
return false;
16+
}
17+
if (Math.abs(numerator) === Math.abs(denominator) ){
18+
return false;
19+
}
20+
if (isNaN(numerator)|| isNaN(denominator)) {
21+
return false;
22+
}
1423
}
1524

25+
1626
// The line below allows us to load the isProperFraction function into tests in other files.
1727
// This will be useful in the "rewrite tests with jest" step.
1828
module.exports = isProperFraction;
@@ -46,14 +56,23 @@ assertEquals(improperFraction, false);
4656
// target output: true
4757
// 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.
4858
const negativeFraction = isProperFraction(-4, 7);
59+
assertEquals(negativeFraction,true)
4960
// ====> complete with your assertion
5061

5162
// Equal Numerator and Denominator check:
5263
// Input: numerator = 3, denominator = 3
5364
// target output: false
5465
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5566
const equalFraction = isProperFraction(3, 3);
67+
assertEquals(equalFraction,false)
5668
// ====> complete with your assertion
5769

5870
// Stretch:
5971
// What other scenarios could you test for?
72+
73+
//Numerator or Denominator not a number
74+
//Input: numerator=NaN, denominator=3
75+
// target output: false
76+
// Explanation: the fraction NaN/3 is not a proper fraction because the numerator is not a number.The function should return false.
77+
const notANumberFraction=isProperFraction(NaN,3);
78+
assertEquals(notANumberFraction,false)

0 commit comments

Comments
 (0)