Skip to content

Commit 0166d84

Browse files
committed
Proper fractions checked to return true or false for a range of inputs
1 parent 71394a8 commit 0166d84

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed
Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
// Implement a function isProperFraction
2-
// Write assertions for your function to check it works in different cases
3-
// Terms:
4-
// Fractions: https://www.bbc.co.uk/bitesize/topics/zt9n6g8/articles/zjxpp4j
5-
// Written here like this: 1/2 == Numerator/Denominator
6-
// the first test and first case is written for you
7-
// complete the rest of the tests and cases
8-
// write one test at a time, and make it pass, build your solution up methodically
91

102
function isProperFraction(numerator, denominator) {
113
if (numerator < denominator) {
124
return true;
135
}
6+
else {
7+
return false;
8+
}
149
}
1510

1611
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -25,35 +20,55 @@ function assertEquals(actualOutput, targetOutput) {
2520
);
2621
}
2722

28-
// Acceptance criteria:
29-
23+
// Case 1
3024
// Proper Fraction check:
3125
// Input: numerator = 2, denominator = 3
3226
// target output: true
3327
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
3428
const properFraction = isProperFraction(2, 3);
3529
assertEquals(properFraction, true);
3630

31+
//Case 2
3732
// Improper Fraction check:
3833
// Input: numerator = 5, denominator = 2
3934
// target output: false
4035
// 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.
4136
const improperFraction = isProperFraction(5, 2);
4237
assertEquals(improperFraction, false);
4338

39+
//Case 3
4440
// Negative Fraction check:
4541
// Input: numerator = -4, denominator = 7
4642
// target output: true
4743
// 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.
4844
const negativeFraction = isProperFraction(-4, 7);
49-
// ====> complete with your assertion
45+
assertEquals(negativeFraction, true);
46+
//The function already works for negative numerators, so no changes are needed.
5047

48+
//case 4
5149
// Equal Numerator and Denominator check:
5250
// Input: numerator = 3, denominator = 3
5351
// target output: false
5452
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5553
const equalFraction = isProperFraction(3, 3);
56-
// ====> complete with your assertion
54+
assertEquals(equalFraction, false);
5755

5856
// Stretch:
5957
// What other scenarios could you test for?
58+
// Case 5
59+
//Negative denominator
60+
const negativeDenominator = isProperFraction(4, -5);
61+
assertEquals(negativeDenominator, true);
62+
// Explanation: The fraction 4/-5 is a proper fraction because the absolute value of the numerator (4) is less than the absolute value of the denominator (5). The function should return true.
63+
64+
// Case 6
65+
//Both numerator and denominator negative
66+
const bothNegative = isProperFraction(-3, -4);
67+
assertEquals(bothNegative, true);
68+
// Explanation: The fraction -3/-4 is a proper fraction because the absolute value of the numerator (3) is less than the absolute value of the denominator (4). The function should return true.
69+
70+
// Case 7
71+
//Zero numerator
72+
const zeroNumerator = isProperFraction(0, 5);
73+
assertEquals(zeroNumerator, true);
74+
// Explanation: The fraction 0/5 is a proper fraction because the numerator (0) is less than the denominator (5). The function should return true.

0 commit comments

Comments
 (0)