Skip to content

Commit 3334102

Browse files
committed
revised function and test for isProperFraction
1 parent ccb7a54 commit 3334102

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ import test from "node:test";
77

88
test("Basic proper fraction", () => {
99
// Example: 1/2 is a proper fraction
10-
assert.equal(isProperFraction(1, 2), "true");
10+
assert.equal(isProperFraction(1, 2), true);
1111
});
1212

1313
test("Basic proper fraction", () => {
14-
assert.equal(isProperFraction(3, 2), "false");
14+
assert.equal(isProperFraction(3, 2), false);
15+
});
16+
17+
test("Basic proper fraction", () => {
18+
assert.equal(isProperFraction(0, 2), false);
19+
});
20+
21+
test("Basic proper fraction", () => {
22+
assert.equal(isProperFraction(2, -5), false);
1523
});

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
// execute the code to ensure all tests pass.
1515

1616
export function isProperFraction(numerator, denominator) {
17-
if (numerator < denominator) {
18-
return "true";
19-
}
20-
return "false";
17+
return numerator > 0 && denominator > 0 && numerator < denominator;
2118
}
19+
20+
console.log(isProperFraction(2, 6));

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js";
44

55
// Special case: numerator is zero
66
test(`should return false when denominator is zero`, () => {
7-
expect(isProperFraction(1, 0)).toEqual("false");
7+
expect(isProperFraction(1, 0)).toEqual(false);
88
});
99

1010
test(`should return true when denominator is more than numerator`, () => {
11-
expect(isProperFraction(1, 4)).toEqual("true");
11+
expect(isProperFraction(1, 4)).toEqual(true);
1212
});
1313

1414
test(`should return false when denominator is less than numerator`, () => {
15-
expect(isProperFraction(4, 1)).toEqual("false");
15+
expect(isProperFraction(4, 1)).toEqual(false);
1616
});
1717

1818
test(`should true when denominator and numerator are negative`, () => {
19-
expect(isProperFraction(-5, -2)).toEqual("true");
19+
expect(isProperFraction(-5, -2)).toEqual(false);
2020
});

0 commit comments

Comments
 (0)