|
| 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 |
| 9 | + |
| 10 | +function getAngleType(angle) { |
| 11 | +<<<<<<<< HEAD:Sprint-3/implement/1-get-angle-type.js |
| 12 | + if (angle === 90) return "Right angle"; |
| 13 | + if (angle < 90) return "Acute angle"; |
| 14 | + if (angle > 90 && angle < 180) return "Obtuse angle"; |
| 15 | + if (angle === 180) return "Straight angle"; |
| 16 | + if (angle > 180 && angle < 360) return "Reflex angle"; |
| 17 | + |
| 18 | + // read to the end, complete line 36, then pass your test here |
| 19 | +======== |
| 20 | + if (angle === 90) { |
| 21 | + return "Right angle"; |
| 22 | + } |
| 23 | + // Run the tests, work out what Case 2 is testing, and implement the required code here. |
| 24 | + // Then keep going for the other cases, one at a time. |
| 25 | +>>>>>>>> main:Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js |
| 26 | +} |
| 27 | + |
| 28 | +// The line below allows us to load the getAngleType function into tests in other files. |
| 29 | +// This will be useful in the "rewrite tests with jest" step. |
| 30 | +module.exports = getAngleType; |
| 31 | + |
| 32 | +// we're going to use this helper function to make our assertions easier to read |
| 33 | +// if the actual output matches the target output, the test will pass |
| 34 | +function assertEquals(actualOutput, targetOutput) { |
| 35 | + console.assert( |
| 36 | + actualOutput === targetOutput, |
| 37 | + `Expected ${actualOutput} to equal ${targetOutput}` |
| 38 | + ); |
| 39 | +} |
| 40 | + |
| 41 | +// Acceptance criteria: |
| 42 | + |
| 43 | +// Given an angle in degrees, |
| 44 | +// When the function getAngleType is called with this angle, |
| 45 | +// Then it should: |
| 46 | + |
| 47 | +// Case 1: Identify Right Angles: |
| 48 | +// When the angle is exactly 90 degrees, |
| 49 | +// Then the function should return "Right angle" |
| 50 | +const right = getAngleType(90); |
| 51 | +assertEquals(right, "Right angle"); |
| 52 | + |
| 53 | +// Case 2: Identify Acute Angles: |
| 54 | +// When the angle is less than 90 degrees, |
| 55 | +// Then the function should return "Acute angle" |
| 56 | +const acute = getAngleType(45); |
| 57 | +assertEquals(acute, "Acute angle"); |
| 58 | + |
| 59 | +// Case 3: Identify Obtuse Angles: |
| 60 | +// When the angle is greater than 90 degrees and less than 180 degrees, |
| 61 | +// Then the function should return "Obtuse angle" |
| 62 | +const obtuse = getAngleType(120); |
| 63 | +assertEquals(obtuse, "Obtuse angle"); |
| 64 | +// ====> write your test here, and then add a line to pass the test in the function above |
| 65 | + |
| 66 | +// Case 4: Identify Straight Angles: |
| 67 | +// When the angle is exactly 180 degrees, |
| 68 | +// Then the function should return "Straight angle" |
| 69 | +// ====> write your test here, and then add a line to pass the test in the function above |
| 70 | +const straight = getAngleType(180); |
| 71 | +assertEquals(straight, "Straight angle"); |
| 72 | + |
| 73 | +// Case 5: Identify Reflex Angles: |
| 74 | +// When the angle is greater than 180 degrees and less than 360 degrees, |
| 75 | +// Then the function should return "Reflex angle" |
| 76 | +// ====> write your test here, and then add a line to pass the test in the function above |
| 77 | +const reflex = getAngleType(270); |
| 78 | +assertEquals(reflex, "Reflex angle"); |
0 commit comments