Skip to content

Commit 5a195ff

Browse files
committed
rewrite proper fraction test with jest(exercise 2)
1 parent dec4845 commit 5a195ff

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,37 @@
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-
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
5+
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.]
66

7-
// Special case: numerator is zero
7+
//case 1: proper function
8+
9+
test("should return true when |numerator| < |denominator|", () => {
10+
expect(isProperFraction(-3, 4)).toEqual(true);
11+
expect(isProperFraction(3, -4)).toEqual(true);
12+
expect(isProperFraction(1, 2)).toEqual(true);
13+
});
14+
15+
//case 2: result is a whole number
16+
test("should return false when the result is a whole number", () => {
17+
expect(isProperFraction(2, 2)).toEqual(false);
18+
expect(isProperFraction(-2 - 2)).toEqual(false);
19+
expect(isProperFraction(2, -2)).toEqual(false);
20+
});
21+
22+
//case 3: numerator or denominator is a decimal
23+
test("should return false if the numerator or denominator is a decimal", () => {
24+
expect(isProperFraction(1.5, 2)).toEqual(false);
25+
expect(isProperFraction(1, 1.5)).toEqual(false);
26+
});
27+
28+
//case 4: numerator or denominator is negative
29+
test("should return true even if the numerator or denominator is negative", () => {
30+
expect(isProperFraction(-4, 5)).toEqual(true);
31+
expect(isProperFraction(4, -5)).toEqual(true);
32+
});
33+
34+
// Special case: numerator or denominator is zero
835
test(`should return false when denominator is zero`, () => {
936
expect(isProperFraction(1, 0)).toEqual(false);
37+
expect(isProperFraction(0, 1)).toEqual(false);
1038
});

0 commit comments

Comments
 (0)