Skip to content

Commit 842dbaa

Browse files
committed
Tests passes all cases and updated test description and formated with prettier extension
1 parent 9fc0d42 commit 842dbaa

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

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

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,40 @@
1111
// execute the code to ensure all tests pass.
1212

1313
function isProperFraction(numerator, denominator) {
14-
// TODO: Implement this function
15-
if(denominator === 0){
14+
if (denominator === 0) {
1615
return false;
17-
}else if(Math.abs(numerator) < Math.abs(denominator)){
16+
} else if (Math.abs(numerator) < Math.abs(denominator)) {
1817
return true;
19-
}else return false;
18+
} else return false;
2019
}
2120

22-
// The line below allows us to load the isProperFraction function into tests in other files.
23-
// This will be useful in the "rewrite tests with jest" step.
24-
module.exports = isProperFraction;
25-
2621
// Here's our helper again
2722
function assertEquals(actualOutput, targetOutput) {
28-
console.assert(actualOutput === targetOutput,
23+
console.assert(
24+
actualOutput === targetOutput,
2925
`Expected ${actualOutput} to equal ${targetOutput}`
3026
);
3127
}
3228

3329
// TODO: Write tests to cover all cases.
34-
// What combinations of numerators and denominators should you test?
35-
36-
// Example: 1/2 is a proper fraction
37-
assertEquals(isProperFraction(1, 2), "true");
38-
assertEquals(isProperFraction(3, 2), "false");
39-
assertEquals(isProperFraction(1, 0), "false");
40-
assertEquals(isProperFraction(8, 9), "true");
41-
assertEquals(isProperFraction(0, 1), "false");
42-
assertEquals(isProperFraction(-4, 1), "false");
43-
assertEquals(isProperFraction(2, -4), "false");
30+
31+
// numerator < denominator (in absolute value) → proper fraction
32+
assertEquals(isProperFraction(1, 2), true);
33+
assertEquals(isProperFraction(8, 9), true);
34+
assertEquals(isProperFraction(0, 5), true); // numerator = 0
35+
36+
// numerator > denominator (in absolute value) → improper fraction
37+
assertEquals(isProperFraction(3, 2), false);
38+
assertEquals(isProperFraction(-4, 1), false);
39+
40+
// numerator = denominator (in absolute value) → not a proper fraction
41+
assertEquals(isProperFraction(5, 5), false);
42+
assertEquals(isProperFraction(-7, -7), false);
43+
44+
// denominator = 0 → invalid fraction
45+
assertEquals(isProperFraction(1, 0), false);
46+
assertEquals(isProperFraction(0, 0), false);
47+
48+
// negative numbers still follow the rule: numerator < denominator (in absolute value)
49+
assertEquals(isProperFraction(2, -4), true);
50+
assertEquals(isProperFraction(-2, -5), true);

0 commit comments

Comments
 (0)