Add koan addressing Hash#fetch.
# Why is this so?
end
- def test_different_objects_have_difference_instance_variables
+ def test_different_objects_have_different_instance_variables
fido = Dog6.new("Fido")
rover = Dog6.new("Rover")
def test_unless_statement
result = :default_value
- unless false
+ unless false # same as saying 'if !false', which evaluates as 'if true'
result = :false_value
end
assert_equal __, result
end
+ def test_unless_statement_evaluate_true
+ result = :default_value
+ unless true # same as saying 'if !true', which evaluates as 'if false'
+ result = :true_value
+ end
+ assert_equal __, result
+ end
+
def test_unless_statement_modifier
result = :default_value
result = :false_value unless false
assert_equal __, hash2[:one]
assert_equal __, hash2[:two]
end
+
+ def test_default_value_is_the_same_object
+ hash = Hash.new([])
+
+ hash[:one] << "uno"
+ hash[:two] << "dos"
+
+ assert_equal __, hash[:one]
+ assert_equal __, hash[:two]
+ assert_equal __, hash[:three]
+
+ assert_equal __, hash[:one].object_id == hash[:two].object_id
+ end
+
+ def test_default_value_with_block
+ hash = Hash.new {|hash, key| hash[key] = [] }
+
+ hash[:one] << "uno"
+ hash[:two] << "dos"
+
+ assert_equal __, hash[:one]
+ assert_equal __, hash[:two]
+ assert_equal __, hash[:three]
+ end
end
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutIteration < EdgeCase::Koan
+ in_ruby_version("1.8") do
+ def test_each_is_a_method_on_arrays
+ assert_equal __, [].methods.include?("each")
+ end
+ end
- def test_each_is_a_method_on_arrays
- assert_equal __, [].methods.include?(:each)
+ in_ruby_version("1.9") do
+ def test_each_is_a_method_on_arrays
+ assert_equal __, [].methods.include?(:each)
+ end
end
def test_iterating_with_each
end
def test_calling_with_variable_arguments
+ assert_equal __, method_with_var_args.class
assert_equal __, method_with_var_args
assert_equal __, method_with_var_args(:one)
assert_equal __, method_with_var_args(:one, :two)
def test_shortcut_character_classes_are_negated_with_capitals
assert_equal __, "the number is 42"[/\D+/]
assert_equal __, "space: \t\n"[/\S+/]
+ # ... a programmer would most likely do
+ assert_equal __, "variable_1 = 42"[/[^a-zA-Z0-9_]+/]
assert_equal __, "variable_1 = 42"[/\W+/]
end