From 8ef93f1d3ac5e067f904765c7668327661bb377d Mon Sep 17 00:00:00 2001 From: Jim Weirich Date: Mon, 16 Aug 2010 15:06:12 -0400 Subject: [PATCH] UPdated koans to match latest source. --- koans/Rakefile | 2 +- koans/about_array_assignment.rb | 2 +- koans/about_arrays.rb | 2 +- koans/about_asserts.rb | 2 +- koans/about_blocks.rb | 2 +- koans/about_class_methods.rb | 2 +- koans/about_classes.rb | 10 +++++----- koans/about_constants.rb | 26 +++++++++++++------------- koans/about_control_statements.rb | 2 +- koans/about_dice_project.rb | 2 +- koans/about_exceptions.rb | 2 +- koans/about_hashes.rb | 2 +- koans/about_inheritance.rb | 2 +- koans/about_iteration.rb | 2 +- koans/about_message_passing.rb | 2 +- koans/about_methods.rb | 2 +- koans/about_modules.rb | 2 +- koans/about_nil.rb | 2 +- koans/about_open_classes.rb | 2 +- koans/about_proxy_object_project.rb | 2 +- koans/about_sandwich_code.rb | 2 +- koans/about_scope.rb | 6 +++--- koans/about_scoring_project.rb | 2 +- koans/about_strings.rb | 21 +++++++++++++++------ koans/about_triangle_project.rb | 2 +- koans/about_triangle_project_2.rb | 2 +- koans/about_true_and_false.rb | 2 +- koans/code_mash.rb | 2 +- koans/edgecase.rb | 24 ++++++++++++++++++------ 29 files changed, 78 insertions(+), 57 deletions(-) diff --git a/koans/Rakefile b/koans/Rakefile index 1a2c7f2..171fffe 100644 --- a/koans/Rakefile +++ b/koans/Rakefile @@ -7,6 +7,6 @@ require 'rake/testtask' task :default => :test task :test do - ruby 'path_to_enlightenment.rb' + ruby '-I.', 'path_to_enlightenment.rb' end diff --git a/koans/about_array_assignment.rb b/koans/about_array_assignment.rb index 4e6cfee..12733fb 100644 --- a/koans/about_array_assignment.rb +++ b/koans/about_array_assignment.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutArrayAssignment < EdgeCase::Koan def test_non_parallel_assignment diff --git a/koans/about_arrays.rb b/koans/about_arrays.rb index 9b6b4a6..8dc4dfc 100644 --- a/koans/about_arrays.rb +++ b/koans/about_arrays.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutArrays < EdgeCase::Koan def test_creating_arrays diff --git a/koans/about_asserts.rb b/koans/about_asserts.rb index 53a42aa..e1c34d4 100644 --- a/koans/about_asserts.rb +++ b/koans/about_asserts.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # -*- ruby -*- -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutAsserts < EdgeCase::Koan diff --git a/koans/about_blocks.rb b/koans/about_blocks.rb index 08458f5..1bd2d13 100644 --- a/koans/about_blocks.rb +++ b/koans/about_blocks.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutBlocks < EdgeCase::Koan def method_with_block diff --git a/koans/about_class_methods.rb b/koans/about_class_methods.rb index c768b00..8072166 100644 --- a/koans/about_class_methods.rb +++ b/koans/about_class_methods.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutClassMethods < EdgeCase::Koan class Dog diff --git a/koans/about_classes.rb b/koans/about_classes.rb index d576e4b..08858b8 100644 --- a/koans/about_classes.rb +++ b/koans/about_classes.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutClasses < EdgeCase::Koan class Dog @@ -43,7 +43,7 @@ class AboutClasses < EdgeCase::Koan fido = Dog2.new fido.set_name("Fido") - assert_equal __, fido.instance_variable_get("@name") + assert_equal __, fido.instance_variable_get("@name") end def test_you_can_rip_the_value_out_using_instance_eval @@ -89,7 +89,7 @@ class AboutClasses < EdgeCase::Koan assert_equal __, fido.name end - + # ------------------------------------------------------------------ class Dog5 @@ -125,7 +125,7 @@ class AboutClasses < EdgeCase::Koan # THINK ABOUT IT: # Why is this so? end - + def test_different_objects_have_difference_instance_variables fido = Dog6.new("Fido") rover = Dog6.new("Rover") @@ -186,5 +186,5 @@ class AboutClasses < EdgeCase::Koan assert_equal __, "STRING".to_s assert_equal __, "STRING".inspect end - + end diff --git a/koans/about_constants.rb b/koans/about_constants.rb index ae270ed..0beccdc 100644 --- a/koans/about_constants.rb +++ b/koans/about_constants.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') C = "top level" @@ -20,7 +20,7 @@ class AboutConstants < EdgeCase::Koan end # ------------------------------------------------------------------ - + class Animal LEGS = 4 def legs_in_animal @@ -33,25 +33,25 @@ class AboutConstants < EdgeCase::Koan end end end - + def test_nested_classes_inherit_constants_from_enclosing_classes - assert_equal __, Animal::NestedAnimal.new.legs_in_nested_animal + assert_equal __, Animal::NestedAnimal.new.legs_in_nested_animal end # ------------------------------------------------------------------ - + class Reptile < Animal def legs_in_reptile LEGS end end - + def test_subclasses_inherit_constants_from_parent_classes assert_equal __, Reptile.new.legs_in_reptile end - + # ------------------------------------------------------------------ - + class MyAnimals LEGS = 2 @@ -61,16 +61,16 @@ class AboutConstants < EdgeCase::Koan end end end - + def test_who_wins_with_both_nested_and_inherited_constants assert_equal __, MyAnimals::Bird.new.legs_in_bird end - + # QUESTION: Which has precedence: The constant in the lexical scope, # or the constant from the inheritance heirarachy? - + # ------------------------------------------------------------------ - + class MyAnimals::Oyster < Animal def legs_in_oyster LEGS @@ -83,5 +83,5 @@ class AboutConstants < EdgeCase::Koan # QUESTION: Now Which has precedence: The constant in the lexical # scope, or the constant from the inheritance heirarachy? Why is it - # different? + # different than the previous answer? end diff --git a/koans/about_control_statements.rb b/koans/about_control_statements.rb index 8ecf88e..768dace 100644 --- a/koans/about_control_statements.rb +++ b/koans/about_control_statements.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutControlStatements < EdgeCase::Koan diff --git a/koans/about_dice_project.rb b/koans/about_dice_project.rb index c1fccb1..28066c5 100644 --- a/koans/about_dice_project.rb +++ b/koans/about_dice_project.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class DiceSet attr_reader :values diff --git a/koans/about_exceptions.rb b/koans/about_exceptions.rb index 6604e6c..33b538a 100644 --- a/koans/about_exceptions.rb +++ b/koans/about_exceptions.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutExceptions < EdgeCase::Koan diff --git a/koans/about_hashes.rb b/koans/about_hashes.rb index 05af65a..d491f6d 100644 --- a/koans/about_hashes.rb +++ b/koans/about_hashes.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutHashes < EdgeCase::Koan def test_creating_hashes diff --git a/koans/about_inheritance.rb b/koans/about_inheritance.rb index 01dde2c..cafec34 100644 --- a/koans/about_inheritance.rb +++ b/koans/about_inheritance.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutInheritance < EdgeCase::Koan class Dog diff --git a/koans/about_iteration.rb b/koans/about_iteration.rb index 01808dc..608f1e9 100644 --- a/koans/about_iteration.rb +++ b/koans/about_iteration.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutIteration < EdgeCase::Koan diff --git a/koans/about_message_passing.rb b/koans/about_message_passing.rb index 26e7b66..d6c0bc4 100644 --- a/koans/about_message_passing.rb +++ b/koans/about_message_passing.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutMessagePassing < EdgeCase::Koan diff --git a/koans/about_methods.rb b/koans/about_methods.rb index 7f5c487..ecf7240 100644 --- a/koans/about_methods.rb +++ b/koans/about_methods.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') def my_global_method(a,b) a + b diff --git a/koans/about_modules.rb b/koans/about_modules.rb index c18c81e..c528c32 100644 --- a/koans/about_modules.rb +++ b/koans/about_modules.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutModules < EdgeCase::Koan module Nameable diff --git a/koans/about_nil.rb b/koans/about_nil.rb index af092e2..5e1e28b 100644 --- a/koans/about_nil.rb +++ b/koans/about_nil.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutNil < EdgeCase::Koan def test_nil_is_an_object diff --git a/koans/about_open_classes.rb b/koans/about_open_classes.rb index 233cef5..afef1f9 100644 --- a/koans/about_open_classes.rb +++ b/koans/about_open_classes.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutOpenClasses < EdgeCase::Koan class Dog diff --git a/koans/about_proxy_object_project.rb b/koans/about_proxy_object_project.rb index f3d2a65..a959a80 100644 --- a/koans/about_proxy_object_project.rb +++ b/koans/about_proxy_object_project.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') # Project: Create a Proxy Class # diff --git a/koans/about_sandwich_code.rb b/koans/about_sandwich_code.rb index 37f0c5f..689e901 100644 --- a/koans/about_sandwich_code.rb +++ b/koans/about_sandwich_code.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutUsingBlocks < EdgeCase::Koan diff --git a/koans/about_scope.rb b/koans/about_scope.rb index e616ae0..77fe668 100644 --- a/koans/about_scope.rb +++ b/koans/about_scope.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutScope < EdgeCase::Koan module Jims @@ -28,7 +28,7 @@ class AboutScope < EdgeCase::Koan rover = Joes::Dog.new assert_equal __, fido.identify assert_equal __, rover.identify - + assert_not_equal fido.class, rover.class assert_not_equal Jims::Dog, Joes::Dog end @@ -41,7 +41,7 @@ class AboutScope < EdgeCase::Koan def test_bare_bones_class_names_assume_the_current_scope assert_equal __, AboutScope::String == String end - + def test_nested_string_is_not_the_same_as_the_system_string assert_equal __, String == "HI".class end diff --git a/koans/about_scoring_project.rb b/koans/about_scoring_project.rb index e71423f..2e9c207 100644 --- a/koans/about_scoring_project.rb +++ b/koans/about_scoring_project.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') # Greed is a dice game where you roll up to five dice to accumulate # points. The following "score" function will be used calculate the diff --git a/koans/about_strings.rb b/koans/about_strings.rb index 48190dd..3d9037b 100644 --- a/koans/about_strings.rb +++ b/koans/about_strings.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutStrings < EdgeCase::Koan def test_double_quoted_strings_are_strings @@ -146,11 +146,20 @@ EOS # Surprised? end - def test_single_characters_are_represented_by_integers - assert_equal __, ?a - assert_equal __, ?a == 97 + in_ruby_version("1.8") do + def test_in_ruby_1_8_single_characters_are_represented_by_integers + assert_equal __, ?a + assert_equal __, ?a == 97 - assert_equal __, ?b == (?a + 1) + assert_equal __, ?b == (?a + 1) + end + end + + in_ruby_version("1.9") do + def test_in_ruby_1_8_single_characters_are_represented_by_strings + assert_equal __, ?a + assert_equal __, ?a == 97 + end end def test_strings_can_be_split @@ -166,7 +175,7 @@ EOS # NOTE: Patterns are formed from Regular Expressions. Ruby has a # very powerful Regular Expression library. Unfortunately, time - # does not permit us to explore it in detail in Ruby 101. + # does not permit us to explore it in detail now. end def test_strings_can_be_joined diff --git a/koans/about_triangle_project.rb b/koans/about_triangle_project.rb index 5c1855c..085113b 100644 --- a/koans/about_triangle_project.rb +++ b/koans/about_triangle_project.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') # You need to write the triangle method in the file 'triangle.rb' require 'triangle.rb' diff --git a/koans/about_triangle_project_2.rb b/koans/about_triangle_project_2.rb index 34f7482..f9f3976 100644 --- a/koans/about_triangle_project_2.rb +++ b/koans/about_triangle_project_2.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') # You need to write the triangle method in the file 'triangle.rb' require 'triangle.rb' diff --git a/koans/about_true_and_false.rb b/koans/about_true_and_false.rb index 5192251..d585644 100644 --- a/koans/about_true_and_false.rb +++ b/koans/about_true_and_false.rb @@ -1,4 +1,4 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutTrueAndFalse < EdgeCase::Koan def truth_value(condition) diff --git a/koans/code_mash.rb b/koans/code_mash.rb index 1157de9..8fbf617 100644 --- a/koans/code_mash.rb +++ b/koans/code_mash.rb @@ -1 +1 @@ -require 'edgecase' +require File.expand_path(File.dirname(__FILE__) + '/edgecase') diff --git a/koans/edgecase.rb b/koans/edgecase.rb index acb032b..0f92a6b 100644 --- a/koans/edgecase.rb +++ b/koans/edgecase.rb @@ -6,12 +6,24 @@ require 'test/unit/assertions' class FillMeInError < StandardError end -def __(value="FILL ME IN") - value +def in_ruby_version(version) + yield if RUBY_VERSION =~ /^#{version}/ end -def _n_(value=999999) - value +def __(value="FILL ME IN", value19=:mu) + if RUBY_VERSION < "1.9" + value + else + (value19 == :mu) ? value : value19 + end +end + +def _n_(value=999999, value19=:mu) + if RUBY_VERSION < "1.9" + value + else + (value19 == :mu) ? value : value19 + end end def ___(value=FillMeInError) @@ -104,7 +116,7 @@ module EdgeCase end end end - end + end class Koan include Test::Unit::Assertions @@ -181,7 +193,7 @@ module EdgeCase load(arg) else fail "Unknown command line argument '#{arg}'" - end + end end end end