Skip to content

Commit bec514f

Browse files
committed
Implement isProperFraction function and added tests for various fraction cases
1 parent b150432 commit bec514f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15+
if (denominator <= 0) {
16+
return false;
17+
}
18+
if (numerator < denominator && numerator >= 0) {
19+
return true;
20+
}
21+
return false;
1522
}
1623

1724
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +38,27 @@ function assertEquals(actualOutput, targetOutput) {
3138

3239
// Example: 1/2 is a proper fraction
3340
assertEquals(isProperFraction(1, 2), true);
41+
42+
// Example: 3/5 is a proper fraction
43+
assertEquals(properFraction(3 / 5), true);
44+
45+
// Example: 1/100 is a positive fraction
46+
assertEquals(smallFraction(1, 100), true);
47+
48+
// Example: 0/4 is a proper fraction with zero numerator
49+
assertEquals(zeroNumerator(0, 4), true);
50+
51+
// Example: 7/7 is an improper fraction,
52+
assertEquals(equalFraction(7, 7), false);
53+
54+
// Example: 8/3 is an improper fraction,
55+
assertEquals(numeratorLarger(8, 3), false);
56+
57+
// Example: 5/0 is an invalid fraction
58+
assertEquals(zeroDenominator(5, 0), false);
59+
60+
// Example: 2/-6 is an invalid fraction
61+
assertEquals(negativeDenominator(2, -6), false);
62+
63+
// Example: -1/4 is an invalid fraction
64+
assertEquals(negativeNumerator(-1, 4), false);

0 commit comments

Comments
 (0)