Skip to content

Commit 468706d

Browse files
committed
test: enhance isProperFraction function with additional edge cases
1 parent 9207345 commit 468706d

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,23 @@
1111
// execute the code to ensure all tests pass.
1212

1313
function isProperFraction(numerator, denominator) {
14-
if (numerator < denominator ){
15-
return true;
14+
15+
if(denominator === 0){
16+
return false
17+
}
18+
19+
if (typeof numerator !== "number" || typeof denominator !== "number") {
20+
return false;
1621
}
17-
return false;
22+
23+
if (numerator < 0) {
24+
numerator = numerator * -1;
25+
}
26+
27+
if (denominator < 0) {
28+
denominator = denominator * -1;
29+
}
30+
return numerator < denominator;
1831
}
1932

2033
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -33,9 +46,18 @@ function assertEquals(actualOutput, targetOutput) {
3346
// What combinations of numerators and denominators should you test?
3447

3548
// Example: 1/2 is a proper fraction
36-
assertEquals(isProperFraction(3, 2), false);
37-
assertEquals(isProperFraction(2, 2), false);
49+
assertEquals(isProperFraction(5, 9), true);
3850
assertEquals(isProperFraction(3, 4), true);
39-
assertEquals(isProperFraction(5, 3), false);
51+
assertEquals(isProperFraction(2, 8), true);
52+
assertEquals(isProperFraction(1, 6), true);
4053
assertEquals(isProperFraction(0, 5), true);
54+
assertEquals(isProperFraction(-3, -5), true);
55+
56+
57+
58+
// Example: 3/2 is a improper fraction
59+
assertEquals(isProperFraction(3, 0), false);
60+
assertEquals(isProperFraction(-7, 5), false);
61+
assertEquals(isProperFraction(5, "-36"), false);
62+
assertEquals(isProperFraction("-8", 5), false);
4163
console.log("✓ All test executed!");

0 commit comments

Comments
 (0)