Skip to content

Instantly share code, notes, and snippets.

@brenfrow
Created June 29, 2012 17:46
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save brenfrow/3019571 to your computer and use it in GitHub Desktop.
triangle
# 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