Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
green plz
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-bitbucket authored and anatoliliotych committed Jul 10, 2018
1 parent d5e6f62 commit d844885
Show file tree
Hide file tree
Showing 34 changed files with 4,029 additions and 0 deletions.
53 changes: 53 additions & 0 deletions 2396/1/koans/about_array_assignment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require File.expand_path(File.dirname(__FILE__) + '/neo')

class AboutArrayAssignment < Neo::Koan
def test_non_parallel_assignment
names = %w[John Smith]
assert_equal %w[John Smith], names
end

def test_parallel_assignments
first_name = 'John'
last_name = 'Smith'
assert_equal 'John', first_name
assert_equal 'Smith', last_name
end

def test_parallel_assignments_with_extra_values
first_name, last_name = %w[John Smith III]
assert_equal 'John', first_name
assert_equal 'Smith', last_name
end

def test_parallel_assignments_with_splat_operator
first_name, *last_name = %w[John Smith III]
assert_equal 'John', first_name
assert_equal %w[Smith III], last_name
end

def test_parallel_assignments_with_too_few_variables
first_name, last_name = %w[Cher]
assert_equal 'Cher', first_name
assert_equal nil, last_name
end

def test_parallel_assignments_with_subarrays
first_name = %w[Willie Rae]
last_name = 'Johnson'
assert_equal %w[Willie Rae], first_name
assert_equal 'Johnson', last_name
end

def test_parallel_assignment_with_one_variable
first_name, = %w[John Smith]
assert_equal 'John', first_name
end

def test_swapping_with_parallel_assignment
first_name = 'Roy'
last_name = 'Rob'
first_name, last_name = last_name, first_name
assert_equal 'Rob', first_name
assert_equal 'Roy', last_name
end
end
116 changes: 116 additions & 0 deletions 2396/1/koans/about_arrays.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
require File.expand_path(File.dirname(__FILE__) + '/neo')

# This class smells of :reek:UncommunicativeModuleName
class AboutArrays < Neo::Koan
# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_creating_arrays
empty_array = []
assert_equal Array, empty_array.class
assert_equal 0, empty_array.size
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_array_literals
array = []
assert_equal [], array

array[0] = 1
assert_equal [1], array

array[1] = 2
assert_equal [1, 2], array

array << 333
assert_equal [1, 2, 333], array
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_accessing_array_elements
array = %i[peanut butter and jelly]

assert_equal :peanut, array[0]
assert_equal :peanut, array.first
assert_equal :jelly, array[3]
assert_equal :jelly, array.last
assert_equal :jelly, array[-1]
assert_equal :butter, array[-3]
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_slicing_arrays
array = %i[peanut butter and jelly]

assert_equal %i[peanut], array[0, 1]
assert_equal %i[peanut butter], array[0, 2]
assert_equal %i[and jelly], array[2, 2]
assert_equal %i[and jelly], array[2, 20]
assert_equal [], array[4, 0]
assert_equal [], array[4, 100]
assert_equal nil, array[5, 0]
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_arrays_and_ranges
assert_equal Range, (1..5).class
assert_not_equal [1, 2, 3, 4, 5], (1..5)
assert_equal [1, 2, 3, 4, 5], (1..5).to_a
assert_equal [1, 2, 3, 4], (1...5).to_a
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_slicing_with_ranges
array = %i[peanut butter and jelly]

assert_equal %i[peanut butter and], array[0..2]
assert_equal %i[peanut butter], array[0...2]
assert_equal %i[and jelly], array[2..-1]
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_pushing_and_popping_arrays
array = [1, 2]
array.push(:last)

assert_equal [1, 2, :last], array

popped_value = array.pop
assert_equal :last, popped_value
assert_equal [1, 2], array
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_shifting_arrays
array = [1, 2]
array.unshift(:first)

assert_equal [:first, 1, 2], array

shifted_value = array.shift
assert_equal :first, shifted_value
assert_equal [1, 2], array
end
end
38 changes: 38 additions & 0 deletions 2396/1/koans/about_asserts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- ruby -*-

require File.expand_path(File.dirname(__FILE__) + '/neo')

class AboutAsserts < Neo::Koan
# We shall contemplate truth by testing reality, via asserts.
def test_assert_truth
assert 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'
end

# To understand reality, we must compare our expectations against
# reality.
def test_assert_equality
expected_value = 2
actual_value = 1 + 1

assert expected_value == actual_value
end

# Some ways of asserting equality are better than others.
def test_a_better_way_of_asserting_equality
expected_value = 2
actual_value = 1 + 1

assert_equal expected_value, actual_value
end

# Sometimes we will ask you to fill in the values
def test_fill_in_values
assert_equal 2, 1 + 1
end
end
132 changes: 132 additions & 0 deletions 2396/1/koans/about_blocks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
require File.expand_path(File.dirname(__FILE__) + '/neo')

# This class smells of :reek:UncommunicativeModuleName
class AboutBlocks < Neo::Koan
def method_with_block
result = yield
result
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_methods_can_take_blocks
yielded_result = method_with_block { 1 + 2 }
assert_equal 3, yielded_result
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_blocks_can_be_defined_with_do_end_too
yielded_result = method_with_block { 1 + 2 }
assert_equal 3, yielded_result
end

# ------------------------------------------------------------------

def method_with_block_arguments
yield('Jim')
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_blocks_can_take_arguments
method_with_block_arguments do |argument|
assert_equal 'Jim', argument
end
end

# ------------------------------------------------------------------

def many_yields
yield(:peanut)
yield(:butter)
yield(:and)
yield(:jelly)
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_methods_can_call_yield_many_times
result = []
success_result = %i[peanut butter and jelly]
many_yields { |item| result << item }
assert_equal success_result, result
end

# ------------------------------------------------------------------

def yield_tester
if block_given?
yield
else
:no_block
end
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_methods_can_see_if_they_have_been_called_with_a_block
assert_equal(:with_block, yield_tester { :with_block })
assert_equal :no_block, yield_tester
end

# ------------------------------------------------------------------

def test_block_can_affect_variables_in_the_code_where_they_are_created
value = :initial_value
method_with_block { value = :modified_in_a_block }
assert_equal :modified_in_a_block, value
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_blocks_can_be_assigned_to_variables_and_called_explicitly
add_one = ->(n) { n + 1 }
assert_equal 11, add_one.call(10)

# Alternative calling syntax
assert_equal 11, add_one[10]
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_stand_alone_blocks_can_be_passed_to_methods_expecting_blocks
make_upper = ->(n) { n.upcase }
result = method_with_block_arguments(&make_upper)
assert_equal 'JIM', result
end

# ------------------------------------------------------------------
# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def method_with_explicit_block
yield(10)
end

# This method smells of :reek:UncommunicativeMethodName
# This method smells of :reek:UncommunicativeVariableName
# This method smells of :reek:TooManyStatements
# This method smells of :reek:FeatureEnvy
def test_methods_can_take_an_explicit_block_argument
assert_equal(20, method_with_explicit_block { |n| n * 2 })

add_one = ->(n) { n + 1 }
assert_equal 11, method_with_explicit_block(&add_one)
end
end
Loading

0 comments on commit d844885

Please sign in to comment.