Skip to content

Commit 281f53b

Browse files
committed
implement function for angles and write test cases
1 parent b31a586 commit 281f53b

1 file changed

Lines changed: 50 additions & 2 deletions

File tree

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

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
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) return "Invalid angle";
19+
if (angle < 90) return "Acute angle";
20+
if (angle === 90) return "Right angle";
21+
if (angle < 180) return "Obtuse angle";
22+
if (angle === 180) return "Straight angle";
23+
if (angle < 360) return "Reflex angle";
1924
}
20-
2125
// The line below allows us to load the getAngleType function into tests in other files.
2226
// This will be useful in the "rewrite tests with jest" step.
2327
module.exports = getAngleType;
@@ -35,3 +39,47 @@ function assertEquals(actualOutput, targetOutput) {
3539
// Example: Identify Right Angles
3640
const right = getAngleType(90);
3741
assertEquals(right, "Right angle");
42+
43+
const straight = getAngleType(180);
44+
assertEquals(straight, "Straight angle");
45+
46+
const acute_upper_boundary = getAngleType(89);
47+
assertEquals(acute_upper_boundary, "Acute angle");
48+
49+
const acute_lower_boundary = getAngleType(1);
50+
assertEquals(acute_lower_boundary, "Acute angle");
51+
52+
const invalid_negative = getAngleType(-1);
53+
assertEquals(invalid_negative, "Invalid angle");
54+
55+
const invalid_zero = getAngleType(0);
56+
assertEquals(invalid_zero, "Invalid angle");
57+
58+
const invalid_full = getAngleType(360);
59+
assertEquals(invalid_full, "Invalid angle");
60+
61+
const invalid_big = getAngleType(361);
62+
assertEquals(invalid_big, "Invalid angle");
63+
64+
const obtuse_lower_boundary = getAngleType(91);
65+
assertEquals(obtuse_lower_boundary, "Obtuse angle");
66+
67+
const obtuse_upper_boundary = getAngleType(179);
68+
assertEquals(obtuse_upper_boundary, "Obtuse angle");
69+
70+
const reflex_lower_boundary = getAngleType(181);
71+
assertEquals(reflex_lower_boundary, "Reflex angle");
72+
73+
const reflex_upper_boundary = getAngleType(359);
74+
assertEquals(reflex_upper_boundary, "Reflex angle");
75+
76+
//decimal test cases
77+
78+
const acute_decimal = getAngleType(89.9);
79+
assertEquals(acute_decimal, "Acute angle");
80+
81+
const obtuse_decimal = getAngleType(179.9);
82+
assertEquals(obtuse_decimal, "Obtuse angle");
83+
84+
const reflex_decimal = getAngleType(180.1);
85+
assertEquals(reflex_decimal, "Reflex angle");

0 commit comments

Comments
 (0)