mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-21 01:03:20 -04:00
Merged src directory with existing koans.
This commit is contained in:
@@ -42,7 +42,6 @@ class AboutArrays < EdgeCase::Koan
|
||||
assert_equal __([]), array[4,0]
|
||||
assert_equal __([]), array[4,100]
|
||||
assert_equal __(nil), array[5,0]
|
||||
assert_equal __(nil), array[5,0]
|
||||
end
|
||||
|
||||
def test_arrays_and_ranges
|
||||
@@ -57,7 +56,7 @@ class AboutArrays < EdgeCase::Koan
|
||||
|
||||
assert_equal __([:peanut, :butter, :and]), array[0..2]
|
||||
assert_equal __([:peanut, :butter]), array[0...2]
|
||||
assert_equal ([:and, :jelly]), array[2..-1]
|
||||
assert_equal __([:and, :jelly]), array[2..-1]
|
||||
end
|
||||
|
||||
def test_pushing_and_popping_arrays
|
||||
|
||||
@@ -7,13 +7,13 @@ class AboutAsserts < EdgeCase::Koan
|
||||
|
||||
# We shall contemplate truth by testing reality, via asserts.
|
||||
def test_assert_truth
|
||||
assert __(true) # 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 __(true), "This should be true -- Please fix this"
|
||||
assert false, "This should be true -- Please fix this"
|
||||
end
|
||||
|
||||
# To understand reality, we must compare our expectations against
|
||||
|
||||
@@ -19,11 +19,11 @@ class AboutClassMethods < EdgeCase::Koan
|
||||
|
||||
def test_objects_have_methods
|
||||
fido = Dog.new
|
||||
assert_equal __(45), fido.methods.size
|
||||
assert_equal __(44), fido.methods.size
|
||||
end
|
||||
|
||||
def test_classes_have_methods
|
||||
assert_equal __(80), Dog.methods.size
|
||||
assert_equal __(79), Dog.methods.size
|
||||
end
|
||||
|
||||
def test_you_can_define_methods_on_individual_objects
|
||||
@@ -34,9 +34,12 @@ class AboutClassMethods < EdgeCase::Koan
|
||||
assert_equal __(:fidos_wag), fido.wag
|
||||
end
|
||||
|
||||
def test_other_objects_are_unaffected_by_these_singleton_methods
|
||||
def test_other_objects_are_not_affected_by_these_singleton_methods
|
||||
fido = Dog.new
|
||||
rover = Dog.new
|
||||
def fido.wag
|
||||
:fidos_wag
|
||||
end
|
||||
|
||||
assert_raise(___(NoMethodError)) do
|
||||
rover.wag
|
||||
@@ -45,24 +48,24 @@ class AboutClassMethods < EdgeCase::Koan
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def Dog.bark
|
||||
:class_level_bark
|
||||
end
|
||||
|
||||
class Dog
|
||||
def bark
|
||||
:instance_level_bark
|
||||
class Dog2
|
||||
def wag
|
||||
:instance_level_wag
|
||||
end
|
||||
end
|
||||
|
||||
def Dog2.wag
|
||||
:class_level_wag
|
||||
end
|
||||
|
||||
def test_since_classes_are_objects_you_can_define_singleton_methods_on_them_too
|
||||
assert_equal __(:class_level_bark), Dog.bark
|
||||
assert_equal __(:class_level_wag), Dog2.wag
|
||||
end
|
||||
|
||||
def test_class_methods_are_independent_of_instance_methods
|
||||
fido = Dog.new
|
||||
assert_equal __(:instance_level_bark), fido.bark
|
||||
assert_equal __(:class_level_bark), Dog.bark
|
||||
fido = Dog2.new
|
||||
assert_equal __(:instance_level_wag), fido.wag
|
||||
assert_equal __(:class_level_wag), Dog2.wag
|
||||
end
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
@@ -155,7 +158,7 @@ class AboutClassMethods < EdgeCase::Koan
|
||||
# end
|
||||
#
|
||||
# Which do you prefer and why?
|
||||
# Are there times you might prefer the other way?
|
||||
# Are there times you might prefer one over the other?
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ class AboutMethods < EdgeCase::Koan
|
||||
def method_with_explicit_return
|
||||
:a_non_return_value
|
||||
return :return_value
|
||||
:anoher_non_return_value
|
||||
:another_non_return_value
|
||||
end
|
||||
|
||||
def test_method_with_explicit_return
|
||||
|
||||
@@ -25,7 +25,7 @@ require 'edgecase'
|
||||
# score([3,4,5,3,3]) => 350 points
|
||||
# score([1,5,1,2,4]) => 250 points
|
||||
#
|
||||
# More scoing examples are given in the tests below:
|
||||
# More scoring examples are given in the tests below:
|
||||
#
|
||||
# Your goal is to write the score method.
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ EOS
|
||||
assert_equal __('The value is #{value}'), string
|
||||
end
|
||||
|
||||
def test_any_ruby_expression_my_be_interpolated
|
||||
def test_any_ruby_expression_may_be_interpolated
|
||||
string = "The square root of 5 is #{Math.sqrt(5)}"
|
||||
assert_equal __("The square root of 5 is 2.23606797749979"), string
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'edgecase'
|
||||
# You need to write the triangle method in the file 'triangle.rb'
|
||||
require 'triangle.rb'
|
||||
|
||||
class AboutTriangleAssignment < EdgeCase::Koan
|
||||
class AboutTriangleAssignment2 < EdgeCase::Koan
|
||||
# The first assignment did not talk about how to handle errors.
|
||||
# Let's handle that part now.
|
||||
def test_illegal_triangles_throw_exceptions
|
||||
|
||||
Reference in New Issue
Block a user