Skip to content

Commit

Permalink
Almost finished.
Browse files Browse the repository at this point in the history
  • Loading branch information
elvinlucero committed Feb 13, 2013
1 parent addfed0 commit 52c137d
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .path_progress
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0,0,1,5,6,6,6,6,6,6,6,6,7,7,7,8,8,8,9,10,10,11,11,11,13,13,13,14,15,16,18,19,19,19,19,19,19,19,19,20,21,21,22,23,24,25,26,27,27,29,31,31,32,32,33,35,35,35,35,35,35,35,35,35,35,38,40,41,41,41,42,42,42,43,43,44,45,46,49,50,50,50,50,51,52,53,53,55,58,59,60,61,62,62,63,64,64,64,65,66,66,66,69,71,71,71,71,71,75,79,75,79,75,79,82,83,84,84,84,84,84,85,88,90,92,93,94,95,97,98,98,99,99,99,102,103,103,106,106,106,107,107,108,109,111,111,112,114,114,114,114,114,115,115,114,115,116,116,117,117,117,119,121,122,122,122,123,125,125,125,125,125,131,132,135,136,137,141,141,144,144,146,149,149,150,153,153,153,152,153,153,153,153,153,153,153,154,156,156,158,158,158,158,150,159,159,163,165,166,166,167,168,168,168,173,174,176,177,178,181,182,182,182,182,183,183,182,182,182,183,184,184,188,188,183,190,188,190,190,182,190
0,0,1,5,6,6,6,6,6,6,6,6,7,7,7,8,8,8,9,10,10,11,11,11,13,13,13,14,15,16,18,19,19,19,19,19,19,19,19,20,21,21,22,23,24,25,26,27,27,29,31,31,32,32,33,35,35,35,35,35,35,35,35,35,35,38,40,41,41,41,42,42,42,43,43,44,45,46,49,50,50,50,50,51,52,53,53,55,58,59,60,61,62,62,63,64,64,64,65,66,66,66,69,71,71,71,71,71,75,79,75,79,75,79,82,83,84,84,84,84,84,85,88,90,92,93,94,95,97,98,98,99,99,99,102,103,103,106,106,106,107,107,108,109,111,111,112,114,114,114,114,114,115,115,114,115,116,116,117,117,117,119,121,122,122,122,123,125,125,125,125,125,131,132,135,136,137,141,141,144,144,146,149,149,150,153,153,153,152,153,153,153,153,153,153,153,154,156,156,158,158,158,158,150,159,159,163,165,166,166,167,168,168,168,173,174,176,177,178,181,182,182,182,182,183,183,182,182,182,183,184,184,188,188,183,190,188,190,190,182,190,190,190,190,191,191,192,192,195,196,199,201,201,201,201,201,201,203,204,205,205,205,206,207,209,210,210,214,218,219,220,221,221,221,222,226,226,226,227,228,228,230,232,233,234,234,234,235,235,235,241,241,241,242,244,244,247,249,253,253,253,253,253,254,256,256,256,257,259,259,260,262,263,265
36 changes: 18 additions & 18 deletions about_class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@ class Dog

def test_objects_are_objects
fido = Dog.new
assert_equal __, fido.is_a?(Object)
assert_equal true, fido.is_a?(Object)
end

def test_classes_are_classes
assert_equal __, Dog.is_a?(Class)
assert_equal true, Dog.is_a?(Class)
end

def test_classes_are_objects_too
assert_equal __, Dog.is_a?(Object)
assert_equal true, Dog.is_a?(Object)
end

def test_objects_have_methods
fido = Dog.new
assert fido.methods.size > _n_
assert fido.methods.size > 1
end

def test_classes_have_methods
assert Dog.methods.size > _n_
assert Dog.methods.size > 1
end

def test_you_can_define_methods_on_individual_objects
fido = Dog.new
def fido.wag
:fidos_wag
end
assert_equal __, fido.wag
assert_equal :fidos_wag, fido.wag
end

def test_other_objects_are_not_affected_by_these_singleton_methods
Expand All @@ -41,7 +41,7 @@ def fido.wag
:fidos_wag
end

assert_raise(___) do
assert_raise(NoMethodError) do
rover.wag
end
end
Expand All @@ -59,13 +59,13 @@ def Dog2.wag
end

def test_since_classes_are_objects_you_can_define_singleton_methods_on_them_too
assert_equal __, Dog2.wag
assert_equal :class_level_wag, Dog2.wag
end

