-
-
Notifications
You must be signed in to change notification settings - Fork 550
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
Triangle: Update tests to check properties, not types #424
Merged
IanWhitney
merged 3 commits into
exercism:master
from
IanWhitney:property_based_triangles
Oct 26, 2016
Merged
Changes from all 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 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 |
---|---|---|
|
@@ -8,88 +8,115 @@ | |
"They're degenerate triangles with all three vertices collinear.", | ||
"(In contrast, we will test (0, 0, 0, Illegal), as it is a point).", | ||
|
||
"The expectation are given as strings,", | ||
"but your language may use the appropriate representations.", | ||
"For example, enums, variants, or tagged unions all are viable candidates.", | ||
"The tests assert properities of the triangle are true or false.", | ||
"See: https://github.com/exercism/x-common/issues/379 for disscussion of this approach", | ||
|
||
"Your track may choose to have the 'illegal' result be another member of the enum/variant/union/etc.,", | ||
"or instead to signal an error/exception/etc. on an illegal triangle.", | ||
|
||
"If appropriate for your track, you'll need to ensure that no pair of expected values are equal.", | ||
"Otherwise, an implementation that always returns a constant value may falsely pass the tests.", | ||
"See https://github.com/exercism/xgo/pull/208" | ||
"How you handle invalid triangles is up to you. These tests suggest a triangle", | ||
"is returned, but all of its properties are false. But you could also have the creation", | ||
"of an invalid triangle return an error or exception. Choose what is idiomatic for", | ||
"your language." | ||
], | ||
"cases": [ | ||
"equilateral": { | ||
"description": "returns true if the triangle is equilateral", | ||
"cases": [ | ||
{ | ||
"description": "equilateral triangle has all sides equal", | ||
"sides": [2, 2, 2], | ||
"expected": "equilateral" | ||
"description": "true if all sides are equal", | ||
"sides": [2, 2, 2], | ||
"expected": true | ||
}, | ||
{ | ||
"description": "larger equilateral triangle", | ||
"sides": [10, 10, 10], | ||
"expected": "equilateral" | ||
"description": "false if any side is unequal", | ||
"sides": [2, 3, 2], | ||
"expected": false | ||
}, | ||
{ | ||
"description": "isosceles triangle with last two sides equal", | ||
"sides": [3, 4, 4], | ||
"expected": "isosceles" | ||
"description": "false if no sides are equal", | ||
"sides": [5, 4, 6], | ||
"expected": false | ||
}, | ||
{ | ||
"description": "isosceles triangle with first two sides equal", | ||
"sides": [4, 4, 3], | ||
"expected": "isosceles" | ||
"description": "All zero sides are illegal, so the triangle is not equilateral", | ||
"sides": [0, 0, 0], | ||
"expected": false | ||
}, | ||
{ | ||
"description": "isosceles triangle with first and last sides equal", | ||
"sides": [4, 3, 4], | ||
"expected": "isosceles" | ||
"#": "Your track may choose to skip this test and deal only with integers if appropriate", | ||
"description": "sides may be floats", | ||
"sides": [0.5, 0.5, 0.5], | ||
"expected": true | ||
} | ||
] | ||
}, | ||
"isosceles": { | ||
"description": "returns true if the triangle is isosceles", | ||
"cases": [ | ||
{ | ||
"description": "true if last two sides are equal", | ||
"sides": [3, 4, 4], | ||
"expected": true | ||
}, | ||
{ | ||
"description": "isosceles triangle with unequal side larger than equal sides", | ||
"sides": [4, 7, 4], | ||
"expected": "isosceles" | ||
"description": "true if first two sides are equal", | ||
"sides": [4, 4, 3], | ||
"expected": true | ||
}, | ||
{ | ||
"description": "scalene triangle has no equal sides", | ||
"sides": [3, 4, 5], | ||
"expected": "scalene" | ||
"description": "true if first and last sides are equal", | ||
"sides": [4, 3, 4], | ||
"expected": true | ||
}, | ||
{ | ||
"description": "2a == b+c looks like equilateral, but isn't always", | ||
"sides": [5, 4, 6], | ||
"expected": "scalene" | ||
"description": "equilateral triangles are also isosceles", | ||
"sides": [4, 4, 4], | ||
"expected": true | ||
}, | ||
{ | ||
"description": "larger scalene triangle", | ||
"sides": [10, 11, 12], | ||
"expected": "scalene" | ||
"description": "false if no sides are equal", | ||
"sides": [2, 3, 4], | ||
"expected": false | ||
}, | ||
{ | ||
"description": "scalene triangle with sides in descending order", | ||
"sides": [5, 4, 2], | ||
"expected": "scalene" | ||
"description": "Sides that violate triangle inequality are not isosceles, even if two are equal", | ||
"sides": [1, 1, 3], | ||
"expected": false | ||
}, | ||
{ | ||
"#": "Your track may choose to skip this test and deal only with integers if appropriate", | ||
"description": "sides may be floats", | ||
"sides": [0.5, 0.4, 0.5], | ||
"expected": true | ||
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. This doesn't look isosceles |
||
} | ||
] | ||
}, | ||
"scalene": { | ||
"description": "returns true if the triangle is scalene", | ||
"cases": [ | ||
{ | ||
"description": "true if no sides are equal", | ||
"sides": [5, 4, 6], | ||
"expected": true | ||
}, | ||
{ | ||
"#": "Your track may choose to skip this test and deal only with integers if appropriate", | ||
"description": "small scalene triangle with floating point values", | ||
"sides": [0.4, 0.6, 0.3], | ||
"expected": "scalene" | ||
"description": "false if all sides are equal", | ||
"sides": [4, 4, 4], | ||
"expected": false | ||
}, | ||
{ | ||
"description": "a triangle violating the triangle inequality is illegal", | ||
"sides": [7, 3, 2], | ||
"expected": "illegal" | ||
"description": "false if two sides are equal", | ||
"sides": [4, 4, 3], | ||
"expected": false | ||
}, | ||
{ | ||
"description": "two sides equal, but still violates triangle inequality", | ||
"sides": [1, 1, 3], | ||
"expected": "illegal" | ||
"description": "Sides that violate triangle inequality are not scalene, even if they are all different", | ||
"sides": [7, 3, 2], | ||
"expected": false | ||
}, | ||
{ | ||
"description": "triangles with all sides zero are illegal", | ||
"sides": [0, 0, 0], | ||
"expected": "illegal" | ||
"#": "Your track may choose to skip this test and deal only with integers if appropriate", | ||
"description": "sides may be floats", | ||
"sides": [0.5, 0.4, 0.6], | ||
"expected": true | ||
} | ||
] | ||
] | ||
} | ||
} |
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.
Might be good to add a comment or expansion of the description here that clarifies that this is BOTH isosceles and equilateral.