Back ported a lot of changes made to the Koans directory.

Evidently, a lot of changes / pull requests were made to the koans
directory and not to the src directory.  Perhaps we should remove the
koans directory entirely from the repo.
This commit is contained in:
Jim Weirich
2011-12-04 02:00:22 -05:00
parent 51acb84736
commit 6592f3d36e
16 changed files with 145 additions and 81 deletions

View File

@@ -117,7 +117,7 @@ class AboutControlStatements < EdgeCase::Koan
while i < 10
i += 1
next if (i % 2) == 0
result << i
result << i
end
assert_equal __, result
end

View File

@@ -27,51 +27,52 @@ class AboutProxyObjectProject < EdgeCase::Koan
def test_proxy_method_returns_wrapped_object
# NOTE: The Television class is defined below
tv = Proxy.new(Television.new)
# HINT: Proxy class is defined above, may need tweaking...
assert tv.instance_of?(Proxy)
end
def test_tv_methods_still_perform_their_function
tv = Proxy.new(Television.new)
# HINT Proxy class is defined above, may need tweaking...
tv.channel = 10
tv.power
assert_equal 10, tv.channel
assert tv.on?
end
def test_proxy_records_messages_sent_to_tv
tv = Proxy.new(Television.new)
tv.power
tv.channel = 10
assert_equal [:power, :channel=], tv.messages
end
def test_proxy_handles_invalid_messages
tv = Proxy.new(Television.new)
assert_raise(NoMethodError) do
tv.no_such_method
end
end
def test_proxy_reports_methods_have_been_called
tv = Proxy.new(Television.new)
tv.power
tv.power
assert tv.called?(:power)
assert ! tv.called?(:channel)
end
def test_proxy_counts_method_calls
tv = Proxy.new(Television.new)
tv.power
tv.channel = 48
tv.power
@@ -100,7 +101,7 @@ end
# Example class using in the proxy testing above.
class Television
attr_accessor :channel
def power
if @power == :on
@power = :off
@@ -108,7 +109,7 @@ class Television
@power = :on
end
end
def on?
@power == :on
end
@@ -118,31 +119,31 @@ end
class TelevisionTest < EdgeCase::Koan
def test_it_turns_on
tv = Television.new
tv.power
assert tv.on?
end
def test_it_also_turns_off
tv = Television.new
tv.power
tv.power
assert ! tv.on?
end
def test_edge_case_on_off
tv = Television.new
tv.power
tv.power
tv.power
assert tv.on?
tv.power
assert ! tv.on?
end

View File

@@ -141,6 +141,13 @@ EOS
assert_equal __, string[7..9]
end
def test_you_can_get_a_single_character_from_a_string
string = "Bacon, lettuce and tomato"
assert_equal __, string[1]
# Surprised?
end
in_ruby_version("1.8") do
def test_in_ruby_1_8_single_characters_are_represented_by_integers
assert_equal __, ?a
@@ -157,26 +164,6 @@ EOS
end
end
in_ruby_version("1.8") do
def test_in_ruby_1_8_you_can_get_a_single_character_from_a_string
string = "Bacon, lettuce and tomato"
assert_equal __, string[1]
# Surprised?
end
end
in_ruby_version("1.9") do
def test_in_ruby_1_9_you_can_get_a_single_character_from_a_string
string = "Bacon, lettuce and tomato"
assert_equal "__", string[1]
# Surprised?
end
end
def test_strings_can_be_split
string = "Sausage Egg Cheese"
words = string.split

View File

@@ -84,7 +84,7 @@ class AboutSymbols < EdgeCase::Koan
# interesting string operations are available on symbols.
def test_symbols_cannot_be_concatenated
# Exceptions will be pondered further farther down the path
# Exceptions will be pondered further down the path
assert_raise(___) do
:cats + :dogs
end

View File

@@ -11,7 +11,7 @@ class AboutTriangleProject2 < EdgeCase::Koan
assert_raise(TriangleError) do triangle(3, 4, -5) end
assert_raise(TriangleError) do triangle(1, 1, 3) end
assert_raise(TriangleError) do triangle(2, 4, 2) end
#HINT: for tips, see http://stackoverflow.com/questions/3834203/ruby-koan-151-raising-exceptions
# HINT: for tips, see http://stackoverflow.com/questions/3834203/ruby-koan-151-raising-exceptions
end
end

View File

@@ -2,10 +2,11 @@
# -*- ruby -*-
require 'test/unit/assertions'
begin
begin
require 'win32console'
rescue LoadError
end
# --------------------------------------------------------------------
# Support code for the Ruby Koans.
# --------------------------------------------------------------------
@@ -121,6 +122,7 @@ module EdgeCase
def using_windows?
File::ALT_SEPARATOR
end
def using_win32console
defined? Win32::Console
end