Skip to content

Commit 6998ca1

Browse files
committed
Add tests and handle invalid angle cases in getAngleType
1 parent 49fe3af commit 6998ca1

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,23 @@
1515
// execute the code to ensure all tests pass.
1616

1717
function getAngleType(angle) {
18-
// TODO: Implement this function
18+
if (angle <= 0 || angle >= 360) {
19+
return "Invalid angle";
20+
} else if (angle > 0 && angle < 90) {
21+
return "Acute angle";
22+
} else if (angle === 90) {
23+
return "Right angle";
24+
} else if (angle > 90 && angle < 180) {
25+
return "Obtuse angle";
26+
} else if (angle === 180) {
27+
return "Straight angle";
28+
} else if (angle > 180 && angle < 360) {
29+
return "Reflex angle";
30+
}
1931
}
2032

33+
// TODO: Implement this function
34+
2135
// The line below allows us to load the getAngleType function into tests in other files.
2236
// This will be useful in the "rewrite tests with jest" step.
2337
module.exports = getAngleType;
@@ -35,3 +49,24 @@ function assertEquals(actualOutput, targetOutput) {
3549
// Example: Identify Right Angles
3650
const right = getAngleType(90);
3751
assertEquals(right, "Right angle");
52+
53+
const acute = getAngleType(45);
54+
assertEquals(acute, "Acute angle");
55+
56+
const obtuse = getAngleType(120);
57+
assertEquals(obtuse, "Obtuse angle");
58+
59+
const straight = getAngleType(180);
60+
assertEquals(straight, "Straight angle");
61+
62+
const Reflex = getAngleType(200);
63+
assertEquals(Reflex, "Reflex angle");
64+
65+
const invalid1 = getAngleType(0);
66+
assertEquals(invalid1, "Invalid angle");
67+
68+
const invalid2 = getAngleType(360);
69+
assertEquals(invalid2, "Invalid angle");
70+
71+
const invalid3 = getAngleType(-10);
72+
assertEquals(invalid3, "Invalid angle");

0 commit comments

Comments
 (0)