|
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 | +// Proper fraction |
| 6 | +test("should return true when the denominator is greater than the numerator", () => { |
| 7 | + expect(isProperFraction(1, 2)).toBe(true); |
| 8 | +}); |
| 9 | + |
| 10 | +// Improper fraction |
| 11 | +test("should return false when the numerator is greater than the denominator", () => { |
| 12 | + expect(isProperFraction(2, 1)).toBe(false); |
| 13 | +}); |
| 14 | + |
| 15 | +// Zero numerator |
| 16 | +test("should return true when the numerator is zero", () => { |
| 17 | + expect(isProperFraction(0, 5)).toBe(true); |
| 18 | +}); |
| 19 | + |
| 20 | +// Zero denominator |
| 21 | +test("should return false when the denominator is zero", () => { |
| 22 | + expect(isProperFraction(5, 0)).toBe(false); |
| 23 | +}); |
| 24 | + |
| 25 | +// numerator equals denominator |
| 26 | +test("should return false when numerator equals denominator ", () => { |
| 27 | + expect(isProperFraction(5, 5)).toBe(false); |
| 28 | +}); |
| 29 | + |
| 30 | +// Both numerator and denominator are zero |
| 31 | +test("should return false when both the numerator and denominator are zero", () => { |
| 32 | + expect(isProperFraction(0, 0)).toBe(false); |
| 33 | +}); |
| 34 | + |
| 35 | +// Negative numbers |
| 36 | +test("should correctly identify proper fractions when given negative numbers", () => { |
| 37 | + expect(isProperFraction(-1, 2)).toBe(true); |
| 38 | + expect(isProperFraction(1, -2)).toBe(true); |
| 39 | + expect(isProperFraction(-1, -2)).toBe(true); |
| 40 | + expect(isProperFraction(-2, -1)).toBe(false); |
| 41 | +}); |
| 42 | + |
| 43 | +// Decimal numbers |
| 44 | +test("should correctly identify proper fractions when given decimal numbers", () => { |
| 45 | + expect(isProperFraction(0.5, 1)).toBe(true); |
| 46 | + expect(isProperFraction(1.5, 1)).toBe(false); |
| 47 | +}); |
5 | 48 |
|
6 | | -test("should correctly identify proper fractions", () => { |
7 | | - // Whole number fractions |
8 | | - expect(isProperFraction(1, 2)).toEqual(true); |
9 | | - expect(isProperFraction(2, 1)).toEqual(false); |
10 | | - expect(isProperFraction(5, 5)).toEqual(false); |
11 | | - |
12 | | - // Zero |
13 | | - expect(isProperFraction(0, 5)).toEqual(true); |
14 | | - expect(isProperFraction(5, 0)).toEqual(false); |
15 | | - expect(isProperFraction(0, 0)).toEqual(false); |
16 | | - |
17 | | - // Negative numbers |
18 | | - expect(isProperFraction(-1, 2)).toEqual(true); |
19 | | - expect(isProperFraction(1, -2)).toEqual(false); |
20 | | - expect(isProperFraction(-2, -1)).toEqual(true); |
21 | | - expect(isProperFraction(-1, -2)).toEqual(false); |
22 | | - |
23 | | - // Decimal numbers |
24 | | - expect(isProperFraction(0.5, 1)).toEqual(true); |
25 | | - expect(isProperFraction(1.5, 1)).toEqual(false); |
26 | | - |
27 | | - // Infinity |
28 | | - expect(isProperFraction(Infinity, 2)).toEqual(false); |
29 | | - expect(isProperFraction(2, Infinity)).toEqual(false); |
30 | | - |
31 | | - // NaN |
32 | | - expect(isProperFraction(NaN, 2)).toEqual(false); |
33 | | - expect(isProperFraction(2, NaN)).toEqual(false); |
34 | | - |
35 | | - // Large numbers |
36 | | - expect(isProperFraction(999999999, 1000000000)).toEqual(true); |
| 49 | +// Large numbers |
| 50 | +test("should correctly identify proper fractions when given very large numbers", () => { |
| 51 | + expect(isProperFraction(999999999, 1000000000)).toBe(true); |
37 | 52 | }); |
0 commit comments