Skip to content

Commit 0ef19ec

Browse files
written tests to check whether a given angle matches the expected output
1 parent b31a586 commit 0ef19ec

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,27 @@
1515
// execute the code to ensure all tests pass.
1616

1717
function getAngleType(angle) {
18-
// TODO: Implement this function
18+
if (angle > 0 && angle < 90) {
19+
return "Acute angle";
20+
}
21+
if (angle === 90) {
22+
return "Right angle";
23+
}
24+
if (angle > 90 && angle < 180) {
25+
return "Obtuse angle";
26+
}
27+
if (angle === 180) {
28+
return "Straight angle";
29+
}
30+
if (angle > 180 && angle < 360) {
31+
return "Reflex angle";
32+
}
33+
return "Invalid angle";
1934
}
2035

2136
// The line below allows us to load the getAngleType function into tests in other files.
2237
// This will be useful in the "rewrite tests with jest" step.
2338
module.exports = getAngleType;
24-
2539
// This helper function is written to make our assertions easier to read.
2640
// If the actual output matches the target output, the test will pass
2741
function assertEquals(actualOutput, targetOutput) {
@@ -33,5 +47,15 @@ function assertEquals(actualOutput, targetOutput) {
3347

3448
// TODO: Write tests to cover all cases, including boundary and invalid cases.
3549
// Example: Identify Right Angles
50+
const acute = getAngleType(45);
51+
assertEquals(acute, "Acute angle");
3652
const right = getAngleType(90);
3753
assertEquals(right, "Right angle");
54+
const obtuse = getAngleType(135);
55+
assertEquals(obtuse, "Obtuse angle");
56+
const straight = getAngleType(180);
57+
assertEquals(straight, "Straight angle");
58+
const reflex = getAngleType(270);
59+
assertEquals(reflex, "Reflex angle");
60+
const invalidAngle = getAngleType(-10);
61+
assertEquals(invalidAngle, "Invalid angle");

0 commit comments

Comments
 (0)