-
-
Notifications
You must be signed in to change notification settings - Fork 656
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
Conversation
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): |
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.
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
Test version is added so this is ready for review. |
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 |
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.
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.
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.
I agree with this.
Thank you! |
triangle: Allow triangles where a+b == c
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