Created
June 29, 2012 17:46
-
-
Save brenfrow/3019571 to your computer and use it in GitHub Desktop.
triangle
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
# You need to write the triangle method | |
class TriangleError < RuntimeError | |
end | |
def triangle(x,y,z) | |
raise TriangleError if has_zero_side? x,y,z | |
raise TriangleError if has_negitive_side? x,y,z | |
raise TriangleError if side_too_long? x,y,z | |
return :equilateral if equilateral? x,y,z | |
return :isosceles if isoceles? x,y,z | |
:scalene | |
end | |
triangle.should have_zero_sides | |
def has_zero_side?(x,y,z) | |
x == 0 || y == 0 || z == 0 | |
end | |
def has_negitive_side(x,y,z) | |
x < 0 || y < 0 || z < 0 | |
end | |
def side_to_long(x,y,z) | |
x+y <= z || y+z <= x || z+x <= y | |
end | |
def is_equilateral(x,y,z) | |
x == y && y == z && z == x | |
end | |
def is_isoceles(x,y,z) | |
x == y || y == z || z == x | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment