88// Then, write the next test! :) Go through this process until all the cases are implemented
99
1010function getAngleType ( angle ) {
11- angleType = "" ;
12- if ( angle === 90 ) {
13- angleType = "Right angle" ;
11+ if ( typeof angle !== "number" || angle < 0 || angle > 360 ) {
12+ return "Invalid angle" ;
13+ }
14+
15+ if ( angle === 0 ) {
16+ return "Acute angle" ;
1417 } else if ( angle < 90 ) {
15- angleType = "Acute angle" ;
18+ return "Acute angle" ;
19+ } else if ( angle === 90 ) {
20+ return "Right angle" ;
1621 } else if ( angle > 90 && angle < 180 ) {
17- angleType = "Obtuse angle" ;
22+ return "Obtuse angle" ;
1823 } else if ( angle === 180 ) {
19- angleType = "Straight angle" ;
20- } else if ( angle > 180 && angle < 360 ) {
21- angleType = "Reflex angle" ;
24+ return "Straight angle" ;
25+ } else if ( angle > 180 && angle < 360 ) {
26+ return "Reflex angle" ;
27+ } else if ( angle === 360 ) {
28+ return "Full rotation" ;
2229 }
23- return angleType ;
24- // Run the tests, work out what Case 2 is testing, and implement the required code here.
25- // Then keep going for the other cases, one at a time.
30+
31+ return "Invalid angle" ;
2632}
2733
34+
35+
2836// The line below allows us to load the getAngleType function into tests in other files.
2937// This will be useful in the "rewrite tests with jest" step.
3038module . exports = getAngleType ;
@@ -47,33 +55,61 @@ function assertEquals(actualOutput, targetOutput) {
4755// Case 1: Identify Right Angles:
4856// When the angle is exactly 90 degrees,
4957// Then the function should return "Right angle"
50-
5158const right = getAngleType ( 90 ) ;
5259assertEquals ( right , "Right angle" ) ;
60+ const rightEdge = getAngleType ( 90.0 ) ;
61+ assertEquals ( rightEdge , "Right angle" ) ;
5362
5463// Case 2: Identify Acute Angles:
5564// When the angle is less than 90 degrees,
5665// Then the function should return "Acute angle"
57- const acute = getAngleType ( 45 ) ;
58- assertEquals ( acute , "Acute angle" ) ;
66+ const acute1 = getAngleType ( 45 ) ;
67+ assertEquals ( acute1 , "Acute angle" ) ;
68+ const acute2 = getAngleType ( 0 ) ;
69+ assertEquals ( acute2 , "Acute angle" ) ;
70+ const acute3 = getAngleType ( 89.999 ) ;
71+ assertEquals ( acute3 , "Acute angle" ) ;
5972
6073// Case 3: Identify Obtuse Angles:
6174// When the angle is greater than 90 degrees and less than 180 degrees,
6275// Then the function should return "Obtuse angle"
63- const obtuse = getAngleType ( 120 ) ;
64- // ====> write your test here, and then add a line to pass the test in the function above
65- assertEquals ( obtuse , "Obtuse angle" ) ;
76+ const obtuse1 = getAngleType ( 91 ) ;
77+ assertEquals ( obtuse1 , "Obtuse angle" ) ;
78+ const obtuse2 = getAngleType ( 120 ) ;
79+ assertEquals ( obtuse2 , "Obtuse angle" ) ;
80+ const obtuse3 = getAngleType ( 179.999 ) ;
81+ assertEquals ( obtuse3 , "Obtuse angle" ) ;
6682
6783// Case 4: Identify Straight Angles:
6884// When the angle is exactly 180 degrees,
6985// Then the function should return "Straight angle"
70- // ====> write your test here, and then add a line to pass the test in the function above
71- const straight = getAngleType ( 180 ) ;
72- assertEquals ( straight , "Straight angle" ) ;
86+ const straight1 = getAngleType ( 180 ) ;
87+ assertEquals ( straight1 , "Straight angle" ) ;
88+ const straightEdge = getAngleType ( 180.0 ) ;
89+ assertEquals ( straightEdge , "Straight angle" ) ;
7390
7491// Case 5: Identify Reflex Angles:
7592// When the angle is greater than 180 degrees and less than 360 degrees,
7693// Then the function should return "Reflex angle"
77- // ====> write your test here, and then add a line to pass the test in the function above
78- const reflex = getAngleType ( 270 ) ;
79- assertEquals ( reflex , "Reflex angle" ) ;
94+ const reflex1 = getAngleType ( 181 ) ;
95+ assertEquals ( reflex1 , "Reflex angle" ) ;
96+ const reflex2 = getAngleType ( 270 ) ;
97+ assertEquals ( reflex2 , "Reflex angle" ) ;
98+ const reflex3 = getAngleType ( 359.999 ) ;
99+ assertEquals ( reflex3 , "Reflex angle" ) ;
100+
101+ // Case 6: Identify Full Rotation:
102+ // When the angle is exactly 360 degrees,
103+ // Then the function should return "Full rotation"
104+ const fullRotation = getAngleType ( 360 ) ;
105+ assertEquals ( fullRotation , "Full rotation" ) ;
106+
107+ // Case 7: Handle Invalid Angles:
108+ // When the angle is negative or greater than 360,
109+ // Then the function should return "Invalid angle"
110+ const invalid1 = getAngleType ( - 10 ) ;
111+ assertEquals ( invalid1 , "Invalid angle" ) ;
112+ const invalid2 = getAngleType ( 400 ) ;
113+ assertEquals ( invalid2 , "Invalid angle" ) ;
114+ const invalid3 = getAngleType ( "abc" ) ;
115+ assertEquals ( invalid3 , "Invalid angle" ) ;
0 commit comments