Skip to content

Commit ad52844

Browse files
committed
rewrite all tests based on mathematical definition of proper fractions
1 parent c852657 commit ad52844

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
// After you have implemented the function, write tests to cover all the cases, and
1111
// execute the code to ensure all tests pass.
1212

13-
function isProperFraction(numerator, denominator) {
14-
// TODO: Implement this function
15-
}
13+
function isProperFraction(numerator, denominator) {}
1614

1715
// The line below allows us to load the isProperFraction function into tests in other files.
1816
// This will be useful in the "rewrite tests with jest" step.
@@ -34,14 +32,18 @@ assertEquals(isProperFraction(1, 2), true);
3432

3533
assertEquals(isProperFraction(9, 10), true);
3634

37-
assertEquals(isProperFraction(0, 7), false);
35+
assertEquals(isProperFraction(-6, 8), true);
36+
37+
assertEquals(isProperFraction(-2, -3), true);
38+
39+
assertEquals(isProperFraction(3.5, 6), true);
3840

39-
assertEquals(isProperFraction(5, 0), false);
41+
assertEquals(isProperFraction(4, 4.67), true);
4042

41-
assertEquals(isProperFraction(3.5, 6), false);
43+
assertEquals(isProperFraction(7, 0), false);
4244

4345
assertEquals(isProperFraction(2, 1), false);
4446

45-
assertEquals(isProperFraction(9, 3), false);
47+
assertEquals(isProperFraction(-9, -3), false);
4648

47-
assertEquals(isProperFraction(4, 4.67), false);
49+
assertEquals(isProperFraction(-5.68, 0), false);

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,35 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
66

77
// Special case: numerator is zero
88

9-
test(`should return true when numerator < denominator and both are integers`, () => {
9+
test(`should return true when the absolute value of the numerator is less than the absolute value of the denominator and the denominator is not 0`, () => {
1010
expect(isProperFraction(1, 2)).toEqual(true);
11-
expect(isProperFraction(3, 9)).toEqual(true);
12-
expect(isProperFraction(99, 100)).toEqual(true);
11+
expect(isProperFraction(3.5, 4)).toEqual(true);
12+
expect(isProperFraction(-99, -100)).toEqual(true);
13+
expect(isProperFraction(0, -5)).toEqual(true);
14+
expect(isProperFraction(8, 12.5)).toEqual(true);
15+
expect(isProperFraction(-6, 12)).toEqual(true);
1316
});
1417

15-
test(`should return false when denominator = zero`, () => {
16-
expect(isProperFraction(1, 0)).toEqual(false);
17-
expect(isProperFraction(5, 0)).toEqual(false);
18+
test(`should return false when the denominator is equal to zero`, () => {
19+
expect(isProperFraction(-1, 0)).toEqual(false);
20+
expect(isProperFraction(0, 0)).toEqual(false);
21+
expect(isProperFraction(15, 0)).toEqual(false);
22+
expect(isProperFraction(6.4, 0)).toEqual(false);
23+
expect(isProperFraction(-8.5, 0)).toEqual(false);
1824
});
1925

20-
test(`should return false when numerator = zero`, () => {
21-
expect(isProperFraction(0, 5)).toEqual(false);
22-
expect(isProperFraction(0, 7)).toEqual(false);
23-
});
24-
25-
test(`should return false when numerator > denominator`, () => {
26+
test(`should return false when the absolute value of the numerator is greater than the absolute value of the denominator`, () => {
2627
expect(isProperFraction(3, 2)).toEqual(false);
27-
expect(isProperFraction(9, 3)).toEqual(false);
28-
expect(isProperFraction(36, 7)).toEqual(false);
29-
});
30-
31-
test(`should return false when either numerator or denominator or both are float numbers`, () => {
32-
expect(isProperFraction(1.5, 2)).toEqual(false);
33-
expect(isProperFraction(6, 7.1)).toEqual(false);
34-
expect(isProperFraction(3.56, 2.4)).toEqual(false);
28+
expect(isProperFraction(-9, 3)).toEqual(false);
29+
expect(isProperFraction(-15, -4)).toEqual(false);
30+
expect(isProperFraction(36, -5)).toEqual(false);
31+
expect(isProperFraction(3.8, 2.7)).toEqual(false);
3532
});
3633

37-
test(`should return false when denominator is zero`, () => {
38-
expect(isProperFraction(1, 0)).toEqual(false);
34+
test(`should return false when the absolute value of the numerator is equal to the absolute value of the denominator`, () => {
35+
expect(isProperFraction(3, 3)).toEqual(false);
36+
expect(isProperFraction(-19, -19)).toEqual(false);
37+
expect(isProperFraction(7.45, 7.45)).toEqual(false);
38+
expect(isProperFraction(67, -67)).toEqual(false);
39+
expect(isProperFraction(-8, 8)).toEqual(false);
3940
});

0 commit comments

Comments
 (0)