def test_class_methods_are_independent_of_instance_methods
fido = Dog2.new
assert_equal __, fido.wag
assert_equal __, Dog2.wag
assert_equal :instance_level_wag, fido.wag
assert_equal :class_level_wag, Dog2.wag
end

# ------------------------------------------------------------------
Expand All @@ -81,8 +81,8 @@ def Dog.name
def test_classes_and_instances_do_not_share_instance_variables
fido = Dog.new
fido.name = "Fido"
assert_equal __, fido.name
assert_equal __, Dog.name
assert_equal "Fido", fido.name
assert_equal nil, Dog.name
end

# ------------------------------------------------------------------
Expand All @@ -94,7 +94,7 @@ def Dog.a_class_method
end

def test_you_can_define_class_methods_inside_the_class
assert_equal __, Dog.a_class_method
assert_equal :dogs_class_method, Dog.a_class_method
end

# ------------------------------------------------------------------
Expand All @@ -104,7 +104,7 @@ def test_you_can_define_class_methods_inside_the_class
end

def test_class_statements_return_the_value_of_their_last_expression
assert_equal __, LastExpressionInClassStatement
assert_equal 21, LastExpressionInClassStatement
end

# ------------------------------------------------------------------
Expand All @@ -114,7 +114,7 @@ def test_class_statements_return_the_value_of_their_last_expression
end

def test_self_while_inside_class_is_class_object_not_instance
assert_equal __, Dog == SelfInsideOfClassStatement
assert_equal true, Dog == SelfInsideOfClassStatement
end

# ------------------------------------------------------------------
Expand All @@ -126,7 +126,7 @@ def self.class_method2
end

def test_you_can_use_self_instead_of_an_explicit_reference_to_dog
assert_equal __, Dog.class_method2
assert_equal :another_way_to_write_class_methods, Dog.class_method2
end

# ------------------------------------------------------------------
Expand All @@ -140,7 +140,7 @@ def another_class_method
end

def test_heres_still_another_way_to_write_class_methods
assert_equal __, Dog.another_class_method
assert_equal :still_another_way, Dog.another_class_method
end

# THINK ABOUT IT:
Expand All @@ -163,7 +163,7 @@ def test_heres_still_another_way_to_write_class_methods

def test_heres_an_easy_way_to_call_class_methods_from_instance_methods
fido = Dog.new
assert_equal __, fido.class.another_class_method
assert_equal :still_another_way, fido.class.another_class_method
end

end
46 changes: 23 additions & 23 deletions about_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Dog

def test_instances_of_classes_can_be_created_with_new
fido = Dog.new
assert_equal __, fido.class
assert_equal Dog, fido.class
end

# ------------------------------------------------------------------
Expand All @@ -19,21 +19,21 @@ def set_name(a_name)

def test_instance_variables_can_be_set_by_assigning_to_them
fido = Dog2.new
assert_equal __, fido.instance_variables
assert_equal [], fido.instance_variables

fido.set_name("Fido")
assert_equal __, fido.instance_variables
assert_equal [:@name], fido.instance_variables
end

def test_instance_variables_cannot_be_accessed_outside_the_class
fido = Dog2.new
fido.set_name("Fido")

assert_raise(___) do
assert_raise(NoMethodError) do
fido.name
end

assert_raise(___) do
assert_raise(SyntaxError) do
eval "fido.@name"
# NOTE: Using eval because the above line is a syntax error.
end
Expand All @@ -43,15 +43,15 @@ def test_you_can_politely_ask_for_instance_variable_values
fido = Dog2.new
fido.set_name("Fido")

assert_equal __, fido.instance_variable_get("@name")
assert_equal "Fido", fido.instance_variable_get("@name")
end

def test_you_can_rip_the_value_out_using_instance_eval
fido = Dog2.new
fido.set_name("Fido")

assert_equal __, fido.instance_eval("@name") # string version
assert_equal __, fido.instance_eval { @name } # block version
assert_equal "Fido", fido.instance_eval("@name") # string version
assert_equal "Fido", fido.instance_eval { @name } # block version
end

# ------------------------------------------------------------------
Expand All @@ -69,7 +69,7 @@ def test_you_can_create_accessor_methods_to_return_instance_variables
fido = Dog3.new
fido.set_name("Fido")

assert_equal __, fido.name
assert_equal "Fido", fido.name
end

# ------------------------------------------------------------------
Expand All @@ -87,7 +87,7 @@ def test_attr_reader_will_automatically_define_an_accessor
fido = Dog4.new
fido.set_name("Fido")

assert_equal __, fido.name
assert_equal "Fido", fido.name
end

