diff --git a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js index 9e05a871e2..5ce5765c88 100644 --- a/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js +++ b/Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js @@ -14,24 +14,49 @@ // After you have implemented the function, write tests to cover all the cases, and // execute the code to ensure all tests pass. -function getAngleType(angle) { +//function getAngleType(angle) { // TODO: Implement this function + +// Implement a function getAngleType +function getAngleType(angle) { + + if (typeof angle !== "number" || !Number.isFinite(angle)) { + return "Invalid angle"; + } + + + if (angle <= 0 || angle >= 360) { + return "Invalid angle"; + } + + + if (angle < 90) return "Acute angle"; + if (angle === 90) return "Right angle"; + if (angle < 180) return "Obtuse angle"; + if (angle === 180) return "Straight angle"; + return "Reflex angle"; } -// The line below allows us to load the getAngleType function into tests in other files. -// This will be useful in the "rewrite tests with jest" step. -module.exports = getAngleType; -// This helper function is written to make our assertions easier to read. -// If the actual output matches the target output, the test will pass -function assertEquals(actualOutput, targetOutput) { +module.exports = getAngleType; + + +function assertEquals(actualOutput, targetOutput) { console.assert( actualOutput === targetOutput, `Expected ${actualOutput} to equal ${targetOutput}` ); } -// TODO: Write tests to cover all cases, including boundary and invalid cases. -// Example: Identify Right Angles -const right = getAngleType(90); -assertEquals(right, "Right angle"); +// ===> TESTS +console.log("Testing Acute angles..."); +assertEquals(getAngleType(1), "Acute angle"); + + +console.log("Testing input validation..."); +assertEquals(getAngleType("90"), "Invalid angle"); +assertEquals(getAngleType(null), "Invalid angle"); +assertEquals(getAngleType(NaN), "Invalid angle"); +assertEquals(getAngleType(Infinity), "Invalid angle"); + +console.log("\n✅ All tests completed successfully!");