1616
1717function getAngleType ( angle ) {
1818 // TODO: Implement this function
19+ // Check invalid first - angles must be between 0 and 360 (exclusive)
20+ if ( angle <= 0 || angle >= 360 ) return "Invalid angle" ;
21+ // Check exact values before ranges to avoid overlap
22+ if ( angle === 90 ) return "Right angle" ;
23+ if ( angle === 180 ) return "Straight angle" ;
24+ // Now check ranges
25+ if ( angle < 90 ) return "Acute angle" ;
26+ if ( angle < 180 ) return "Obtuse angle" ;
27+ return "Reflex angle" ; // anything left must be between 180 and 360, which is reflex
1928}
2029
2130// The line below allows us to load the getAngleType function into tests in other files.
@@ -33,5 +42,53 @@ function assertEquals(actualOutput, targetOutput) {
3342
3443// TODO: Write tests to cover all cases, including boundary and invalid cases.
3544// Example: Identify Right Angles
45+ // // Right angle: only one possible value
3646const right = getAngleType ( 90 ) ;
3747assertEquals ( right , "Right angle" ) ;
48+
49+ // Acute angles: test a boundary (just above 0), a normal case, and a boundary (just below 90)
50+ const acute1 = getAngleType ( 1 ) ;
51+ assertEquals ( acute1 , "Acute angle" ) ; // boundary: just above 0
52+
53+ const acute2 = getAngleType ( 45 ) ;
54+ assertEquals ( acute2 , "Acute angle" ) ; // normal acute angle
55+
56+ const acute3 = getAngleType ( 89 ) ;
57+ assertEquals ( acute3 , "Acute angle" ) ; // boundary: just below 90
58+
59+ // Obtuse angles: boundary just above 90, normal, boundary just below 180
60+ const obtuse1 = getAngleType ( 91 ) ;
61+ assertEquals ( obtuse1 , "Obtuse angle" ) ; // boundary: just above 90
62+
63+ const obtuse2 = getAngleType ( 120 ) ;
64+ assertEquals ( obtuse2 , "Obtuse angle" ) ; // normal obtuse angle
65+
66+ const obtuse3 = getAngleType ( 179 ) ;
67+ assertEquals ( obtuse3 , "Obtuse angle" ) ; // boundary: just below 180
68+
69+ // Straight angle: only one possible value
70+ const straight = getAngleType ( 180 ) ;
71+ assertEquals ( straight , "Straight angle" ) ;
72+
73+ // Reflex angles: boundary just above 180, normal, boundary just below 360
74+ const reflex1 = getAngleType ( 181 ) ;
75+ assertEquals ( reflex1 , "Reflex angle" ) ; // boundary: just above 180
76+
77+ const reflex2 = getAngleType ( 270 ) ;
78+ assertEquals ( reflex2 , "Reflex angle" ) ; // normal reflex angle
79+
80+ const reflex3 = getAngleType ( 359 ) ;
81+ assertEquals ( reflex3 , "Reflex angle" ) ; // boundary: just below 360
82+
83+ // Invalid angles: exactly 0, exactly 360, negative, over 360
84+ const invalid1 = getAngleType ( 0 ) ;
85+ assertEquals ( invalid1 , "Invalid angle" ) ; // boundary: exactly 0
86+
87+ const invalid2 = getAngleType ( 360 ) ;
88+ assertEquals ( invalid2 , "Invalid angle" ) ; // boundary: exactly 360
89+
90+ const invalid3 = getAngleType ( - 10 ) ;
91+ assertEquals ( invalid3 , "Invalid angle" ) ; // negative number
92+
93+ const invalid4 = getAngleType ( 400 ) ;
94+ assertEquals ( invalid4 , "Invalid angle" ) ; // over 360
0 commit comments