Skip to content

Commit

Permalink
154/274
Browse files Browse the repository at this point in the history
  • Loading branch information
Lincoln Lee committed Sep 18, 2011
1 parent c257f8b commit 9944fc1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
24 changes: 12 additions & 12 deletions about_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class MySpecialError < RuntimeError
end

def test_exceptions_inherit_from_Exception
assert_equal __, MySpecialError.ancestors[1]
assert_equal __, MySpecialError.ancestors[2]
assert_equal __, MySpecialError.ancestors[3]
assert_equal __, MySpecialError.ancestors[4]
assert_equal RuntimeError, MySpecialError.ancestors[1]
assert_equal StandardError, MySpecialError.ancestors[2]
assert_equal Exception, MySpecialError.ancestors[3]
assert_equal Object, MySpecialError.ancestors[4]
end

def test_rescue_clause
Expand All @@ -20,15 +20,15 @@ def test_rescue_clause
result = :exception_handled
end

assert_equal __, result
assert_equal :exception_handled, result

assert_equal __, ex.is_a?(StandardError), "Should be a Standard Error"
assert_equal __, ex.is_a?(RuntimeError), "Should be a Runtime Error"
assert_equal true, ex.is_a?(StandardError), "Should be a Standard Error"
assert_equal true, ex.is_a?(RuntimeError), "Should be a Runtime Error"

assert RuntimeError.ancestors.include?(StandardError),
"RuntimeError is a subclass of StandardError"

assert_equal __, ex.message
assert_equal "Oops", ex.message
end

def test_raising_a_particular_error
Expand All @@ -40,8 +40,8 @@ def test_raising_a_particular_error
result = :exception_handled
end

assert_equal __, result
assert_equal __, ex.message
assert_equal :exception_handled, result
assert_equal "My Message", ex.message
end

def test_ensure_clause
Expand All @@ -54,13 +54,13 @@ def test_ensure_clause
result = :always_run
end

assert_equal __, result
assert_equal :always_run, result
end

# Sometimes, we must know about the unknown
def test_asserting_an_error_is_raised
# A do-end is a block, a topic to explore more later
assert_raise(___) do
assert_raise(MySpecialError) do
raise MySpecialError.new("New instances can be raised directly.")
end
end
Expand Down
8 changes: 8 additions & 0 deletions triangle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def compare(a, b)
end
def triangle(a, b, c)
# WRITE THIS CODE
sides = [a,b,c]
for side in sides
raise TriangleError,"No negative side." if side < 1
if not (a + b > c and b + c > a and a + c > b)
raise TriangleError, "Not a triangle"
end
end

equ = compare(a, compare(b,c))
if equ
:equilateral
Expand Down

0 comments on commit 9944fc1

Please sign in to comment.