88// Then, write the next test! :) Go through this process until all the cases are implemented
99
1010function getAngleType ( angle ) {
11- if ( angle === 90 ) {
12- return "Right angle" ;
13- }
14- // Run the tests, work out what Case 2 is testing, and implement the required code here.
15- // Then keep going for the other cases, one at a time.
11+ if ( angle === 90 ) return "Right angle" ;
12+ if ( angle < 90 ) return "Acute angle" ;
13+ if ( angle > 90 && angle < 180 ) return "Obtuse angle" ;
14+ if ( angle === 180 ) return "Straight angle" ;
15+ if ( angle > 180 && angle < 360 ) return "Reflex angle" ;
1616}
1717
18- // The line below allows us to load the getAngleType function into tests in other files.
19- // This will be useful in the "rewrite tests with jest" step.
2018module . exports = getAngleType ;
2119
22- // we're going to use this helper function to make our assertions easier to read
23- // if the actual output matches the target output, the test will pass
2420function assertEquals ( actualOutput , targetOutput ) {
2521 console . assert (
2622 actualOutput === targetOutput ,
2723 `Expected ${ actualOutput } to equal ${ targetOutput } `
2824 ) ;
2925}
3026
31- // Acceptance criteria:
32-
33- // Given an angle in degrees,
34- // When the function getAngleType is called with this angle,
35- // Then it should:
36-
37- // Case 1: Identify Right Angles:
38- // When the angle is exactly 90 degrees,
39- // Then the function should return "Right angle"
40- const right = getAngleType ( 90 ) ;
41- assertEquals ( right , "Right angle" ) ;
42-
43- // Case 2: Identify Acute Angles:
44- // When the angle is less than 90 degrees,
45- // Then the function should return "Acute angle"
46- const acute = getAngleType ( 45 ) ;
47- assertEquals ( acute , "Acute angle" ) ;
48-
49- // Case 3: Identify Obtuse Angles:
50- // When the angle is greater than 90 degrees and less than 180 degrees,
51- // Then the function should return "Obtuse angle"
52- const obtuse = getAngleType ( 120 ) ;
53- // ====> write your test here, and then add a line to pass the test in the function above
54-
55- // Case 4: Identify Straight Angles:
56- // When the angle is exactly 180 degrees,
57- // Then the function should return "Straight angle"
58- // ====> write your test here, and then add a line to pass the test in the function above
59-
60- // Case 5: Identify Reflex Angles:
61- // When the angle is greater than 180 degrees and less than 360 degrees,
62- // Then the function should return "Reflex angle"
63- // ====> write your test here, and then add a line to pass the test in the function above
27+ // Case 1: Identify Right Angles (90°)
28+ assertEquals ( getAngleType ( 90 ) , "Right angle" ) ;
29+
30+ // Case 2: Identify Acute Angles (< 90°)
31+ assertEquals ( getAngleType ( 45 ) , "Acute angle" ) ;
32+
33+ // Case 3: Identify Obtuse Angles (> 90° and < 180°)
34+ assertEquals ( getAngleType ( 120 ) , "Obtuse angle" ) ;
35+
36+ // Case 4: Identify Straight Angles (180°)
37+ assertEquals ( getAngleType ( 180 ) , "Straight angle" ) ;
38+
39+ // Case 5: Identify Reflex Angles (> 180° and < 360°)
40+ assertEquals ( getAngleType ( 270 ) , "Reflex angle" ) ;
41+
42+ console . log ( "✅ All tests passed!" ) ;
0 commit comments