Skip to content

Commit f8727eb

Browse files
committed
proper fractions jest tests
1 parent d387eda commit f8727eb

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// execute the code to ensure all tests pass.
1212

1313
function isProperFraction(numerator, denominator) {
14+
if (denominator === 0) return false;
1415
return numerator < denominator ? true : false;
1516
}
1617

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,33 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
77
// Special case: numerator is zero
88
test(`should return false when denominator is zero`, () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
10+
expect(isProperFraction(0, 0)).toEqual(false);
11+
expect(isProperFraction(-1, 0)).toEqual(false);
12+
});
13+
14+
test(`should return true when numerator and denominator both positive and numerator < denominator`, () => {
15+
expect(isProperFraction(1, 2)).toEqual(true);
16+
expect(isProperFraction(4, 5)).toEqual(true);
17+
expect(isProperFraction(2, 3)).toEqual(true);
18+
});
19+
20+
test(`should return true when numerator and denominator both negative and numerator < denominator`, () => {
21+
expect(isProperFraction(-3, -2)).toEqual(true);
22+
});
23+
24+
test(`should return true when numerator is negative and numerator < denominator`, () => {
25+
expect(isProperFraction(-3, 2)).toEqual(true);
26+
});
27+
28+
test(`should return false when numerator > denominator`, () => {
29+
expect(isProperFraction(2, 1)).toEqual(false);
30+
});
31+
32+
test(`should return false when numerator > denominator, negative nums`, () => {
33+
expect(isProperFraction(-1, -2)).toEqual(false);
34+
});
35+
36+
test(`should return false when numerator == denominator`, () => {
37+
expect(isProperFraction(-2, -2)).toEqual(false);
38+
expect(isProperFraction(2, 2)).toEqual(false);
1039
});

0 commit comments

Comments
 (0)