Skip to content

Commit e8ca830

Browse files
committed
Completed exercise 2-is-proper-fraction.js and 2-is-proper-fraction-test.js and updated test in 1-get-angle-type.test.js
1 parent d28e5ce commit e8ca830

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,19 @@
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) {
14+
// Denominator cannot be 0
15+
if (denominator === 0)
16+
return false;
17+
if (!Number.isFinite(numerator) || !Number.isFinite(denominator)){
18+
return false;
19+
}
20+
if (!Number.isInteger(numerator) || !Number.isInteger(denominator)){
21+
return false;
22+
}
23+
//if is less than
24+
return Math.abs(numerator) < Math.abs(denominator);
25+
}
1626

1727
// The line below allows us to load the isProperFraction function into tests in other files.
1828
// This will be useful in the "rewrite tests with jest" step.
@@ -31,3 +41,8 @@ function assertEquals(actualOutput, targetOutput) {
3141

3242
// Example: 1/2 is a proper fraction
3343
assertEquals(isProperFraction(1, 2), true);
44+
assertEquals(isProperFraction(2, 1), false);
45+
assertEquals(isProperFraction(-1, -2), true);
46+
assertEquals(isProperFraction("1", 2), false);
47+
assertEquals(isProperFraction(1, 0), false);
48+

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ const getAngleType = require("../implement/1-get-angle-type");
99
// Case 1: Acute angles
1010
// When angle is greater that 0 and less than 90
1111
test(`should return "Acute angle" when (angle >0 angle < 90)`, () => {
12-
expect(getAngleType(1)).toEqual("Acute angle");
13-
expect(getAngleType(45)).toEqual("Acute angle");
14-
expect(getAngleType(89)).toEqual("Acute angle");
12+
expect(getAngleType(1)).toEqual("Acute angle");
13+
expect(getAngleType(45)).toEqual("Acute angle");
14+
expect(getAngleType(89)).toEqual("Acute angle");
1515
});
1616

1717
// Case 2: Right angles
1818
// When angle is 90
19-
test(`should return "Right angle" when (angle = 90)`, () => {
19+
test(`should return Right angle when (angle = 90)`, () => {
2020
expect(getAngleType(90)).toEqual("Right angle");
2121
});
2222

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,20 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
88
test(`should return false when denominator is zero`, () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
1010
});
11+
12+
test(`should return true when denominator is greater than numerator (2)`, () => {
13+
expect(isProperFraction(1, 2)).toEqual(true);
14+
});
15+
16+
test(`should return false when denominator is smaller than the numerator (1)`, () => {
17+
expect(isProperFraction(2, 1)).toEqual(false);
18+
});
19+
20+
test(`should return true when both values are valid numbers`, () => {
21+
expect(isProperFraction(-1, -2)).toEqual(true);
22+
});
23+
24+
test(`should return false when a number is not an integer`, () => {
25+
expect(isProperFraction("1", 2)).toEqual(false);
26+
});
27+

0 commit comments

Comments
 (0)