Skip to content

Commit 2eae682

Browse files
committed
Cover proper fraction sign and boundary cases
1 parent acbe93e commit 2eae682

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

‎implement-and-rewrite-tests/implement-tests-with-node-test/2-is-proper-fraction.test.js‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,31 @@ import test from "node:test";
33

44
import { isProperFraction } from "../implement/2-is-proper-fraction.js";
55

6-
// TODO: Write tests to cover all cases.
7-
// What combinations of numerators and denominators should you test?
8-
9-
test("Basic proper fraction", () => {
10-
// Example: 1/2 is a proper fraction
6+
test("returns true when the numerator's magnitude is less than the denominator's", () => {
117
assert.equal(isProperFraction(1, 2), true);
8+
assert.equal(isProperFraction(-1, 2), true);
9+
assert.equal(isProperFraction(1, -2), true);
10+
assert.equal(isProperFraction(-1, -2), true);
11+
});
12+
13+
test("returns false when the numerator's magnitude equals or exceeds the denominator's", () => {
14+
assert.equal(isProperFraction(2, 2), false);
15+
assert.equal(isProperFraction(-2, 2), false);
16+
assert.equal(isProperFraction(2, -2), false);
17+
assert.equal(isProperFraction(-2, -2), false);
18+
assert.equal(isProperFraction(3, 2), false);
19+
assert.equal(isProperFraction(-3, 2), false);
20+
assert.equal(isProperFraction(3, -2), false);
21+
assert.equal(isProperFraction(-3, -2), false);
22+
});
23+
24+
test("returns true when the numerator is zero and the denominator is nonzero", () => {
25+
assert.equal(isProperFraction(0, 5), true);
26+
assert.equal(isProperFraction(0, -5), true);
27+
});
28+
29+
test("returns false when the denominator is zero", () => {
30+
assert.equal(isProperFraction(1, 0), false);
31+
assert.equal(isProperFraction(-1, 0), false);
32+
assert.equal(isProperFraction(0, 0), false);
1233
});

0 commit comments

Comments
 (0)