-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy path2-is-proper-fraction.test.js
More file actions
48 lines (40 loc) · 2.13 KB
/
2-is-proper-fraction.test.js
File metadata and controls
48 lines (40 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// This statement loads the isProperFraction function you wrote in the implement directory.
// We will use the same function, but write tests for it using Jest in this file.
const isProperFraction = require("../implement/2-is-proper-fraction");
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
// Special case: denominator is zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});
// Case 2: Proper fractions
// the numerator is smaller than the denominator, so the fraction is a proper fraction
test(`should return true when numerator < denominator`, () => {
expect(isProperFraction(6, 7)).toEqual(true);
expect(isProperFraction(2, 4)).toEqual(true);
});
// Case 3: Improper fractions
// numerator is bigger than denominator, so the fraction is not proper
test("should return false when numerator is bigger than denominator", () => {
expect(isProperFraction(8, 6)).toEqual(false);
expect(isProperFraction(4, 2)).toEqual(false);
});
// Case 4: Negative numbers
// numerator or denominator is negative, but function compares absolute values
test("should return false when |numerator| < |denominator| positive numerator and negative denominator)", () => {
expect(isProperFraction(7, -3)).toEqual(false);
});
test("should return true when |numerator| < |denominator| negative numerator and positive denominator)", () => {
expect(isProperFraction(-5, 9)).toEqual(true);
});
// Case 5: Numerator equals denominator fraction equals 1, so it is not proper
test("should return false when numerator is equal to denominator", () => {
expect(isProperFraction(6, 6)).toEqual(false);
});
// Case 6: Numerator just less than denominator fraction is slightly below 1, so it is proper
test("should return true when numerator is just less than denominator", () => {
expect(isProperFraction(2, 3)).toEqual(true);
});
// Case 7: Numerator greater than denominator fraction is slightly above 1, so it is not proper
test("should return false when numerator is greater than denominator", () => {
expect(isProperFraction(6, 5)).toEqual(false);
});