Skip to content

Commit f8431cf

Browse files
committed
implement isProperFraction() and add tests
1 parent 281f53b commit f8431cf

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

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

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

1313
function isProperFraction(numerator, denominator) {
14-
// TODO: Implement this function
14+
if (denominator === 0 || numerator === 0) return false;
15+
if (!(denominator % 1 === 0 && numerator % 1 === 0)) return false;
16+
if (Math.abs(numerator) < Math.abs(denominator)) return true;
17+
else return false;
1518
}
1619

1720
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -28,6 +31,25 @@ function assertEquals(actualOutput, targetOutput) {
2831

2932
// TODO: Write tests to cover all cases.
3033
// What combinations of numerators and denominators should you test?
31-
34+
// definition is |numerator| < |denominator| so negative values need to be tested as well; also 0 for either - wouldn't be a fraction (or a valid fraction if its the den); also when the num = den
3235
// Example: 1/2 is a proper fraction
3336
assertEquals(isProperFraction(1, 2), true);
37+
assertEquals(isProperFraction(-3, 4), true);
38+
assertEquals(isProperFraction(3, -4), true);
39+
40+
//numerator or denominator is 0
41+
assertEquals(isProperFraction(0, 2), false);
42+
assertEquals(isProperFraction(2, 0), false);
43+
44+
//result is a whole number
45+
assertEquals(isProperFraction(-2, 2), false);
46+
assertEquals(isProperFraction(-3, -3), false);
47+
assertEquals(isProperFraction(3, 3), false);
48+
49+
//numerator or denominator is a decimal
50+
assertEquals(isProperFraction(1.2, 3), false);
51+
assertEquals(isProperFraction(1, 1.2), false);
52+
53+
//numerator or denominator is negative
54+
assertEquals(isProperFraction(-4, 5), true);
55+
assertEquals(isProperFraction(-5, 4), false);

0 commit comments

Comments
 (0)