Skip to content

Commit cfecb6c

Browse files
committed
Add edge case test cases for isProperFraction: floats, large numbers, negative zero, and 2/4 fraction
1 parent 47809af commit cfecb6c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,54 @@ assertEquals(bothNegative, true);
108108
// Explanation: Division by zero is invalid; fraction cannot be proper.
109109
const zeroDenominator = isProperFraction(1, 0);
110110
assertEquals(zeroDenominator, false);
111+
112+
113+
// Float Numerator check:
114+
// Input: numerator = 2.5, denominator = 3
115+
// Target output: false
116+
// Explanation: Fractions with a non-integer numerator are not considered proper fractions.
117+
const floatNumerator = isProperFraction(2.5, 3);
118+
assertEquals(floatNumerator, false);
119+
120+
// Float Denominator check:
121+
// Input: numerator = 2, denominator = 3.5
122+
// Target output: false
123+
// Explanation: Fractions with a non-integer denominator are invalid and should not be considered proper fractions.
124+
const floatDenominator = isProperFraction(2, 3.5);
125+
assertEquals(floatDenominator, false);
126+
127+
// Both Numerator and Denominator as Floats check:
128+
// Input: numerator = 1.5, denominator = 2.5
129+
// Target output: false
130+
// Explanation: Fractions with both numerator and denominator as floats are invalid and should not be considered proper fractions.
131+
const floatBoth = isProperFraction(1.5, 2.5);
132+
assertEquals(floatBoth, false);
133+
134+
// Large Number check:
135+
// Input: numerator = 99, denominator = 100
136+
// Target output: true
137+
// Explanation: 99/100 is a valid proper fraction, even with large values.
138+
const largeNumbers = isProperFraction(99, 100);
139+
assertEquals(largeNumbers, true);
140+
141+
// Negative Zero check:
142+
// Input: numerator = -0, denominator = 5
143+
// Target output: false
144+
// Explanation: Negative zero is equivalent to zero; not a proper fraction.
145+
const negativeZero = isProperFraction(-0, 5);
146+
assertEquals(negativeZero, false);
147+
148+
// Denominator less than -1 check:
149+
// Input: numerator = 1, denominator = -1
150+
// Target output: false
151+
// Explanation: Equal magnitude makes it improper, regardless of sign.
152+
const negOneDenominator = isProperFraction(1, -1);
153+
assertEquals(negOneDenominator, false);
154+
155+
// Proper Fraction check:
156+
// Input: numerator = 2, denominator = 4
157+
// Target output: true
158+
// Explanation: 2/4 is a proper fraction because the absolute value of the numerator is less than the absolute value of the denominator.
159+
const twoOverFour = isProperFraction(2, 4);
160+
assertEquals(twoOverFour, true);
161+

0 commit comments

Comments
 (0)