Skip to content

Commit 649826a

Browse files
added tests to check for proper fraction
1 parent 13d8ab7 commit 649826a

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

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

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +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) {
12-
return true;
13-
}
11+
if (typeof numerator !== "number" || typeof denominator !== "number")
12+
return "Use only numbers";
13+
14+
return Math.abs(numerator) < Math.abs(denominator);
1415
}
1516

1617
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -46,14 +47,43 @@ assertEquals(improperFraction, false);
4647
// target output: true
4748
// 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.
4849
const negativeFraction = isProperFraction(-4, 7);
49-
// ====> complete with your assertion
50+
assertEquals(negativeFraction, true);
5051

5152
// Equal Numerator and Denominator check:
5253
// Input: numerator = 3, denominator = 3
5354
// target output: false
5455
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5556
const equalFraction = isProperFraction(3, 3);
57+
assertEquals(equalFraction, false);
5658
// ====> complete with your assertion
5759

5860
// Stretch:
5961
// What other scenarios could you test for?
62+
63+
// Negative Fraction check:
64+
// Input: numerator = 4, denominator = -7
65+
// target output: true
66+
// Explanation: The fraction 4/-7 is a proper fraction because the numerator (4) is less than the absolute value of the denominator (7). The function should return true.
67+
const negativeFraction2 = isProperFraction(4, -7);
68+
assertEquals(negativeFraction2, true);
69+
70+
// Negative Fraction check:
71+
// Input: numerator = -4, denominator = -7
72+
// target output: true
73+
// Explanation: The fraction -4/-7 is a proper fraction because the absolute value of the numerator (4) is less than the absolute value of the denominator (7). The function should return true.
74+
const negativeFraction3 = isProperFraction(-4, -7);
75+
assertEquals(negativeFraction3, true);
76+
77+
//Invalid input
78+
//Input:numerator = "q", denominator = 7
79+
// target output: message
80+
//Explanation: the fraction only takes numbers
81+
const notANumber = isProperFraction("q", 7);
82+
assertEquals(notANumber, "Use only numbers");
83+
84+
//Invalid input
85+
//Input:numerator = 7, denominator = "q"
86+
// target output: message
87+
//Explanation: the fraction only takes numbers
88+
const notANumber2 = isProperFraction(7, "q");
89+
assertEquals(notANumber2, "Use only numbers");

0 commit comments

Comments
 (0)