|
2 | 2 | // We will use the same function, but write tests for it using Jest in this file. |
3 | 3 | const isProperFraction = require("../implement/2-is-proper-fraction"); |
4 | 4 |
|
5 | | -// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. |
| 5 | +// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.] |
6 | 6 |
|
7 | | -// Special case: numerator is zero |
| 7 | +//case 1: proper function |
| 8 | + |
| 9 | +test("should return true when |numerator| < |denominator|", () => { |
| 10 | + expect(isProperFraction(-3, 4)).toEqual(true); |
| 11 | + expect(isProperFraction(3, -4)).toEqual(true); |
| 12 | + expect(isProperFraction(1, 2)).toEqual(true); |
| 13 | +}); |
| 14 | + |
| 15 | +//case 2: result is a whole number |
| 16 | +test("should return false when the result is a whole number", () => { |
| 17 | + expect(isProperFraction(2, 2)).toEqual(false); |
| 18 | + expect(isProperFraction(-2 - 2)).toEqual(false); |
| 19 | + expect(isProperFraction(2, -2)).toEqual(false); |
| 20 | +}); |
| 21 | + |
| 22 | +//case 3: numerator or denominator is a decimal |
| 23 | +test("should return false if the numerator or denominator is a decimal", () => { |
| 24 | + expect(isProperFraction(1.5, 2)).toEqual(false); |
| 25 | + expect(isProperFraction(1, 1.5)).toEqual(false); |
| 26 | +}); |
| 27 | + |
| 28 | +//case 4: numerator or denominator is negative |
| 29 | +test("should return true even if the numerator or denominator is negative", () => { |
| 30 | + expect(isProperFraction(-4, 5)).toEqual(true); |
| 31 | + expect(isProperFraction(4, -5)).toEqual(true); |
| 32 | +}); |
| 33 | + |
| 34 | +// Special case: numerator or denominator is zero |
8 | 35 | test(`should return false when denominator is zero`, () => { |
9 | 36 | expect(isProperFraction(1, 0)).toEqual(false); |
| 37 | + expect(isProperFraction(0, 1)).toEqual(false); |
10 | 38 | }); |
0 commit comments