|
1 | | -// This statement loads the isProperFraction function you wrote in the implement directory. |
2 | | -// We will use the same function, but write tests for it using Jest in this file. |
3 | 1 | const isProperFraction = require("../implement/2-is-proper-fraction"); |
4 | 2 |
|
5 | | -// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. |
6 | | - |
7 | | -// Special case: numerator is zero |
8 | | -test(`should return false when denominator is zero`, () => { |
| 3 | +// Case 1: numerator/denominator is zero |
| 4 | +test(`should return false when either numerator or denominator is zero`, () => { |
| 5 | + expect(isProperFraction(0, 1)).toEqual(false); |
9 | 6 | expect(isProperFraction(1, 0)).toEqual(false); |
| 7 | + expect(isProperFraction(0, 0)).toEqual(false); |
| 8 | +}); |
| 9 | + |
| 10 | +// Case 2: numerator and denominator are positive integers and form proper fractions |
| 11 | +test(`should return true when either numerator is smaller than denominator`, () => { |
| 12 | + expect(isProperFraction(1, 2)).toEqual(true); |
| 13 | + expect(isProperFraction(1, 10)).toEqual(true); |
| 14 | + expect(isProperFraction(9, 100)).toEqual(true); |
| 15 | +}); |
| 16 | + |
| 17 | +// Case 3: numerator and denominator are negative and make proper fractions |
| 18 | +test(`should return true when absolute of numerator is smaller than absolute of denominator`, () => { |
| 19 | + expect(isProperFraction(-1, 2)).toEqual(true); |
| 20 | + expect(isProperFraction(1, -10)).toEqual(true); |
| 21 | + expect(isProperFraction(-9, -100)).toEqual(true); |
| 22 | +}); |
| 23 | + |
| 24 | +// Case 4: numerator/denominator is decimal and make proper fractions |
| 25 | +test(`should return true when decimal numerator is smaller than decimal denominator`, () => { |
| 26 | + expect(isProperFraction(0.5, 2)).toEqual(true); |
| 27 | + expect(isProperFraction(1.2, -10)).toEqual(true); |
| 28 | + expect(isProperFraction(-9, -9.5)).toEqual(true); |
| 29 | +}); |
| 30 | + |
| 31 | +// Case 5: numerator and denominator are positive integers and not proper fractions |
| 32 | +test(`should return false when numerator is greater than denominator`, () => { |
| 33 | + expect(isProperFraction(2, 1)).toEqual(false); |
| 34 | + expect(isProperFraction(10, 1)).toEqual(false); |
| 35 | + expect(isProperFraction(100, 9)).toEqual(false); |
| 36 | +}); |
| 37 | + |
| 38 | +// Case 6: numerator and denominator are negative and not proper fractions |
| 39 | +test(`should return false when absolute of numerator is greater than absolute of denominator`, () => { |
| 40 | + expect(isProperFraction(-2, 1)).toEqual(false); |
| 41 | + expect(isProperFraction(10, -1)).toEqual(false); |
| 42 | + expect(isProperFraction(-100, -9)).toEqual(false); |
| 43 | +}); |
| 44 | + |
| 45 | +// Case 7: numerator/denominator is decimal and not proper fractions |
| 46 | +test(`should return false when numerator is greater than denominator`, () => { |
| 47 | + expect(isProperFraction(2.5, 1)).toEqual(false); |
| 48 | + expect(isProperFraction(10.2, 1)).toEqual(false); |
| 49 | + expect(isProperFraction(100.5, 9.001)).toEqual(false); |
| 50 | +}); |
| 51 | + |
| 52 | +// Case 8: numerator/denominator is not numeric |
| 53 | +test(`should return false when either numerator or denominator is not numeric`, () => { |
| 54 | + expect(isProperFraction(false, 1)).toEqual(false); |
| 55 | + expect(isProperFraction(true, 1)).toEqual(false); |
| 56 | + expect(isProperFraction("10.2", 1)).toEqual(false); |
| 57 | + expect(isProperFraction("", 9.001)).toEqual(false); |
10 | 58 | }); |
0 commit comments