You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 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
9
1
10
2
functionisProperFraction(numerator,denominator){
11
3
if(numerator<denominator){
12
4
returntrue;
13
5
}
6
+
else{
7
+
returnfalse;
8
+
}
14
9
}
15
10
16
11
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -25,35 +20,55 @@ function assertEquals(actualOutput, targetOutput) {
25
20
);
26
21
}
27
22
28
-
// Acceptance criteria:
29
-
23
+
// Case 1
30
24
// Proper Fraction check:
31
25
// Input: numerator = 2, denominator = 3
32
26
// target output: true
33
27
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
34
28
constproperFraction=isProperFraction(2,3);
35
29
assertEquals(properFraction,true);
36
30
31
+
//Case 2
37
32
// Improper Fraction check:
38
33
// Input: numerator = 5, denominator = 2
39
34
// target output: false
40
35
// 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
36
constimproperFraction=isProperFraction(5,2);
42
37
assertEquals(improperFraction,false);
43
38
39
+
//Case 3
44
40
// Negative Fraction check:
45
41
// Input: numerator = -4, denominator = 7
46
42
// target output: true
47
43
// 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
44
constnegativeFraction=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.
50
47
48
+
//case 4
51
49
// Equal Numerator and Denominator check:
52
50
// Input: numerator = 3, denominator = 3
53
51
// target output: false
54
52
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
55
53
constequalFraction=isProperFraction(3,3);
56
-
// ====> complete with your assertion
54
+
assertEquals(equalFraction,false);
57
55
58
56
// Stretch:
59
57
// What other scenarios could you test for?
58
+
// Case 5
59
+
//Negative denominator
60
+
constnegativeDenominator=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
+
constbothNegative=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
+
constzeroNumerator=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