|
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 | + |
5 | 6 | // TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. |
| 7 | +const isProperFraction = require("../implement/2-is-proper-fraction"); |
| 8 | + |
| 9 | +// Case 1: Proper fractions |
| 10 | +test(`should return true for proper fractions`, () => { |
| 11 | + expect(isProperFraction(1, 2)).toEqual(true); |
| 12 | + expect(isProperFraction(-1, 2)).toEqual(true); |
| 13 | + expect(isProperFraction(-1, -2)).toEqual(true); |
| 14 | +}); |
| 15 | + |
| 16 | +// Case 2: Improper fractions |
| 17 | +test(`should return false for improper fractions`, () => { |
| 18 | + expect(isProperFraction(2, 1)).toEqual(false); |
| 19 | + expect(isProperFraction(3, 2)).toEqual(false); |
| 20 | + expect(isProperFraction(-3, 2)).toEqual(false); |
| 21 | + expect(isProperFraction(3, -2)).toEqual(false); |
| 22 | +}); |
| 23 | + |
| 24 | +// Case 3: Zero numerator |
| 25 | +test(`should return true when numerator is zero`, () => { |
| 26 | + expect(isProperFraction(0, 1)).toEqual(true); |
| 27 | + expect(isProperFraction(0, -1)).toEqual(true); |
| 28 | +}); |
| 29 | + |
| 30 | +// Case 4: Zero denominator |
| 31 | +test(`should return false when denominator is zero`, () => { |
| 32 | + expect(isProperFraction(1, 0)).toEqual(false); |
| 33 | + expect(isProperFraction(-1, 0)).toEqual(false); |
| 34 | + expect(isProperFraction(0, 0)).toEqual(false); |
| 35 | +}); |
| 36 | + |
| 37 | +// Case 5: Negative fractions |
| 38 | +test(`should return false for negative fractions with positive denominator`, () => { |
| 39 | + expect(isProperFraction(-1, 2)).toEqual(true); |
| 40 | +}); |
| 41 | + |
| 42 | +test(`should return false for negative fractions with negative denominator`, () => { |
| 43 | + expect(isProperFraction(-1, -2)).toEqual(true); |
| 44 | +}); |
| 45 | + |
| 46 | +// Case 6: Invalid fractions (denominator is zero) |
| 47 | +test(`should return false when denominator is zero`, () => { |
| 48 | + expect(isProperFraction(1, 0)).toEqual(false); |
| 49 | + expect(isProperFraction(-1, 0)).toEqual(false); |
| 50 | + expect(isProperFraction(0, 0)).toEqual(false); |
| 51 | +}); |
| 52 | + |
| 53 | +// Case 7: Special case: numerator is zero |
| 54 | +test(`should return true when numerator is zero`, () => { |
| 55 | + expect(isProperFraction(0, 1)).toEqual(true); |
| 56 | + expect(isProperFraction(0, -1)).toEqual(true); |
| 57 | +}); |
| 58 | + |
6 | 59 |
|
7 | 60 | // Special case: numerator is zero |
8 | 61 | test(`should return false when denominator is zero`, () => { |
9 | 62 | expect(isProperFraction(1, 0)).toEqual(false); |
10 | 63 | }); |
| 64 | + |
0 commit comments