Skip to content

Commit 991832e

Browse files
authored
Enhance Jest tests for isProperFraction function
Expanded test cases for isProperFraction function to include various scenarios such as negative fractions, zero numerator, negative denominator, and large numbers.
1 parent a3c8fc8 commit 991832e

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed
Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,55 @@
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.
31
const isProperFraction = require("../implement/2-is-proper-fraction");
42

3+
// Case 1: Proper fraction
4+
// When numerator < denominator, it should return true.
55
test("should return true for a proper fraction", () => {
66
expect(isProperFraction(2, 3)).toEqual(true);
7-
87
});
98

10-
// Case 2: Identify Improper Fractions:
9+
// Case 2: Improper fraction
10+
// When numerator > denominator, it should return false.
1111
test("should return false for an improper fraction", () => {
1212
expect(isProperFraction(5, 2)).toEqual(false);
1313
});
1414

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", () => {
1718
expect(isProperFraction(-1, 2)).toEqual(true);
1819
});
1920

20-
// Case 4: Identify Equal Numerator and Denominator:
21+
// Case 4: Equal numerator and denominator
22+
// When numerator === denominator, it should return false.
2123
test("should return false for equal numerator and denominator", () => {
2224
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);
2655
});

0 commit comments

Comments
 (0)