Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit 9a62aee

Browse files
committed
node is-proper-fraction.js tested
1 parent 06822f6 commit 9a62aee

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

week-3/implement/is-proper-fraction.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,41 @@
3333
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
3434

3535
// These acceptance criteria cover a range of scenarios to ensure that the isProperFraction function handles both proper and improper fractions correctly and handles potential errors such as a zero denominator.
36+
37+
///...............................................
38+
39+
40+
41+
function isProperFraction(numerator, denominator) {
42+
if (denominator === 0) {
43+
return undefined;
44+
}
45+
if (numerator < denominator && numerator >= 0) {
46+
return true;
47+
} else {
48+
return false;
49+
}
50+
}
51+
52+
// Test cases for each acceptance criterion
53+
54+
// // Proper Fraction check
55+
const testProperFraction = isProperFraction(2, 3);
56+
console.assert(testProperFraction === true);
57+
58+
// // Improper Fraction check
59+
const testImproperFraction = isProperFraction(5, 2);
60+
console.assert(testImproperFraction === false);
61+
62+
// Zero Denominator check
63+
const testZeroDenominator = isProperFraction(3, 0);
64+
console.assert(testZeroDenominator === undefined);
65+
66+
// Negative Fraction check
67+
const testNegativeFraction = isProperFraction(-4, 7);
68+
console.assert(testNegativeFraction === true);
69+
70+
// Equal Numerator and Denominator check
71+
const testEqualNumeratorDenominator = isProperFraction(3, 3);
72+
console.assert(testEqualNumeratorDenominator === false);
73+

0 commit comments

Comments
 (0)