-
-
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
36 lines (32 loc) · 2.37 KB
/
2-is-proper-fraction.test.js
File metadata and controls
36 lines (32 loc) · 2.37 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
// 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 (undefined)
test(`should return false when denominator is zero`, () => {
expect(isProperFraction(1, 0)).toEqual(false);
// Special case: both numerator and denominator are zeros (undefined)
expect(isProperFraction(0, 0)).toEqual(false);
});
// Special case: numerator is zero (proper fraction)
test(`should return true for proper fraction`, () => {
expect(isProperFraction(0, 1)).toEqual(true);
// case: both values are positive and the value of the numerater is less than the value of the denominater (proper fraction)
expect(isProperFraction(1, 2)).toEqual(true);
// case: the value of the numerater is negative and its absolute value is less than the value of the denominater (roper fraction)
expect(isProperFraction(-1, 2)).toEqual(true);
// case: the value of the denominator is negative and its absolute value is greater than the value of the numerator (proper fraction)
expect(isProperFraction(1, -2)).toEqual(true);
// case: both values of the numerator and denominator are negative and the absolute value of the numerator is less than the absolute value of the denominator (proper fraction)
expect(isProperFraction(-1, -2)).toEqual(true);
});
// case: both values are positive and the value of the denominater is less than the value of the numerater (improper fraction)
test(`should return false for improper fraction`, () => {
expect(isProperFraction(2, 1)).toEqual(false);
// case: the value of the numerater is negative and its absolute value is greater than the value of the denominater (improper fraction)
expect(isProperFraction(-2, 1)).toEqual(false);
// case: both values of the numerator and denominator are negative and the absolute value of the numerator is greater than the absolute value of the denominator (improper fraction)
expect(isProperFraction(-2, -1)).toEqual(false);
// case: the value of the denominator is negative and its absolute value is less than the value of the numerator (improper fraction)
expect(isProperFraction(2, -1)).toEqual(false);
});