Skip to content
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: Allow triangles where a+b == c #232

Merged
merged 2 commits into from
Jan 30, 2016
Merged

triangle: Allow triangles where a+b == c #232

merged 2 commits into from
Jan 30, 2016

Conversation

petertseng
Copy link
Member

These are degenerate triangles since they're really just lines, but
they're still good enough under the triangle inequality (which
explicitly allows a+b == c) so let's go ahead and test for them.

Test for isosceles and scalene added. Equilateral is impossible.

Closes #231

@petertseng
Copy link
Member Author

Ah hold on. Should probably bump test version. There is none for this currently, so that means just make it 1.

@@ -26,9 +26,11 @@ func KindFromSides(a, b, c float64) Kind {
}
// sides are now sorted
switch {
case math.IsInf(c, 0):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

someone might be confused about why you only need to check c and not a, b. comment?

These are degenerate triangles since they're really just lines, but
they're still good enough under the triangle inequality (which
explicitly allows a+b == c) so let's go ahead and test for them.

Test for isosceles and scalene added. Equilateral is impossible.

Unfortunately, now we are at risk for failing a test case of (3, Inf,
Inf), since 3 + Inf == Inf, and Inf < Inf is false whereas previously
the test was Inf <= Inf which is true. So we might falsely declare this
triangle as isosceles when it should be NaT. So we need to add another
test to make sure that our largest side isn't +Inf.

Closes #231
@petertseng
Copy link
Member Author

Test version is added so this is ready for review.

@petertseng petertseng mentioned this pull request Jan 30, 2016
The previous change (allow a+b == c) changes test behavior, so now's as
good a time as any to add a test version. The previous version can be
considered to be 0 since it isn't present, so 1 is OK to use here.
@@ -2,6 +2,8 @@

package triangle

const TestVersion = 1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that most other elements of this file (KindFromSides, Kind, Equ, etc...) have some sort of explanatory comment. I chose not to include one for TestVersion since students should have gotten the drill already from previous exercises. Let me know if you disagree.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this.

@kytrinyx
Copy link
Member

Thank you!

kytrinyx added a commit that referenced this pull request Jan 30, 2016
triangle: Allow triangles where a+b == c
@kytrinyx kytrinyx merged commit 23537ea into exercism:master Jan 30, 2016
@petertseng petertseng deleted the triangle-equal branch January 30, 2016 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants