Permalink
Browse files

first session

  • Loading branch information...
1 parent 3fd8d9d commit 2e8a49e075d6a5593b18a4c9bbf109a190cdb6e8 @derwiki committed Apr 7, 2011
Showing with 32 additions and 31 deletions.
  1. +5 −5 koans/about_asserts.rb
  2. +6 −6 koans/about_nil.rb
  3. +21 −20 koans/about_objects.rb
View
@@ -7,34 +7,34 @@ class AboutAsserts < EdgeCase::Koan
# We shall contemplate truth by testing reality, via asserts.
def test_assert_truth
- assert false # This should be true
+ assert true # This should be true
end
# Enlightenment may be more easily achieved with appropriate
# messages.
def test_assert_with_message
- assert false, "This should be true -- Please fix this"
+ assert true, "This should be true -- Please fix this"
end
# To understand reality, we must compare our expectations against
# reality.
def test_assert_equality
- expected_value = __
+ expected_value = 2
actual_value = 1 + 1
assert expected_value == actual_value
end
# Some ways of asserting equality are better than others.
def test_a_better_way_of_asserting_equality
- expected_value = __
+ expected_value = 2
actual_value = 1 + 1
assert_equal expected_value, actual_value
end
# Sometimes we will ask you to fill in the values
def test_fill_in_values
- assert_equal __, 1 + 1
+ assert_equal 2, 1 + 1
end
end
View
@@ -2,7 +2,7 @@
class AboutNil < EdgeCase::Koan
def test_nil_is_an_object
- assert_equal __, nil.is_a?(Object), "Unlike NULL in other languages"
+ assert_equal true, nil.is_a?(Object), "Unlike NULL in other languages"
end
def test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil
@@ -13,18 +13,18 @@ def test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil
nil.some_method_nil_doesnt_know_about
rescue Exception => ex
# What exception has been caught?
- assert_equal __, ex.class
+ assert_equal NoMethodError, ex.class
# What message was attached to the exception?
# (HINT: replace __ with part of the error message.)
- assert_match(/__/, ex.message)
+ assert_match(/some_method_nil_doesnt_know_about/, ex.message)
end
end
def test_nil_has_a_few_methods_defined_on_it
- assert_equal __, nil.nil?
- assert_equal __, nil.to_s
- assert_equal __, nil.inspect
+ assert_equal true, nil.nil?
+ assert_equal "", nil.to_s
+ assert_equal "nil", nil.inspect
# THINK ABOUT IT:
#
View
@@ -2,55 +2,56 @@
class AboutObjects < EdgeCase::Koan
def test_everything_is_an_object
- assert_equal __, 1.is_a?(Object)
- assert_equal __, 1.5.is_a?(Object)
- assert_equal __, "string".is_a?(Object)
- assert_equal __, nil.is_a?(Object)
- assert_equal __, Object.is_a?(Object)
+ assert_equal true, 1.is_a?(Object)
+ assert_equal true, 1.5.is_a?(Object)
+ assert_equal true, "string".is_a?(Object)
+ assert_equal true, nil.is_a?(Object)
+ assert_equal true, Object.is_a?(Object)
end
def test_objects_can_be_converted_to_strings
- assert_equal __, 123.to_s
- assert_equal __, nil.to_s
+ assert_equal '123', 123.to_s
+ assert_equal '', nil.to_s
end
def test_objects_can_be_inspected
- assert_equal __, 123.inspect
- assert_equal __, nil.inspect
+ assert_equal "123", 123.inspect
+ assert_equal "nil", nil.inspect
end
def test_every_object_has_an_id
obj = Object.new
- assert_equal __, obj.object_id.class
+ assert_equal Fixnum, obj.object_id.class
end
def test_every_object_has_different_id
obj = Object.new
another_obj = Object.new
- assert_equal __, obj.object_id != another_obj.object_id
+ assert_equal true, obj.object_id != another_obj.object_id
end
def test_some_system_objects_always_have_the_same_id
- assert_equal __, false.object_id
- assert_equal __, true.object_id
- assert_equal __, nil.object_id
+ assert_equal 0, false.object_id
+ assert_equal 2, true.object_id
+ assert_equal 4, nil.object_id
end
def test_small_integers_have_fixed_ids
- assert_equal __, 0.object_id
- assert_equal __, 1.object_id
- assert_equal __, 2.object_id
- assert_equal __, 100.object_id
+ assert_equal 1, 0.object_id
+ assert_equal 3, 1.object_id
+ assert_equal 5, 2.object_id
+ assert_equal 201, 100.object_id
# THINK ABOUT IT:
# What pattern do the object IDs for small integers follow?
+ # 2n+1 but the significance is lost on me
end
def test_clone_creates_a_different_object
obj = Object.new
copy = obj.clone
- assert_equal __, obj != copy
- assert_equal __, obj.object_id != copy.object_id
+ assert_equal true , obj != copy
+ assert_equal true, obj.object_id != copy.object_id
end
end

0 comments on commit 2e8a49e

Please sign in to comment.