Skip to content

Commit 5274005

Browse files
authored
Editing the jest code
Updated test cases for isProperFraction function to improve clarity and coverage. Added detailed descriptions for each test case.
1 parent f52bd8d commit 5274005

File tree

1 file changed

+44
-34
lines changed

1 file changed

+44
-34
lines changed
Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,65 @@
11
const isProperFraction = require("../implement/2-is-proper-fraction");
22

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)", () => {
68
expect(isProperFraction(2, 3)).toEqual(true);
79
});
810

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)", () => {
1216
expect(isProperFraction(5, 2)).toEqual(false);
1317
});
1418

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)", () => {
1824
expect(isProperFraction(-1, 2)).toEqual(true);
1925
});
2026

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)", () => {
2432
expect(isProperFraction(3, 3)).toEqual(false);
2533
});
2634

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);
3741
});
3842

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);
4349
});
4450

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);
4957
});
5058

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);
5565
});

0 commit comments

Comments
 (0)