|
1 | 1 | // Implement a function getAngleType |
2 | | -// Build up your function case by case, writing tests as you go |
3 | | -// The first test and case is written for you. The next case has a test, but no code. |
4 | | -// Execute this script in your terminal |
5 | | -// node 1-get-angle-type.js |
6 | | -// The assertion error will tell you what the expected output is |
7 | | -// Write the code to pass the test |
8 | | -// Then, write the next test! :) Go through this process until all the cases are implemented |
| 2 | +// |
| 3 | +// When given an angle in degrees, it should return a string indicating the type of angle: |
| 4 | +// - "Acute angle" for angles greater than 0° and less than 90° |
| 5 | +// - "Right angle" for exactly 90° |
| 6 | +// - "Obtuse angle" for angles greater than 90° and less than 180° |
| 7 | +// - "Straight angle" for exactly 180° |
| 8 | +// - "Reflex angle" for angles greater than 180° and less than 360° |
| 9 | +// - "Invalid angle" for angles outside the valid range. |
| 10 | + |
| 11 | +// Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) |
| 12 | + |
| 13 | +// Acceptance criteria: |
| 14 | +// After you have implemented the function, write tests to cover all the cases, and |
| 15 | +// execute the code to ensure all tests pass. |
9 | 16 |
|
10 | 17 | function getAngleType(angle) { |
11 | | - if (angle === 90) { |
12 | | - return "Right angle"; |
13 | | - } |
14 | | - if (angle < 90) { |
15 | | - return "Acute angle"; |
16 | | - } |
17 | | - if (angle > 90 && angle < 180) { |
18 | | - return "Obtuse angle"; |
19 | | - } |
20 | | - if (angle === 180) { |
21 | | - return "Straight angle"; |
22 | | - } |
23 | | - return "Reflex angle"; |
| 18 | + // TODO: Implement this function |
24 | 19 | } |
25 | 20 |
|
26 | 21 | // The line below allows us to load the getAngleType function into tests in other files. |
27 | 22 | // This will be useful in the "rewrite tests with jest" step. |
28 | 23 | module.exports = getAngleType; |
29 | 24 |
|
30 | | -// we're going to use this helper function to make our assertions easier to read |
31 | | -// if the actual output matches the target output, the test will pass |
| 25 | +// This helper function is written to make our assertions easier to read. |
| 26 | +// If the actual output matches the target output, the test will pass |
32 | 27 | function assertEquals(actualOutput, targetOutput) { |
33 | 28 | console.assert( |
34 | 29 | actualOutput === targetOutput, |
35 | 30 | `Expected ${actualOutput} to equal ${targetOutput}` |
36 | 31 | ); |
37 | 32 | } |
38 | 33 |
|
39 | | -// Acceptance criteria: |
40 | | - |
41 | | -// Given an angle in degrees, |
42 | | -// When the function getAngleType is called with this angle, |
43 | | -// Then it should: |
44 | | - |
45 | | -// Case 1: Identify Right Angles: |
46 | | -// When the angle is exactly 90 degrees, |
47 | | -// Then the function should return "Right angle" |
| 34 | +// TODO: Write tests to cover all cases, including boundary and invalid cases. |
| 35 | +// Example: Identify Right Angles |
48 | 36 | const right = getAngleType(90); |
49 | 37 | assertEquals(right, "Right angle"); |
50 | | - |
51 | | -// Case 2: Identify Acute Angles: |
52 | | -// When the angle is less than 90 degrees, |
53 | | -// Then the function should return "Acute angle" |
54 | | -const acute = getAngleType(45); |
55 | | -assertEquals(acute, "Acute angle"); |
56 | | - |
57 | | -// Case 3: Identify Obtuse Angles: |
58 | | -// When the angle is greater than 90 degrees and less than 180 degrees, |
59 | | -// Then the function should return "Obtuse angle" |
60 | | -const obtuse = getAngleType(120); |
61 | | -assertEquals(obtuse, "Obtuse angle"); |
62 | | - |
63 | | -// Case 4: Identify Straight Angles: |
64 | | -// When the angle is exactly 180 degrees, |
65 | | -// Then the function should return "Straight angle" |
66 | | -const straight = getAngleType(180); |
67 | | -assertEquals(straight, "Straight angle"); |
68 | | - |
69 | | -// Case 5: Identify Reflex Angles: |
70 | | -// When the angle is greater than 180 degrees and less than 360 degrees, |
71 | | -// Then the function should return "Reflex angle" |
72 | | -const reflex = getAngleType(340); |
73 | | -assertEquals(reflex, "Reflex angle"); |
0 commit comments