Hi all,
First, thanks to Jeremy for the Ruby Koans link.
Now I'm puzzled, Sensei!
I'm trying to write the code for the cases on lines 12 & 13 (see below) and I don't understand why they should be expected to raise exceptions. They appear to be isosceles triangles and pass the isosceles test.
Am I missing something subtle? Or something obvious?
**Leigh
"Things are not as they appear; nor are they otherwise."
···
---------------
The Master says:
You have not yet reached enlightenment.
I sense frustration. Do not be afraid to ask for help.
The answers you seek...
TriangleError expected but nothing was raised.
Please meditate on the following code:
/Users/leigh/koans/about_triangle_project_2.rb:12:in `test_illegal_triangles_throw_exceptions'
def test_illegal_triangles_throw_exceptions
assert_raise(TriangleError) do triangle(0, 0, 0) end
assert_raise(TriangleError) do triangle(3, 4, -5) end
assert_raise(TriangleError) do triangle(1, 1, 3) end # line 12
assert_raise(TriangleError) do triangle(2, 4, 2) end # line 13
end
These tests all pass, including two from the illegal exceptions test:
def test_isosceles_triangles_have_exactly_two_sides_equal
assert_equal :isosceles, triangle(3, 4, 4)
assert_equal :isosceles, triangle(4, 3, 4)
assert_equal :isosceles, triangle(4, 4, 3)
assert_equal :isosceles, triangle(10, 10, 2)
assert_equal :isosceles, triangle(1, 1, 3) # these two are from
assert_equal :isosceles, triangle(2, 4, 2) # test_illegal_triangles_throw_exceptions
end
Here's the triangle method:
def triangle(a, b, c)
if (a <= 0) || (b <= 0) || (c <= 0)
raise TriangleError
end
case
when (a == b) && (a == c) && (b == c)
return :equilateral
when (b == c) || (a == c) || (a == b)
return :isosceles
when !(a == b) && !(a == c) && !(b == c)
return :scalene
else
return :oops!
end
end