Skip to content

Commit 519a564

Browse files
committed
feat(sprint-3): implement isProperFraction function
1 parent 14e1d56 commit 519a564

File tree

1 file changed

+14
-38
lines changed

1 file changed

+14
-38
lines changed

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

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,28 @@
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) {
12-
return true;
13-
}
11+
return Math.abs(numerator) < denominator;
1412
}
1513

16-
// The line below allows us to load the isProperFraction function into tests in other files.
17-
// This will be useful in the "rewrite tests with jest" step.
1814
module.exports = isProperFraction;
1915

20-
// here's our helper again
2116
function assertEquals(actualOutput, targetOutput) {
2217
console.assert(
2318
actualOutput === targetOutput,
2419
`Expected ${actualOutput} to equal ${targetOutput}`
2520
);
2621
}
2722

28-
// Acceptance criteria:
29-
30-
// Proper Fraction check:
31-
// Input: numerator = 2, denominator = 3
32-
// target output: true
33-
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
34-
const properFraction = isProperFraction(2, 3);
35-
assertEquals(properFraction, true);
36-
37-
// Improper Fraction check:
38-
// Input: numerator = 5, denominator = 2
39-
// target output: false
40-
// Explanation: The fraction 5/2 is an improper fraction, where the numerator is greater than or equal to the denominator. The function should return false.
41-
const improperFraction = isProperFraction(5, 2);
42-
assertEquals(improperFraction, false);
43-
44-
// Negative Fraction check:
45-
// Input: numerator = -4, denominator = 7
46-
// target output: true
47-
// 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.
48-
const negativeFraction = isProperFraction(-4, 7);
49-
// ====> complete with your assertion
50-
51-
// Equal Numerator and Denominator check:
52-
// Input: numerator = 3, denominator = 3
53-
// target output: false
54-
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
55-
const equalFraction = isProperFraction(3, 3);
56-
// ====> complete with your assertion
57-
58-
// Stretch:
59-
// What other scenarios could you test for?
23+
// Proper Fraction: 2/3 → true
24+
assertEquals(isProperFraction(2, 3), true);
25+
26+
// Improper Fraction: 5/2 → false
27+
assertEquals(isProperFraction(5, 2), false);
28+
29+
// Negative Fraction: -4/7 → true (absolute value < denominator)
30+
assertEquals(isProperFraction(-4, 7), true);
31+
32+
// Equal Numerator and Denominator: 3/3 → false
33+
assertEquals(isProperFraction(3, 3), false);
34+
35+
console.log("✅ All tests passed!");

0 commit comments

Comments
 (0)