Skip to content

Commit 5245e20

Browse files
committed
finsihed 4 cases and tests of proper fraction, start doing stretch cases
1 parent 096f9b6 commit 5245e20

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11-
if (numerator < denominator) {
11+
if (Math.abs(numerator) < Math.abs(denominator)) {
1212
return true;
13+
} else {
14+
return false;
1315
}
1416
}
1517

@@ -47,13 +49,50 @@ assertEquals(improperFraction, false);
4749
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
4850
const negativeFraction = isProperFraction(-4, 7);
4951
// ====> complete with your assertion
52+
assertEquals(negativeFraction, true);
5053

5154
// Equal Numerator and Denominator check:
5255
// Input: numerator = 3, denominator = 3
5356
// target output: false
5457
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5558
const equalFraction = isProperFraction(3, 3);
5659
// ====> complete with your assertion
60+
assertEquals(equalFraction, false);
5761

5862
// Stretch:
5963
// What other scenarios could you test for?
64+
65+
// Stretch 1: negative denominator
66+
// Input: numerator = 2, denominator = -3
67+
// target output: true
68+
// Explanation: The fraction 2/-3 is a proper fraction because the absolute value of denominator (3) is larger than the numerator (2).
69+
const negativeDenominator = isProperFraction(2, -3);
70+
assertEquals(negativeDenominator, true);
71+
72+
// Stretch 2: zero numerator
73+
// Input: numerator = 0, denominator = 5
74+
// target output: true
75+
// Explanation: The fraction 0/5 is a proper fraction because the absolute value of numerator (0) is less than the denominator (5).
76+
const zeroNumerator = isProperFraction(0, 5);
77+
assertEquals(zeroNumerator, true);
78+
// Stretch 3: zero denominator - this is mathematically undefined but we can decide how we want to handle it
79+
const zeroDenominator = isProperFraction(5, 0);
80+
assertEquals(zeroDenominator, false);
81+
// Stretch 4: both zero
82+
const bothZero = isProperFraction(0, 0);
83+
assertEquals(bothZero, false);
84+
// Stretch 5: negative numerator and denominator
85+
const negativeNumeratorAndDenominator = isProperFraction(-3, -5);
86+
assertEquals(negativeNumeratorAndDenominator, true);
87+
// Stretch 6: improper negative numerator and denominator
88+
const properNegativeNumeratorAndDenominator = isProperFraction(-3, -2);
89+
assertEquals(properNegativeNumeratorAndDenominator, false);
90+
// Stretch 7: decimal values
91+
const decimalValues = isProperFraction(2.5, 3.5);
92+
assertEquals(decimalValues, true);
93+
// Stretch 8: improper decimal values
94+
const improperDecimalValues = isProperFraction(3.5, 2.5);
95+
assertEquals(improperDecimalValues, false);
96+
// Stretch 9: invalid inputs (non-numeric values)
97+
const invalidInputs = isProperFraction("a", 2);
98+
assertEquals(invalidInputs, false);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@ test("should return true for a proper fraction", () => {
77
});
88

99
// Case 2: Identify Improper Fractions:
10+
test("should return false for an improper fraction", () => {
11+
expect(isProperFraction(5, 2)).toEqual(false);
12+
});
1013

1114
// Case 3: Identify Negative Fractions:
15+
test("should return true for a negative proper fraction", () => {
16+
expect(isProperFraction(-4, 7)).toEqual(true);
17+
});
1218

1319
// Case 4: Identify Equal Numerator and Denominator:
20+
test("should return false when numerator equals denominator", () => {
21+
expect(isProperFraction(3, 3)).toEqual(false);
22+
});
23+
24+
// Stretch 1: Identify Negative Denominator:
25+
test("should return true when the absolute value of a negative denominator is larger than numerator", () => {
26+
expect(isProperFraction(2, -3)).toEqual(true);
27+
});

0 commit comments

Comments
 (0)