|
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 |
|
| 3 | +// Case 1: Proper fraction |
| 4 | +// When numerator < denominator, it should return true. |
5 | 5 | test("should return true for a proper fraction", () => { |
6 | 6 | expect(isProperFraction(2, 3)).toEqual(true); |
7 | | - |
8 | 7 | }); |
9 | 8 |
|
10 | | -// Case 2: Identify Improper Fractions: |
| 9 | +// Case 2: Improper fraction |
| 10 | +// When numerator > denominator, it should return false. |
11 | 11 | test("should return false for an improper fraction", () => { |
12 | 12 | expect(isProperFraction(5, 2)).toEqual(false); |
13 | 13 | }); |
14 | 14 |
|
15 | | -// Case 3: Identify Negative Fractions: |
16 | | -test("should return false for a negative fraction", () => { |
| 15 | +// Case 3: Negative proper fraction |
| 16 | +// When numerator is negative but |numerator| < |denominator|, it should return true. |
| 17 | +test("should return true for a negative proper fraction", () => { |
17 | 18 | expect(isProperFraction(-1, 2)).toEqual(true); |
18 | 19 | }); |
19 | 20 |
|
20 | | -// Case 4: Identify Equal Numerator and Denominator: |
| 21 | +// Case 4: Equal numerator and denominator |
| 22 | +// When numerator === denominator, it should return false. |
21 | 23 | test("should return false for equal numerator and denominator", () => { |
22 | 24 | expect(isProperFraction(3, 3)).toEqual(false); |
23 | | - expect(isProperFraction(-3, 3)).toEqual(false); |
24 | | - expect(isProperFraction(3, -3)).toEqual(false); |
25 | | - expect(isProperFraction(-3, -3)).toEqual(false); |
| 25 | +}); |
| 26 | + |
| 27 | +// Case 5: Zero numerator |
| 28 | +// 0 divided by any non-zero denominator is a proper fraction. |
| 29 | +test("should return true for zero numerator", () => { |
| 30 | + expect(isProperFraction(0, 5)).toEqual(true); |
| 31 | +}); |
| 32 | + |
| 33 | +// Case 6: Negative denominator |
| 34 | +// When denominator is negative, the fraction is still valid, so check absolute values. |
| 35 | +test("should return true when denominator is negative but |numerator| < |denominator|", () => { |
| 36 | + expect(isProperFraction(2, -3)).toEqual(true); |
| 37 | +}); |
| 38 | + |
| 39 | +// Case 7: Denominator is zero |
| 40 | +// Division by zero is undefined, should return false. |
| 41 | +test("should return false when denominator is zero", () => { |
| 42 | + expect(isProperFraction(3, 0)).toEqual(false); |
| 43 | +}); |
| 44 | + |
| 45 | +// Case 8: Both numerator and denominator are negative but |numerator| < |denominator| |
| 46 | +// Negative/negative cancels out, still a proper fraction. |
| 47 | +test("should return true when both numerator and denominator are negative and |numerator| < |denominator|", () => { |
| 48 | + expect(isProperFraction(-3, -7)).toEqual(true); |
| 49 | +}); |
| 50 | + |
| 51 | +// Case 9: Large numbers |
| 52 | +// It should handle large numbers correctly. |
| 53 | +test("should return true for large proper fractions", () => { |
| 54 | + expect(isProperFraction(999, 1000)).toEqual(true); |
26 | 55 | }); |
0 commit comments