# ------------------------------------------------------------------
Expand All @@ -101,7 +101,7 @@ def test_attr_accessor_will_automatically_define_both_read_and_write_accessors
fido = Dog5.new

fido.name = "Fido"
assert_equal __, fido.name
assert_equal "Fido", fido.name
end

# ------------------------------------------------------------------
Expand All @@ -115,11 +115,11 @@ def initialize(initial_name)

def test_initialize_provides_initial_values_for_instance_variables
fido = Dog6.new("Fido")
assert_equal __, fido.name
assert_equal "Fido", fido.name
end

def test_args_to_new_must_match_initialize
assert_raise(___) do
assert_raise(ArgumentError) do
Dog6.new
end
# THINK ABOUT IT:
Expand All @@ -130,7 +130,7 @@ def test_different_objects_have_different_instance_variables
fido = Dog6.new("Fido")
rover = Dog6.new("Rover")

assert_equal __, rover.name != fido.name
assert_equal true, rover.name != fido.name
end

# ------------------------------------------------------------------
Expand All @@ -147,7 +147,7 @@ def get_self
end

def to_s
__
@name
end

def inspect
Expand All @@ -159,32 +159,32 @@ def test_inside_a_method_self_refers_to_the_containing_object
fido = Dog7.new("Fido")

fidos_self = fido.get_self
assert_equal __, fidos_self
assert_equal fido, fidos_self
end

def test_to_s_provides_a_string_version_of_the_object
fido = Dog7.new("Fido")
assert_equal __, fido.to_s
assert_equal "Fido", fido.to_s
end

def test_to_s_is_used_in_string_interpolation
fido = Dog7.new("Fido")
assert_equal __, "My dog is #{fido}"
assert_equal "My dog is Fido", "My dog is #{fido}"
end

def test_inspect_provides_a_more_complete_string_version
fido = Dog7.new("Fido")
assert_equal __, fido.inspect
assert_equal "<Dog named 'Fido'>", fido.inspect
end

def test_all_objects_support_to_s_and_inspect
array = [1,2,3]

assert_equal __, array.to_s
assert_equal __, array.inspect
assert_equal "[1, 2, 3]", array.to_s
assert_equal "[1, 2, 3]", array.inspect

assert_equal __, "STRING".to_s
assert_equal __, "STRING".inspect
assert_equal "STRING", "STRING".to_s
assert_equal "\"STRING\"", "STRING".inspect
end

end
14 changes: 14 additions & 0 deletions about_dice_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
# code ...
# end

class DiceSet
attr_accessor :values
def roll(n)
rng = Random.new()
@values = []
i = 0
while i < n
@values << rng.rand(1..6)
i += 1
end
@values
end
end

class AboutDiceProject < EdgeCase::Koan
def test_can_create_a_dice_set
dice = DiceSet.new
Expand Down
18 changes: 9 additions & 9 deletions about_inheritance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,34 @@ def bark
end

def test_subclasses_have_the_parent_as_an_ancestor
assert_equal __, Chihuahua.ancestors.include?(Dog)
assert_equal true, Chihuahua.ancestors.include?(Dog)
end

def test_all_classes_ultimately_inherit_from_object
assert_equal __, Chihuahua.ancestors.include?(Object)
assert_equal true, Chihuahua.ancestors.include?(Object)
end

def test_subclasses_inherit_behavior_from_parent_class
chico = Chihuahua.new("Chico")
assert_equal __, chico.name
assert_equal "Chico", chico.name
end

def test_subclasses_add_new_behavior
chico = Chihuahua.new("Chico")
assert_equal __, chico.wag
assert_equal :happy, chico.wag

assert_raise(___) do
assert_raise(NoMethodError) do
fido = Dog.new("Fido")
fido.wag
end
end

def test_subclasses_can_modify_existing_behavior
chico = Chihuahua.new("Chico")
assert_equal __, chico.bark
assert_equal "yip", chico.bark

fido = Dog.new("Fido")
assert_equal __, fido.bark
assert_equal "WOOF", fido.bark
end

# ------------------------------------------------------------------
Expand All @@ -64,7 +64,7 @@ def bark

def test_subclasses_can_invoke_parent_behavior_via_super
ralph = BullDog.new("Ralph")
assert_equal __, ralph.bark
assert_equal "WOOF, GROWL", ralph.bark
end

# ------------------------------------------------------------------
Expand All @@ -77,7 +77,7 @@ def growl

def test_super_does_not_work_cross_method
george = GreatDane.new("George")
assert_raise(___) do
assert_raise(NoMethodError) do
george.growl
end
end
Expand Down
Loading

0 comments on commit 52c137d

Please sign in to comment.