Skip to content

Commit f55833e

Browse files
committed
Changes done as per the review
1 parent 6a1888e commit f55833e

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15-
if (denominator === 0) {
15+
if (denominator === 0) {
16+
return false;
17+
}
18+
// check if both numbers are integers
19+
if (!Number.isInteger(numerator) || !Number.isInteger(denominator)) {
1620
return false;
1721
}
1822
return Math.abs(numerator) < Math.abs(denominator);
@@ -38,7 +42,6 @@ assertEquals(isProperFraction(1, 2), true);
3842
assertEquals(isProperFraction(5, 1), false);
3943
assertEquals(isProperFraction(7, 7), false);
4044

41-
4245
//Negative fractions
4346
assertEquals(isProperFraction(-5, -2), false);
4447
assertEquals(isProperFraction(-1, -2), true);
@@ -52,7 +55,11 @@ assertEquals(isProperFraction(-1, 0), false);
5255
assertEquals(isProperFraction(0, 0), false);
5356

5457
// With decimals
55-
assertEquals(isProperFraction(2.5, -3), true);
56-
assertEquals(isProperFraction(-3.4, 6.3), true);
58+
assertEquals(isProperFraction(2.5, -3), false);
59+
assertEquals(isProperFraction(-3.4, 6.3), false);
5760
assertEquals(isProperFraction(-7.4, 3.3), false);
5861

62+
// Boundary cases where |Numerator| equals |Denominator|
63+
assertEquals(isProperFraction(7, -7), false);
64+
assertEquals(isProperFraction(-21, -21), false);
65+
assertEquals(isProperFraction(119, 119), false);

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ test(`should return false when denominator is zero`, () => {
1111
});
1212

1313
// When numerator is greater than the denominator
14-
test(`should return false when numerator > denominator`, () => {
14+
test(`should return false when |numerator| >= |denominator|`, () => {
1515
expect(isProperFraction(5, 3)).toEqual(false);
1616
expect(isProperFraction(140, 7)).toEqual(false);
1717
expect(isProperFraction(-16, -5)).toEqual(false);
1818
expect(isProperFraction(-70, 14)).toEqual(false);
1919
expect(isProperFraction(100, -11)).toEqual(false);
20+
expect(isProperFraction(-13, -13)).toEqual(false);
21+
});
22+
23+
// When the numerator or denominator is not an integer
24+
test(`should return false when numerator or denominator is not an integer`, () => {
25+
expect(isProperFraction(-1.5, 2)).toEqual(false);
26+
expect(isProperFraction(2.3, 4)).toEqual(false);
27+
expect(isProperFraction(3.7, 7)).toEqual(false);
28+
expect(isProperFraction(102.8, -103.2)).toEqual(false);
2029
});
2130

2231
// When the fraction is correct

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ test(`Should return Invalid when given an Invalid card`, () => {
3636
expect(() => getCardValue("K♠♣")).toThrow("Invalid card");
3737
expect(() => getCardValue("QQ♥")).toThrow("Invalid card");
3838
expect(() => getCardValue("")).toThrow("Invalid card");
39+
expect(() => getCardValue("5♡")).toThrow("Invalid card");
40+
expect(() => getCardValue("Q")).toThrow("Invalid card");
3941
});
4042

4143
// To learn how to test whether a function throws an error as expected in Jest,
4244
// please refer to the Jest documentation:
4345
// https://jestjs.io/docs/expect#tothrowerror
44-

0 commit comments

Comments
 (0)