-
-
Notifications
You must be signed in to change notification settings - Fork 337
Glasgow | ITP-Jan-26 | Fattouma Ouannassi | Sprint 3 | Coursework 3 implement and rewrite #1080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FAprogrammerO
wants to merge
3
commits into
CodeYourFuture:main
Choose a base branch
from
FAprogrammerO:coursework/sprint-3-implement-and-rewrite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,24 +14,90 @@ | |
| // 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 (angle > 0 && angle < 90) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The range checks work correctly, but the logic can be simplified. Try to see if you can reduce the number of checks, to make the code cleaner.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done ✅ |
||
| return "Acute angle"; | ||
| } else if (angle === 90) { | ||
| return "Right angle"; | ||
| } else if (angle > 90 && angle < 180) { | ||
| return "Obtuse angle"; | ||
| } else if (angle === 180) { | ||
| return "Straight angle"; | ||
| } else if (angle > 180 && angle < 360) { | ||
| return "Reflex angle"; | ||
| } else { | ||
| return "Invalid angle"; | ||
| } | ||
| } | ||
|
|
||
| // Export for use in other files / Jest tests | ||
| //module.exports = getAngleType; | ||
|
|
||
| // Helper function for assertions | ||
| function assertEquals(actualOutput, targetOutput) { | ||
| console.assert( | ||
| actualOutput === targetOutput, | ||
| `Expected ${actualOutput} to equal ${targetOutput}` | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| // 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; | ||
| //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) { | ||
| /*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 | ||
|
|
||
| // Acute angles (0 < angle < 90) | ||
| console.log("Testing Acute angles..."); | ||
| assertEquals(getAngleType(1), "Acute angle"); | ||
| assertEquals(getAngleType(45), "Acute angle"); | ||
| assertEquals(getAngleType(89), "Acute angle"); | ||
| assertEquals(getAngleType(0.5), "Acute angle"); | ||
|
|
||
| // Right angle (=90) | ||
| console.log("Testing Right angle..."); | ||
| assertEquals(getAngleType(90), "Right angle"); | ||
|
|
||
| // Obtuse angles (90 < angle < 180) | ||
| console.log("Testing Obtuse angles..."); | ||
| assertEquals(getAngleType(91), "Obtuse angle"); | ||
| assertEquals(getAngleType(135), "Obtuse angle"); | ||
| assertEquals(getAngleType(179), "Obtuse angle"); | ||
|
|
||
| // Straight angle (=180) | ||
| console.log("Testing Straight angle..."); | ||
| assertEquals(getAngleType(180), "Straight angle"); | ||
|
|
||
| // Reflex angles (180 < angle < 360) | ||
| console.log("Testing Reflex angles..."); | ||
| assertEquals(getAngleType(181), "Reflex angle"); | ||
| assertEquals(getAngleType(270), "Reflex angle"); | ||
| assertEquals(getAngleType(359), "Reflex angle"); | ||
| assertEquals(getAngleType(359.9), "Reflex angle"); | ||
|
|
||
| // Invalid angles (angle <= 0 or angle >= 360) | ||
| console.log("Testing Invalid angles..."); | ||
| assertEquals(getAngleType(0), "Invalid angle"); | ||
| assertEquals(getAngleType(-1), "Invalid angle"); | ||
| assertEquals(getAngleType(-45), "Invalid angle"); | ||
| assertEquals(getAngleType(360), "Invalid angle"); | ||
| assertEquals(getAngleType(361), "Invalid angle"); | ||
| assertEquals(getAngleType(720), "Invalid angle"); | ||
|
|
||
| console.log("\n✅ All tests completed successfully!"); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function assumes the input is always a valid number. You may want to guard against non-number values (e.g. "90", null, NaN) to avoid unexpected behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✅