-
-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy path2-is-proper-fraction.test.js
More file actions
34 lines (31 loc) · 1.47 KB
/
2-is-proper-fraction.test.js
File metadata and controls
34 lines (31 loc) · 1.47 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
// 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: numerator is zero
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
});
// Case 1: Proper fractions
test(`should return true for proper fractions`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(-1, 2)).toEqual(true);
expect(isProperFraction(1, -2)).toEqual(true);
expect(isProperFraction(-1, -2)).toEqual(true);
expect(isProperFraction(0, 2)).toEqual(true);
});
// Case 2: Improper fractions
test(`should return false for improper fractions`, () => {
expect(isProperFraction(2, 1)).toEqual(false);
expect(isProperFraction(-2, 1)).toEqual(false);
expect(isProperFraction(2, -1)).toEqual(false);
expect(isProperFraction(-2, -1)).toEqual(false);
expect(isProperFraction(2, 2)).toEqual(false);
expect(isProperFraction(-2, -2)).toEqual(false);
});
// Case 3: Invalid fractions (denominator is zero)
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
expect(isProperFraction(-1, 0)).toEqual(false);
expect(isProperFraction(0, 0)).toEqual(false);
});