Skip to content

Commit 61d68a8

Browse files
created function getAngleType(angle) and wrote tests to cover all cases
1 parent 3372770 commit 61d68a8

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
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 > 90 && angle < 180) return "Obtuse angle";
22+
if (angle === 180) return "Straight angle";
23+
return "Reflex angle";
1924
}
2025

2126
// The line below allows us to load the getAngleType function into tests in other files.
@@ -31,7 +36,31 @@ function assertEquals(actualOutput, targetOutput) {
3136
);
3237
}
3338

34-
// TODO: Write tests to cover all cases, including boundary and invalid cases.
35-
// Example: Identify Right Angles
3639
const right = getAngleType(90);
3740
assertEquals(right, "Right angle");
41+
42+
const acute = getAngleType(45);
43+
assertEquals(acute, "Acute angle");
44+
45+
const obtuse = getAngleType(120);
46+
assertEquals(obtuse, "Obtuse angle");
47+
48+
const straight = getAngleType(180);
49+
assertEquals(straight, "Straight angle");
50+
51+
const reflex = getAngleType(270);
52+
assertEquals(reflex, "Reflex angle");
53+
54+
const invalid = getAngleType(-10);
55+
assertEquals(invalid, "Invalid angle");
56+
57+
const invalid2 = getAngleType(360);
58+
assertEquals(invalid2, "Invalid angle");
59+
60+
console.log(getAngleType(20));
61+
console.log(getAngleType(90));
62+
console.log(getAngleType(120));
63+
console.log(getAngleType(180));
64+
console.log(getAngleType(270));
65+
console.log(getAngleType(-10));
66+
console.log(getAngleType(360));

0 commit comments

Comments
 (0)