|
1 | 1 | const isProperFraction = require("../implement/2-is-proper-fraction"); |
2 | 2 |
|
3 | | -// Case 1: Proper fraction |
4 | | -// When numerator < denominator, it should return true. |
5 | | -test("should return true for a proper fraction", () => { |
| 3 | +// Case 1: Proper Fraction |
| 4 | +// Given a numerator smaller than denominator (2/3), |
| 5 | +// When the function is called, |
| 6 | +// Then it should return true because it's a proper fraction. |
| 7 | +test("should return true for a proper fraction (2/3)", () => { |
6 | 8 | expect(isProperFraction(2, 3)).toEqual(true); |
7 | 9 | }); |
8 | 10 |
|
9 | | -// Case 2: Improper fraction |
10 | | -// When numerator > denominator, it should return false. |
11 | | -test("should return false for an improper fraction", () => { |
| 11 | +// Case 2: Improper Fraction |
| 12 | +// Given a numerator greater than denominator (5/2), |
| 13 | +// When the function is called, |
| 14 | +// Then it should return false because it's an improper fraction. |
| 15 | +test("should return false for an improper fraction (5/2)", () => { |
12 | 16 | expect(isProperFraction(5, 2)).toEqual(false); |
13 | 17 | }); |
14 | 18 |
|
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", () => { |
| 19 | +// Case 3: Negative Proper Fraction |
| 20 | +// Given a negative proper fraction (-1/2), |
| 21 | +// When the function is called, |
| 22 | +// Then it should return true because the value is between -1 and 1. |
| 23 | +test("should return true for a negative proper fraction (-1/2)", () => { |
18 | 24 | expect(isProperFraction(-1, 2)).toEqual(true); |
19 | 25 | }); |
20 | 26 |
|
21 | | -// Case 4: Equal numerator and denominator |
22 | | -// When numerator === denominator, it should return false. |
23 | | -test("should return false for equal numerator and denominator", () => { |
| 27 | +// Case 4: Equal Numerator and Denominator |
| 28 | +// Given a numerator equal to denominator (3/3), |
| 29 | +// When the function is called, |
| 30 | +// Then it should return false because it's equal to 1 (not proper). |
| 31 | +test("should return false for equal numerator and denominator (3/3)", () => { |
24 | 32 | expect(isProperFraction(3, 3)).toEqual(false); |
25 | 33 | }); |
26 | 34 |
|
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); |
| 35 | +// Case 5: Negative Improper Fraction |
| 36 | +// Given a negative improper fraction (-4/3), |
| 37 | +// When the function is called, |
| 38 | +// Then it should return false because the absolute value is greater than 1. |
| 39 | +test("should return false for a negative improper fraction (-4/3)", () => { |
| 40 | + expect(isProperFraction(-4, 3)).toEqual(false); |
37 | 41 | }); |
38 | 42 |
|
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 | +// Case 6: Both Negative (Proper Fraction) |
| 44 | +// Given both numerator and denominator negative (-2/-3), |
| 45 | +// When the function is called, |
| 46 | +// Then it should return true because the value is positive and less than 1. |
| 47 | +test("should return true for both negative proper fraction (-2/-3)", () => { |
| 48 | + expect(isProperFraction(-2, -3)).toEqual(true); |
43 | 49 | }); |
44 | 50 |
|
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); |
| 51 | +// Case 7: Zero Numerator |
| 52 | +// Given a numerator of 0 (0/5), |
| 53 | +// When the function is called, |
| 54 | +// Then it should return true because 0 is less than any nonzero denominator. |
| 55 | +test("should return true for zero numerator (0/5)", () => { |
| 56 | + expect(isProperFraction(0, 5)).toEqual(true); |
49 | 57 | }); |
50 | 58 |
|
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); |
| 59 | +// Case 8: Zero Denominator |
| 60 | +// Given a denominator of 0 (5/0), |
| 61 | +// When the function is called, |
| 62 | +// Then it should return false because division by zero is undefined. |
| 63 | +test("should return false for zero denominator (5/0)", () => { |
| 64 | + expect(isProperFraction(5, 0)).toEqual(false); |
55 | 65 | }); |
0 commit comments