|
1 | 1 | import { isProperFraction } from "../implement/2-is-proper-fraction.js"; |
2 | 2 |
|
3 | | -// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. |
| 3 | +// Special case: numerator is zero (0/1 = 0, which is a proper fraction) |
| 4 | +test(`should return true when numerator is zero`, () => { |
| 5 | + expect(isProperFraction(0, 1)).toEqual(true); |
| 6 | +}); |
4 | 7 |
|
5 | | -// Special case: numerator is zero |
| 8 | +// Special case: denominator is zero (not a valid fraction) |
6 | 9 | test(`should return false when denominator is zero`, () => { |
7 | 10 | expect(isProperFraction(1, 0)).toEqual(false); |
8 | 11 | }); |
| 12 | + |
| 13 | +// Both positive |
| 14 | +test(`should return false when numerator is greater than denominator`, () => { |
| 15 | + expect(isProperFraction(7, 5)).toEqual(false); |
| 16 | +}); |
| 17 | +test(`should return true when numerator is smaller than denominator`, () => { |
| 18 | + expect(isProperFraction(1, 3)).toEqual(true); |
| 19 | +}); |
| 20 | +test(`should return false when numerator equals denominator`, () => { |
| 21 | + expect(isProperFraction(2, 2)).toEqual(false); |
| 22 | +}); |
| 23 | + |
| 24 | +// Both negative |
| 25 | +test(`should return false when both negative and |numerator| is greater`, () => { |
| 26 | + expect(isProperFraction(-7, -5)).toEqual(false); // was true |
| 27 | +}); |
| 28 | +test(`should return true when both negative and |numerator| is smaller`, () => { |
| 29 | + expect(isProperFraction(-5, -7)).toEqual(true); // was false |
| 30 | +}); |
| 31 | +test(`should return false when both negative and |numerator| is slightly greater`, () => { |
| 32 | + expect(isProperFraction(-10, -9)).toEqual(false); // was true |
| 33 | +}); |
| 34 | +test(`should return false when both negative and equal`, () => { |
| 35 | + expect(isProperFraction(-5, -5)).toEqual(false); |
| 36 | +}); |
| 37 | + |
| 38 | +// Positive numerator, negative denominator |
| 39 | +test(`should return false when numerator is positive, denominator negative, |numerator| greater`, () => { |
| 40 | + expect(isProperFraction(7, -5)).toEqual(false); |
| 41 | +}); |
| 42 | +test(`should return false when numerator is positive, denominator negative, equal absolute values`, () => { |
| 43 | + expect(isProperFraction(7, -7)).toEqual(false); |
| 44 | +}); |
| 45 | + |
| 46 | +// Negative numerator, positive denominator |
| 47 | +test(`should return false when numerator is negative, denominator positive, |numerator| greater`, () => { |
| 48 | + expect(isProperFraction(-7, 5)).toEqual(false); // was true |
| 49 | +}); |
| 50 | +test(`should return false when numerator is negative, denominator positive, equal absolute values`, () => { |
| 51 | + expect(isProperFraction(-7, 7)).toEqual(false); |
| 52 | +}); |
0 commit comments