Skip to content

Commit cd3e753

Browse files
committed
Add comprehensive Jest tests for isProperFraction function covering various cases
1 parent e0d2999 commit cd3e753

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,63 @@
22
// We will use the same function, but write tests for it using Jest in this file.
33
const isProperFraction = require("../implement/2-is-proper-fraction");
44

5+
56
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
7+
const isProperFraction = require("../implement/2-is-proper-fraction");
8+
9+
// Case 1: Proper fractions
10+
test(`should return true for proper fractions`, () => {
11+
expect(isProperFraction(1, 2)).toEqual(true);
12+
expect(isProperFraction(-1, 2)).toEqual(true);
13+
expect(isProperFraction(-1, -2)).toEqual(true);
14+
});
15+
16+
// Case 2: Improper fractions
17+
test(`should return false for improper fractions`, () => {
18+
expect(isProperFraction(2, 1)).toEqual(false);
19+
expect(isProperFraction(3, 2)).toEqual(false);
20+
expect(isProperFraction(-3, 2)).toEqual(false);
21+
expect(isProperFraction(3, -2)).toEqual(false);
22+
});
23+
24+
// Case 3: Zero numerator
25+
test(`should return true when numerator is zero`, () => {
26+
expect(isProperFraction(0, 1)).toEqual(true);
27+
expect(isProperFraction(0, -1)).toEqual(true);
28+
});
29+
30+
// Case 4: Zero denominator
31+
test(`should return false when denominator is zero`, () => {
32+
expect(isProperFraction(1, 0)).toEqual(false);
33+
expect(isProperFraction(-1, 0)).toEqual(false);
34+
expect(isProperFraction(0, 0)).toEqual(false);
35+
});
36+
37+
// Case 5: Negative fractions
38+
test(`should return false for negative fractions with positive denominator`, () => {
39+
expect(isProperFraction(-1, 2)).toEqual(true);
40+
});
41+
42+
test(`should return false for negative fractions with negative denominator`, () => {
43+
expect(isProperFraction(-1, -2)).toEqual(true);
44+
});
45+
46+
// Case 6: Invalid fractions (denominator is zero)
47+
test(`should return false when denominator is zero`, () => {
48+
expect(isProperFraction(1, 0)).toEqual(false);
49+
expect(isProperFraction(-1, 0)).toEqual(false);
50+
expect(isProperFraction(0, 0)).toEqual(false);
51+
});
52+
53+
// Case 7: Special case: numerator is zero
54+
test(`should return true when numerator is zero`, () => {
55+
expect(isProperFraction(0, 1)).toEqual(true);
56+
expect(isProperFraction(0, -1)).toEqual(true);
57+
});
58+
659

760
// Special case: numerator is zero
861
test(`should return false when denominator is zero`, () => {
962
expect(isProperFraction(1, 0)).toEqual(false);
1063
});
64+

0 commit comments

Comments
 (0)