-
-
Notifications
You must be signed in to change notification settings - Fork 396
London | 26-ITP-May | Eyob Zeray | Sprint 3 | Implement and rewrite tests coursework #1547
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
eyob-tech
wants to merge
4
commits into
CodeYourFuture:main
Choose a base branch
from
eyob-tech: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 all commits
Commits
Show all changes
4 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
38 changes: 28 additions & 10 deletions
38
Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
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 |
|---|---|---|
| @@ -1,37 +1,55 @@ | ||
| // Implement a function getAngleType | ||
| // | ||
| // When given an angle in degrees, it should return a string indicating the type of angle: | ||
| // When given an angle in degrees, it should return a string: | ||
| // - "Acute angle" for angles greater than 0° and less than 90° | ||
| // - "Right angle" for exactly 90° | ||
| // - "Obtuse angle" for angles greater than 90° and less than 180° | ||
| // - "Straight angle" for exactly 180° | ||
| // - "Reflex angle" for angles greater than 180° and less than 360° | ||
| // - "Invalid angle" for angles outside the valid range. | ||
| // - "Invalid angle" for angles outside the valid range | ||
|
|
||
| // Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) | ||
| // Assumption: The parameter is a valid number. (You do not need to check this.) | ||
|
|
||
| // Acceptance criteria: | ||
| // After you have implemented the function, write tests to cover all the cases, and | ||
| // After you have implemented the function, write tests to cover all cases, including boundary values, and | ||
| // execute the code to ensure all tests pass. | ||
|
|
||
| function getAngleType(angle) { | ||
| // TODO: Implement this function | ||
| if (angle > 0 && angle < 90) { | ||
| 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"; | ||
| } | ||
| } | ||
|
|
||
| // 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. | ||
| // The line below allows us to load the getAngleType function into other files | ||
| // This will be useful in the "rewrite tests with jest" step later | ||
| 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 | ||
| // This helper function is written to make our assertions easier to read | ||
| // If the actual output matches the target output, the test passes | ||
| 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. | ||
| // TODO: Write tests to cover all cases, including boundary values | ||
| // Example: Identify Right Angles | ||
| const right = getAngleType(90); | ||
| assertEquals(right, "Right angle"); | ||
| const acute = getAngleType(45); | ||
| assertEquals(acute, "Acute angle"); | ||
|
|
||
| const invalid = getAngleType(-10); | ||
| assertEquals(invalid, "Invalid angle"); | ||
|
|
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
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
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
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
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
Oops, something went wrong.
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.
Do you have a test case here for negative improper fractions?
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.
Hey Lon, good spot — you were right, I hadn't covered negative improper fractions. Added a test for
isProperFraction(-7, 3)(should returnfalse) and checked the implementation handles it fine since it usesMath.abs()in the comparison. Just pushed the fix, ready for another look whenever you get a chance