Разпарчетосване

Краен срок
31.10.2013 12:00

Срокът за предаване на решения е отминал

Из третото предизвикателство:

Понеже ви казахме, че Monkey patching-а е нещо, което трябва да се избягва по принцип, решихме отново да ви накараме да го приложите. :-)

С цел да не ви става навик, отново ви даваме Monkey patching :-)

Дефинирайте метод Enumerable#split_up, който приема следните keyword аргументи:

  • length: - задължителен.
  • step: - по подразбиране равен на стойността на параметъра length.
  • pad: - по подразбиране празен списък.

Връща Array, съдържащ списъци (парчета) от по length елемента всеки:

1.upto(10).split_up(length: 3)
=> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]

Ако step е подаден, то елементите за всяко следващо парче започват да се взимат от позиция със стъпка step. По подразбиране step е равно на length:

1.upto(10).split_up(length: 2, step: 4)
=> [[1, 2], [5, 6], [9, 10]]

Ако се подаде списък pad, то елементите му се използват за плънка към последното парче, ако не му достигат елементи. В случай, че в pad няма достатъчно елементи, се връща парче с по-малко от length елемента:

1.upto(10).split_up(length: 3, pad: [:a, :b, :c])
=> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :a, :b]]

Детайли

  • Ако pad не е подаден и последното парче е с по-малко от length елемента, то парчето остава както си е.

      1.upto(10).split_up(length: 2, step: 3)
      => [[1, 2], [4, 5], [7, 8], [10]]
    
  • Методът трябва да работи и ако му бъде подаден блок, като на блока се yield-ва всяко парче от резултатната последователност. В този случай, върнатата стойност от split_up не се променя по никакъв начин, освен ако съзнателно не мутирате yield-нато парче в блока. Например, ако го извикаме по следния начин:

      1.upto(5).split_up(length: 2) { |slice| puts 'Got ' + slice.inspect }
    

    Ще очакваме целият израз да изведе на екрана следното, като след това върне [[1, 2], [3, 4], [5]]:

      Got [1, 2]
      Got [3, 4]
      Got [5]
    
  • Понеже е в Enumerable, методът ще се вика върху колекции. Ще тестваме за хеш и списък.

  • Методът няма да се вика с length > step.

Още примери

1.upto(10).split_up(length: 2, step: 3, pad: [:a, :b, :c])
=> [[1, 2], [4, 5], [7, 8], [10, :a]]

1.upto(10).split_up(length: 2)
=> [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]

{ one: 1, two: 2, three: 3, four: 4 }.split_up(length: 2)
=> [[[:one, 1], [:two, 2]], [[:three, 3], [:four, 4]]]

Решения

Георги Ангелов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Ангелов
module Enumerable
def tap_each(&block)
each &block if block_given?
self
end
def split_up(length:, step: length, pad: [], &block)
each_slice(step).map { |slice| slice.concat(pad).take(length) }.tap_each(&block)
end
end
.........

Finished in 0.22587 seconds
9 examples, 0 failures
Иван Проданов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Проданов
module Enumerable
def split_up (length:, step:length, pad:[])
each_slice(step).each_with_object([]) do |slice, result|
result << bite = slice.take(length) + pad.take(length - slice.take(length).length)
yield bite if block_given?
end
end
end
.........

Finished in 0.19513 seconds
9 examples, 0 failures
Емануела Моллова
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Емануела Моллова
module Enumerable
def split_up(length:, step: length, pad: [])
cultivate_slice = ->(slice) { (slice + pad).first(length) }
(each_slice(step).map &cultivate_slice).each { |slice| yield slice if block_given? }
end
end
.........

Finished in 0.1958 seconds
9 examples, 0 failures
Любомир Георгиев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Георгиев
module Enumerable
def split_up(length:, step: length, pad: [])
self.each_slice(step).to_a.map { |a| a.concat(pad).take(length) }.each{ |a| yield a if block_given? }
end
end
.........

Finished in 0.21105 seconds
9 examples, 0 failures
Слав Керемидчиев
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Слав Керемидчиев
module Enumerable
def split_up(length:, step: length, pad: [], &block)
before_split_up_array = to_a
if (size % step < length and !pad.empty?)
before_split_up_array.concat pad.take(length - size % step)
end
split_up_array = before_split_up_array.each_slice(step).to_a.map do |slice|
slice.take(length)
end
split_up_array.each(&block)
split_up_array
end
end
...F.....

Failures:

  1) Enumerable#split_up does not mutate the input enumerable
     Failure/Error: numbers_list.should eq [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
       
       expected: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
            got: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, :a]
       
       (compared using ==)
     # /tmp/d20131106-4393-1hfopiy/spec.rb:25:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.25602 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20131106-4393-1hfopiy/spec.rb:23 # Enumerable#split_up does not mutate the input enumerable
Диан Николов
  • Некоректно
  • 7 успешни тест(а)
  • 2 неуспешни тест(а)
Диан Николов
module Enumerable
def split_up(length:, step: length, pad: [])
missing = (step - (count % step)) % step
selfCopy = self.to_a
pad.take(missing).each { |x| selfCopy << x}
selfCopy.each_slice(step) { |a| yield a.take(length) if block_given? }
unless block_given?
result = []
selfCopy.each_slice(step) { |a| result << a.take(length)}
result
end
end
end
.F.F.....

Failures:

  1) Enumerable#split_up returns the processed input when a block is passed
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad) {}.should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: nil
       
       (compared using ==)
     # /tmp/d20131106-4393-3neixb/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Enumerable#split_up does not mutate the input enumerable
     Failure/Error: numbers_list.should eq [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
       
       expected: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
            got: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, :a]
       
       (compared using ==)
     # /tmp/d20131106-4393-3neixb/spec.rb:25:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.27556 seconds
9 examples, 2 failures

Failed examples:

rspec /tmp/d20131106-4393-3neixb/spec.rb:12 # Enumerable#split_up returns the processed input when a block is passed
rspec /tmp/d20131106-4393-3neixb/spec.rb:23 # Enumerable#split_up does not mutate the input enumerable
Георги Кръстев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Кръстев
module Enumerable
def split_up(length:, step: length, pad: [])
each_slice(step).map do |slice|
piece = slice.concat(pad).take(length)
yield piece if block_given?
piece
end
end
end
.........

Finished in 0.24213 seconds
9 examples, 0 failures
Наталия Пацовска
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Наталия Пацовска
module Enumerable
def split_up(length:, step: length, pad: [])
slices_elements = select.with_index { |_, index| index % step < length }
slices_elements.each_slice(length).map do |slice|
yield slice if block_given?
slice.concat pad.take(length - slice.length)
end
end
end
.........

Finished in 0.24961 seconds
9 examples, 0 failures
Валентин Ейткен
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Валентин Ейткен
module Enumerable
def split_up length: length, step: step = length, pad: pad = []
result = []
each_slice(step) do |slice|
slice = (slice + pad).take(length)
if block_given?
yield slice
end
result << slice
end
result
end
end
.........

Finished in 0.24351 seconds
9 examples, 0 failures
Милен Мавров
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Милен Мавров
module Enumerable
def split_up(length:, step: length, pad: [])
splitted = []
each_slice(step) { |slice| splitted << slice }
splitted.each { |slice| slice.pop(step - length) if slice.size == step }
(0...length - splitted.last.size).each { |i| splitted.last << pad[i] } if splitted.last.size != length and pad != []
splitted.each { |slice| yield slice } if block_given?
splitted
end
end
........F

Failures:

  1) Enumerable#split_up leaves the last partition with less than n items if not enough padding elements
     Failure/Error: numbers_list.split_up(length: 3, pad: not_enough).should eq [[1, 2, 3],
       
       expected: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :not_enough]]
            got: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :not_enough, nil]]
       
       (compared using ==)
     # /tmp/d20131106-4393-1a8ynhv/spec.rb:76:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01325 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20131106-4393-1a8ynhv/spec.rb:74 # Enumerable#split_up leaves the last partition with less than n items if not enough padding elements
Цветан Иванов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Иванов
module Enumerable
def split_up(length:, step: 0, pad: [])
step = length if step < length
slices = each_slice(step).map{ |slice| slice[0..length - 1] }
pad.each { |slice| slices[slices.length - 1] << slice }
slices[slices.length - 1] = slices[slices.length - 1].first(length)
if block_given?
slices.each{ |slice| yield slice }
end
slices
end
end
.........

Finished in 0.09587 seconds
9 examples, 0 failures
Росен Рачев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Росен Рачев
module Enumerable
def split_up(length:, step: length, pad: [], &block)
partitions = []
each_slice(step) do |part|
part = part.take(length) if part.length > length
partitions << part
yield part if block
end
partitions.last.concat pad.take(length - partitions.last.length) if partitions.last.length < length
partitions
end
end
.........

Finished in 0.06783 seconds
9 examples, 0 failures
Сияна Славова
  • Некоректно
  • 7 успешни тест(а)
  • 2 неуспешни тест(а)
Сияна Славова
module Enumerable
def split_up(length: 1, step: length, pad: nil)
initial_array = (count % step == 0 or pad.nil?) ? to_a : to_a.concat(pad[0..self.count % step])
split_array = []
initial_array.each_with_index { |item,index| split_array << initial_array[index...index + length] if index % step == 0 }
block_given? ? split_array.each { |item| yield item } : split_array
end
end
..FF.....

Failures:

  1) Enumerable#split_up requires the length: keyword argument
     Failure/Error: expect { numbers_list.split_up }.to raise_error(ArgumentError)
       expected ArgumentError but nothing was raised
     # /tmp/d20131106-4393-94q5wr/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Enumerable#split_up does not mutate the input enumerable
     Failure/Error: numbers_list.should eq [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
       
       expected: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
            got: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, :a]
       
       (compared using ==)
     # /tmp/d20131106-4393-94q5wr/spec.rb:25:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.07702 seconds
9 examples, 2 failures

Failed examples:

rspec /tmp/d20131106-4393-94q5wr/spec.rb:19 # Enumerable#split_up requires the length: keyword argument
rspec /tmp/d20131106-4393-94q5wr/spec.rb:23 # Enumerable#split_up does not mutate the input enumerable
Илиян Танев
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Илиян Танев
module Enumerable
def split_up(length:, step: length , pad: [])
res = []
self.each_with_index { |item, index| res << item if index % step < length }
res = res.each_slice(length).to_a
if not pad.empty?
res.last.size.upto(length - 1) do |i|
res.last << pad[i - 1]
end
end
res.each { |x| yield x if block_given? }
end
end
........F

Failures:

  1) Enumerable#split_up leaves the last partition with less than n items if not enough padding elements
     Failure/Error: numbers_list.split_up(length: 3, pad: not_enough).should eq [[1, 2, 3],
       
       expected: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :not_enough]]
            got: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :not_enough, nil]]
       
       (compared using ==)
     # /tmp/d20131106-4393-1ng9i4/spec.rb:76:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.27262 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20131106-4393-1ng9i4/spec.rb:74 # Enumerable#split_up leaves the last partition with less than n items if not enough padding elements
Николай Каращранов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Каращранов
module Enumerable
def split_up(length:, step: length, pad: [])
result_help = self
if (step != length)
result_help = self.reject.with_index(1) do |x, index|
index % step > length || index % step == 0
end
end
result = []
result_help.each_slice(length) do |a|
if a.size < length
a = (a + pad).take(length)
end
if block_given?
yield(a)
end
result << a
end
result
end
end
.........

Finished in 0.27866 seconds
9 examples, 0 failures
Стефан Василев
  • Некоректно
  • 1 успешни тест(а)
  • 8 неуспешни тест(а)
Стефан Василев
def slice(array, index, count)
result_array = []
(index...index + count).each { |i| result_array << array[i] if i < array.size }
result_array
end
module Enumerable
def split_up(length:, step: length , pad: [])
result_array, iterator = [], 0
each do |item|
result_array << slice(self.to_a, iterator, length) if iterator < size
iterator += step
end
pad.each { |item| result_array[result_array.size - 1] << item unless result_array[result_array.size - 1].size > length - 1 }
result_array.each { |element| yield element } if block_given?
result_array
end
end
FF.FFFFFF

Failures:

  1) Enumerable#split_up iterates a block (if given) for each slice
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad) { |slice| slices << slice }
     ArgumentError:
       wrong number of arguments (3 for 1..2)
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `slice'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `block in split_up'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `each'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `split_up'
     # /tmp/d20131106-4393-1eia9jh/spec.rb:8:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Enumerable#split_up returns the processed input when a block is passed
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad) {}.should eq [[1, 2],
     ArgumentError:
       wrong number of arguments (3 for 1..2)
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `slice'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `block in split_up'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `each'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `split_up'
     # /tmp/d20131106-4393-1eia9jh/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) Enumerable#split_up does not mutate the input enumerable
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: [:a])
     ArgumentError:
       wrong number of arguments (3 for 1..2)
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `slice'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `block in split_up'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `each'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `split_up'
     # /tmp/d20131106-4393-1eia9jh/spec.rb:24:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) Enumerable#split_up splits up a collection in slices
     Failure/Error: numbers_list.split_up(length: 3).should eq [[1, 2, 3],
     ArgumentError:
       wrong number of arguments (3 for 1..2)
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `slice'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `block in split_up'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `each'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `split_up'
     # /tmp/d20131106-4393-1eia9jh/spec.rb:29:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) Enumerable#split_up splits up a collection in slices with step
     Failure/Error: numbers_list.split_up(length: 2, step: 3).should eq [[1, 2],
     ArgumentError:
       wrong number of arguments (3 for 1..2)
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `slice'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `block in split_up'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `each'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `split_up'
     # /tmp/d20131106-4393-1eia9jh/spec.rb:45:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) Enumerable#split_up splits up a collection in slices with pad
     Failure/Error: numbers_list.split_up(length: 3, pad: pad).should eq [[1, 2, 3],
     ArgumentError:
       wrong number of arguments (3 for 1..2)
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `slice'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `block in split_up'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `each'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `split_up'
     # /tmp/d20131106-4393-1eia9jh/spec.rb:55:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) Enumerable#split_up splits up a collection in slices with step and pad
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad).should eq [[1, 2],
     ArgumentError:
       wrong number of arguments (3 for 1..2)
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `slice'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `block in split_up'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `each'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `split_up'
     # /tmp/d20131106-4393-1eia9jh/spec.rb:65:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) Enumerable#split_up leaves the last partition with less than n items if not enough padding elements
     Failure/Error: numbers_list.split_up(length: 3, pad: not_enough).should eq [[1, 2, 3],
     ArgumentError:
       wrong number of arguments (3 for 1..2)
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `slice'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:11:in `block in split_up'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `each'
     # /tmp/d20131106-4393-1eia9jh/solution.rb:10:in `split_up'
     # /tmp/d20131106-4393-1eia9jh/spec.rb:76:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.19447 seconds
9 examples, 8 failures

Failed examples:

rspec /tmp/d20131106-4393-1eia9jh/spec.rb:6 # Enumerable#split_up iterates a block (if given) for each slice
rspec /tmp/d20131106-4393-1eia9jh/spec.rb:12 # Enumerable#split_up returns the processed input when a block is passed
rspec /tmp/d20131106-4393-1eia9jh/spec.rb:23 # Enumerable#split_up does not mutate the input enumerable
rspec /tmp/d20131106-4393-1eia9jh/spec.rb:28 # Enumerable#split_up splits up a collection in slices
rspec /tmp/d20131106-4393-1eia9jh/spec.rb:44 # Enumerable#split_up splits up a collection in slices with step
rspec /tmp/d20131106-4393-1eia9jh/spec.rb:54 # Enumerable#split_up splits up a collection in slices with pad
rspec /tmp/d20131106-4393-1eia9jh/spec.rb:64 # Enumerable#split_up splits up a collection in slices with step and pad
rspec /tmp/d20131106-4393-1eia9jh/spec.rb:74 # Enumerable#split_up leaves the last partition with less than n items if not enough padding elements
Георги Шопов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Шопов
module Enumerable
def split_up(length:, step: length, pad: [])
(0...to_a.length).step(step).each_with_object([]) do |index, list|
item = to_a[index...index + length]
item += pad[0...length - item.length] if item.length < length and pad != []
list << item
yield item if block_given?
end
end
end
.........

Finished in 0.14654 seconds
9 examples, 0 failures
Мария Терзиева
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Терзиева
module Enumerable
def split_up(length:, step: length, pad: [])
splited_up = each_slice(step).map { |slice| slice.concat(pad).take(length) }
splited_up.each { |slice| yield(slice) if block_given? }
end
end
.........

Finished in 0.17025 seconds
9 examples, 0 failures
Илиян Бобев
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Илиян Бобев
module Enumerable
def split_up(options)
options[:step] ||= options[:length]
options[:pad] ||= []
result = each_slice(options[:step]).to_a
result[-1] += options[:pad]
result.map! { |s| s.take(options[:length]) }
if block_given?
result.each { |s| yield s}
nil
else
result
end
end
end
.F.......

Failures:

  1) Enumerable#split_up returns the processed input when a block is passed
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad) {}.should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: nil
       
       (compared using ==)
     # /tmp/d20131106-4393-6446se/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.23896 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20131106-4393-6446se/spec.rb:12 # Enumerable#split_up returns the processed input when a block is passed
Мария Митева
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Митева
module Enumerable
def split_up(length:, step: length, pad: [])
splitted_enum = self.each_slice(step).map { |slice| slice.concat(pad).take(length) }
if block_given?
splitted_enum.each { |item| yield item }
else
return splitted_enum.to_a
end
end
end
.........

Finished in 0.22263 seconds
9 examples, 0 failures
Давид Петров
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Давид Петров
module Enumerable
def split_up(length:, step: length, pad: [])
x=to_a.each_slice(step).map{|row| row[0..length-1]}.map {|row| if row.size==length then row else row.concat(pad[0..length-row.size-1]) end }
block_given? ? x.each{|e| yield e} : x
end
end
.........

Finished in 0.20599 seconds
9 examples, 0 failures
Красимира Божанова
  • Некоректно
  • 5 успешни тест(а)
  • 4 неуспешни тест(а)
Красимира Божанова
module Enumerable
def split_up(length:, step: length, pad: [])
result = (to_a + pad).each_slice(step).map { |part| part.take(length) }
result.each { |part| yield part } if block_given?
result
end
end
FF....FF.

Failures:

  1) Enumerable#split_up iterates a block (if given) for each slice
     Failure/Error: slices.should eq [[1, 2], [4, 5], [7, 8], [10, :a]]
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [[1, 2], [4, 5], [7, 8], [10, :a], [:c]]
       
       (compared using ==)
     # /tmp/d20131106-4393-gavcgf/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Enumerable#split_up returns the processed input when a block is passed
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad) {}.should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [[1, 2], [4, 5], [7, 8], [10, :a], [:c]]
       
       (compared using ==)
     # /tmp/d20131106-4393-gavcgf/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) Enumerable#split_up splits up a collection in slices with pad
     Failure/Error: numbers_list.split_up(length: 3, pad: pad).should eq [[1, 2, 3],
       
       expected: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :a, :b]]
            got: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :a, :b], [:c]]
       
       (compared using ==)
     # /tmp/d20131106-4393-gavcgf/spec.rb:55:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) Enumerable#split_up splits up a collection in slices with step and pad
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad).should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [[1, 2], [4, 5], [7, 8], [10, :a], [:c]]
       
       (compared using ==)
     # /tmp/d20131106-4393-gavcgf/spec.rb:65:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.10295 seconds
9 examples, 4 failures

Failed examples:

rspec /tmp/d20131106-4393-gavcgf/spec.rb:6 # Enumerable#split_up iterates a block (if given) for each slice
rspec /tmp/d20131106-4393-gavcgf/spec.rb:12 # Enumerable#split_up returns the processed input when a block is passed
rspec /tmp/d20131106-4393-gavcgf/spec.rb:54 # Enumerable#split_up splits up a collection in slices with pad
rspec /tmp/d20131106-4393-gavcgf/spec.rb:64 # Enumerable#split_up splits up a collection in slices with step and pad
Георги Гърдев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Гърдев
module Enumerable
def split_up(length:, step:length, pad:[])
filtered = select.with_index { |_, i| i.remainder(step) < length }
split_up = filtered.each_slice(length).to_a
split_up[-1] = (split_up[-1] + pad).take(length)
if block_given?
split_up.map { |element| yield element }
end
split_up
end
end
.........

Finished in 0.19056 seconds
9 examples, 0 failures
Георги Пурнаров
  • Некоректно
  • 6 успешни тест(а)
  • 3 неуспешни тест(а)
Георги Пурнаров
module Enumerable
def split_up(length:, step: length, pad: [])
start_index,list=0,[]
data=self.to_a
pad[0..data.length%length].each {|element| data.push element} if data.length%length>0
while start_index<data.length
list.push data[start_index..start_index+length-1]
yield data[start_index..start_index+length-1] if block_given?
start_index+=step
end
list
end
end
FF.....F.

Failures:

  1) Enumerable#split_up iterates a block (if given) for each slice
     Failure/Error: slices.should eq [[1, 2], [4, 5], [7, 8], [10, :a]]
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [[1, 2], [4, 5], [7, 8], [10]]
       
       (compared using ==)
     # /tmp/d20131106-4393-1ora9e8/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Enumerable#split_up returns the processed input when a block is passed
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad) {}.should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [[1, 2], [4, 5], [7, 8], [10]]
       
       (compared using ==)
     # /tmp/d20131106-4393-1ora9e8/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) Enumerable#split_up splits up a collection in slices with step and pad
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad).should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [[1, 2], [4, 5], [7, 8], [10]]
       
       (compared using ==)
     # /tmp/d20131106-4393-1ora9e8/spec.rb:65:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.20109 seconds
9 examples, 3 failures

Failed examples:

rspec /tmp/d20131106-4393-1ora9e8/spec.rb:6 # Enumerable#split_up iterates a block (if given) for each slice
rspec /tmp/d20131106-4393-1ora9e8/spec.rb:12 # Enumerable#split_up returns the processed input when a block is passed
rspec /tmp/d20131106-4393-1ora9e8/spec.rb:64 # Enumerable#split_up splits up a collection in slices with step and pad
Александър Попов
  • Некоректно
  • 7 успешни тест(а)
  • 2 неуспешни тест(а)
Александър Попов
module Enumerable
def split_up(length:, step: length, pad: [])
(to_a + pad).each_slice(step).map { |slice| block_given? ? (yield slice[0...length]) : slice[0...length] }[0...to_a.size/step + 1]
end
end
FF.......

Failures:

  1) Enumerable#split_up iterates a block (if given) for each slice
     Failure/Error: slices.should eq [[1, 2], [4, 5], [7, 8], [10, :a]]
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [[1, 2], [4, 5], [7, 8], [10, :a], [:c]]
       
       (compared using ==)
     # /tmp/d20131106-4393-13pzes8/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Enumerable#split_up returns the processed input when a block is passed
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad) {}.should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [nil, nil, nil, nil]
       
       (compared using ==)
     # /tmp/d20131106-4393-13pzes8/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.18826 seconds
9 examples, 2 failures

Failed examples:

rspec /tmp/d20131106-4393-13pzes8/spec.rb:6 # Enumerable#split_up iterates a block (if given) for each slice
rspec /tmp/d20131106-4393-13pzes8/spec.rb:12 # Enumerable#split_up returns the processed input when a block is passed
Деян Хаджиев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Деян Хаджиев
module Enumerable
def split_up(length:, step: length, pad: [])
concatenated = to_a + pad.take( length - size % length )
concatenated.to_enum.each_slice(step).map { |slice| slice.take length }.each { |slice| yield slice if block_given? }.to_a
end
end
.........

Finished in 0.10471 seconds
9 examples, 0 failures
Петър Мазълов
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Петър Мазълов
module Enumerable
def split_up(length: ,step: length, pad: [])
result = self.to_a
slice = (0..size/step).map { |i| result.slice(step * i, length) }
if (size % step == 0)
slice.pop
else
last_element = slice.pop + pad
slice << last_element.take(length)
end
if(block_given?)
slice.map { |i| yield i}
else
slice
end
end
end
.F.......

Failures:

  1) Enumerable#split_up returns the processed input when a block is passed
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad) {}.should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [nil, nil, nil, nil]
       
       (compared using ==)
     # /tmp/d20131106-4393-rgteqk/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.194 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20131106-4393-rgteqk/spec.rb:12 # Enumerable#split_up returns the processed input when a block is passed
Никола Ненков
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Ненков
module Enumerable
def split_up(length:, step: length, pad: [])
slices = each_slice(step).map { |slice| slice.take(length) }
missing_count = length - slices.last.count
slices.last.concat(pad.take(missing_count))
block_given? ? slices.each { |slice| yield slice } : slices
end
end
.........

Finished in 0.17674 seconds
9 examples, 0 failures
Кристиян Кисимов
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Кристиян Кисимов
module Enumerable
def split_up(length: , step: length, pad: [])
each_slice(step).collect { |array| array.take length }.map do |array|
if array.length < length
block_given? ? yield(array.concat pad.take length - array.length) : array.concat(pad.take length - array.length)
else
block_given? ? yield(array) : array
end
end
end
end
.F.......

Failures:

  1) Enumerable#split_up returns the processed input when a block is passed
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad) {}.should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [nil, nil, nil, nil]
       
       (compared using ==)
     # /tmp/d20131106-4393-11l6672/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.30412 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20131106-4393-11l6672/spec.rb:12 # Enumerable#split_up returns the processed input when a block is passed
Илия Ватахов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Илия Ватахов
module Enumerable
def split_up(length:, step: length, pad: [])
pieces = each_slice(step).to_a
pieces.last.concat pad
result = pieces.map { |x| x.take length }
result.each { |x| yield x } if block_given?
result
end
end
.........

Finished in 0.26814 seconds
9 examples, 0 failures
Калоян Калудов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Калоян Калудов
module Enumerable
def split_up(length:, step: length, pad:[])
each_slice(step).map do |slice|
slice += pad if slice.size < length
yield slice.take(length) if block_given?
slice.take(length)
end
end
end
.........

Finished in 0.26925 seconds
9 examples, 0 failures
Александър Тахчиев
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Александър Тахчиев
module Enumerable
def split_up(length: nil, step: length, pad: [])
slf = self.to_a
return [] if slf == []
arr = slf.each_index.select { |i| i % step == 0 }.map do |i|
slf[i..i + length - 1]
end
result = arr[0..-2].push arr[-1].concat(pad.take(arr[0].count - arr[-1].count))
block_given? ? result.each { |i| yield i } : result
end
end
..F......

Failures:

  1) Enumerable#split_up requires the length: keyword argument
     Failure/Error: expect { numbers_list.split_up }.to raise_error(ArgumentError)
       expected ArgumentError, got #<TypeError: nil can't be coerced into Fixnum> with backtrace:
         # /tmp/d20131106-4393-h5hkw6/solution.rb:5:in `%'
         # /tmp/d20131106-4393-h5hkw6/solution.rb:5:in `block in split_up'
         # /tmp/d20131106-4393-h5hkw6/solution.rb:5:in `each_index'
         # /tmp/d20131106-4393-h5hkw6/solution.rb:5:in `each'
         # /tmp/d20131106-4393-h5hkw6/solution.rb:5:in `select'
         # /tmp/d20131106-4393-h5hkw6/solution.rb:5:in `split_up'
         # /tmp/d20131106-4393-h5hkw6/spec.rb:20:in `block (3 levels) in <top (required)>'
         # /tmp/d20131106-4393-h5hkw6/spec.rb:20:in `block (2 levels) in <top (required)>'
         # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
         # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
     # /tmp/d20131106-4393-h5hkw6/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01507 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20131106-4393-h5hkw6/spec.rb:19 # Enumerable#split_up requires the length: keyword argument
Иван Капукаранов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Капукаранов
module Enumerable
def split_up(length:, step: length, pad: [])
self.each_slice(step).map do |peace|
rezult = (peace + pad).take(length)
if block_given?
yield rezult
rezult
else
rezult
end
end
end
end
.........

Finished in 0.23677 seconds
9 examples, 0 failures
Кристиан Ташков
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Кристиан Ташков
module Enumerable
def split_up(hash, &block)
length = hash[:length]
step = hash[:step] || hash[:length]
pad = hash[:pad] || []
count = (self.size.to_f / step).ceil
items = self.to_a.concat pad
all_slices = items.map.with_index do |item, i|
items[i...(i + length)]
end
result_slices = all_slices.select.with_index { |item, i| i.remainder(step).zero? }
result = result_slices.take count
if block_given?
result.each { |x| yield x }
end
result
end
end
...F.....

Failures:

  1) Enumerable#split_up does not mutate the input enumerable
     Failure/Error: numbers_list.should eq [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
       
       expected: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
            got: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, :a]
       
       (compared using ==)
     # /tmp/d20131106-4393-128qidz/spec.rb:25:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.18786 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20131106-4393-128qidz/spec.rb:23 # Enumerable#split_up does not mutate the input enumerable
Антонио Николов
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Антонио Николов
module Enumerable
def split_up(length:, step: length, pad: [])
group, result, count_length, step_count = [], [], 0, 0
each do |x|
step_count += 1 unless step == length
if step_count > length then
step_count = 0 if step_count == step
next
end
count_length += 1
group << x
if count_length == length then
count_length = 0
result << group
yield group if block_given?
group = []
end
end
group_length = group.length
if group != [] and group.length < length then
(group_length + 1..length).each { |x| group << pad[x - (group_length + 1)] unless pad[x - (group.length + 1)] == nil } unless pad == []
yield group if block_given?
result << group
end
p result
end
end
[[1, 2], [4, 5], [7, 8], [10, :a]]
.[[1, 2], [4, 5], [7, 8], [10, :a]]
..[[1, 2], [4, 5], [7, 8], [10, :a]]
.[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]
[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]
[[[:one, 1], [:two, 2]], [[:three, 3], [:four, 4]]]
.[[1, 2], [4, 5], [7, 8], [10]]
[[[:one, 1], [:two, 2]], [[:four, 4]]]
.[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :a, :b]]
[[[:one, 1], [:two, 2], [:three, 3]], [[:four, 4], :a, :b]]
.[[1, 2], [4, 5], [7, 8], [10, :a]]
[[[:one, 1], [:two, 2]], [[:four, 4], :a]]
.[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :not_enough, nil]]
F

Failures:

  1) Enumerable#split_up leaves the last partition with less than n items if not enough padding elements
     Failure/Error: numbers_list.split_up(length: 3, pad: not_enough).should eq [[1, 2, 3],
       
       expected: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :not_enough]]
            got: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :not_enough, nil]]
       
       (compared using ==)
     # /tmp/d20131106-4393-1xldf4x/spec.rb:76:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.20339 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20131106-4393-1xldf4x/spec.rb:74 # Enumerable#split_up leaves the last partition with less than n items if not enough padding elements
Христо Хърсев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Хърсев
module Enumerable
def split_up(length:, step: length, pad: [])
splitted = each_slice(step).map { |slice| slice[0, length] }
last_slice_size = splitted[-1].size unless splitted.empty?
splitted[-1].concat(pad[0, length - last_slice_size]) unless last_slice_size.nil?
splitted.map { |slice| yield slice } if block_given?
splitted
end
end
.........

Finished in 0.19732 seconds
9 examples, 0 failures
Методи Димитров
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Методи Димитров
module Enumerable
def split_up(length:, step: length, pad: [])
each_slice(step).map do |slice|
element = (slice + pad).first(length)
if block_given?
yield element
else
element
end
end
end
end
.F.......

Failures:

  1) Enumerable#split_up returns the processed input when a block is passed
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad) {}.should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [nil, nil, nil, nil]
       
       (compared using ==)
     # /tmp/d20131106-4393-zo74jz/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.18751 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20131106-4393-zo74jz/spec.rb:12 # Enumerable#split_up returns the processed input when a block is passed
Александър Антов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Антов
module Enumerable
def split_up(blocks)
if blocks[:step] == nil
blocks[:step] = blocks[:length]
end
temp = Array.new
temp_piece = Array.new
if blocks[:step] == blocks[:length]
temp = self.each_slice(blocks[:length]).to_a
else
counter = 0
empty_block_start = blocks[:length] - 1
empty_block_end = blocks[:step] - 1
while counter != self.count
if counter > empty_block_end
empty_block_start += blocks[:step]
empty_block_end += blocks[:step]
temp.push(temp_piece)
temp_piece = Array.new
end
if counter <= empty_block_start or counter > empty_block_end
temp_piece.push(self.to_a[counter])
end
counter = counter + 1
end
if temp_piece.count != 0
temp.push(temp_piece)
end
end
if blocks[:pad] != nil
blocks[:pad] = blocks[:pad].reverse
while temp[temp.count-1].count != blocks[:length] and !blocks[:pad].empty?
temp[temp.count-1].push(blocks[:pad].pop)
end
end
temp.each do |iter|
yield iter if block_given?
end
return temp
end
end
.........

Finished in 0.2132 seconds
9 examples, 0 failures
Венцислав Велков
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Венцислав Велков
module Enumerable
def split_up(length:, step: length, pad: [])
new_array = []
temp_array = self.to_a
while !temp_array.empty?
new_array << temp_array.take(length)
if block_given? then yield temp_array.take(length) end
temp_array = temp_array.drop(step)
end
if new_array.last.length < length then
new_array.last.concat(pad.take(length - new_array.last.length))
end
new_array
end
end
F........

Failures:

  1) Enumerable#split_up iterates a block (if given) for each slice
     Failure/Error: slices.should eq [[1, 2], [4, 5], [7, 8], [10, :a]]
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [[1, 2], [4, 5], [7, 8], [10]]
       
       (compared using ==)
     # /tmp/d20131106-4393-om4nsl/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.18586 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20131106-4393-om4nsl/spec.rb:6 # Enumerable#split_up iterates a block (if given) for each slice
Ясен Трифонов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Ясен Трифонов
#!/usr/local/bin/ruby -w
module Enumerable
def split_up(length: , step: length, pad: [])
splitten = []
each_slice(step) do |slice|
current = slice.take(length)
to_add = length - current.size
if to_add > 0 && pad.size > 0
pad.take(to_add).each { |element| current << element }
end
yield current if block_given?
splitten << current
end
splitten
end
end
.........

Finished in 0.01742 seconds
9 examples, 0 failures
Ангел Венчев
  • Некоректно
  • 3 успешни тест(а)
  • 6 неуспешни тест(а)
Ангел Венчев
module Enumerable
def split_up(length:, step: length, pad: [])
to_a.flatten.each_slice(step).map {|el| el.take length }.tap do |el|
el[-1] += pad[0..length-el.length]
end.each {|el| yield el if block_given?}
end
end
FF..FFFF.

Failures:

  1) Enumerable#split_up iterates a block (if given) for each slice
     Failure/Error: slices.should eq [[1, 2], [4, 5], [7, 8], [10, :a]]
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [[1, 2], [4, 5], [7, 8], [10, :a, :b]]
       
       (compared using ==)
     # /tmp/d20131106-4393-7gmku3/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Enumerable#split_up returns the processed input when a block is passed
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad) {}.should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [[1, 2], [4, 5], [7, 8], [10, :a, :b]]
       
       (compared using ==)
     # /tmp/d20131106-4393-7gmku3/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) Enumerable#split_up splits up a collection in slices
     Failure/Error: numbers_hash.split_up(length: 2).should eq [[[:one, 1], [:two, 2]],
       
       expected: [[[:one, 1], [:two, 2]], [[:three, 3], [:four, 4]]]
            got: [[:one, 1], [:two, 2], [:three, 3], [:four, 4]]
       
       (compared using ==)
     # /tmp/d20131106-4393-7gmku3/spec.rb:40:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) Enumerable#split_up splits up a collection in slices with step
     Failure/Error: numbers_hash.split_up(length: 2, step: 3).should eq [[[:one, 1], [:two, 2]],
       
       expected: [[[:one, 1], [:two, 2]], [[:four, 4]]]
            got: [[:one, 1], [2, :three], [:four, 4]]
       
       (compared using ==)
     # /tmp/d20131106-4393-7gmku3/spec.rb:50:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) Enumerable#split_up splits up a collection in slices with pad
     Failure/Error: numbers_list.split_up(length: 3, pad: pad).should eq [[1, 2, 3],
       
       expected: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :a, :b]]
            got: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :a, :b, :c]]
       
       (compared using ==)
     # /tmp/d20131106-4393-7gmku3/spec.rb:55:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) Enumerable#split_up splits up a collection in slices with step and pad
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad).should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [[1, 2], [4, 5], [7, 8], [10, :a, :b]]
       
       (compared using ==)
     # /tmp/d20131106-4393-7gmku3/spec.rb:65:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01489 seconds
9 examples, 6 failures

Failed examples:

rspec /tmp/d20131106-4393-7gmku3/spec.rb:6 # Enumerable#split_up iterates a block (if given) for each slice
rspec /tmp/d20131106-4393-7gmku3/spec.rb:12 # Enumerable#split_up returns the processed input when a block is passed
rspec /tmp/d20131106-4393-7gmku3/spec.rb:28 # Enumerable#split_up splits up a collection in slices
rspec /tmp/d20131106-4393-7gmku3/spec.rb:44 # Enumerable#split_up splits up a collection in slices with step
rspec /tmp/d20131106-4393-7gmku3/spec.rb:54 # Enumerable#split_up splits up a collection in slices with pad
rspec /tmp/d20131106-4393-7gmku3/spec.rb:64 # Enumerable#split_up splits up a collection in slices with step and pad
Борислава Аладжова
  • Некоректно
  • 6 успешни тест(а)
  • 3 неуспешни тест(а)
Борислава Аладжова
class Object
def split_up(length:, step: length, pad: [])
[] if self == [] or self == {}
splitted = []
each_slice(step) do |slice|
slice = slice.take(length)
slice = (slice << pad).flatten.take(length) unless pad.empty?
yield slice if block_given?
splitted << slice
end
splitted unless block_given?
end
end
.F....FF.

Failures:

  1) Enumerable#split_up returns the processed input when a block is passed
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad) {}.should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: nil
       
       (compared using ==)
     # /tmp/d20131106-4393-1264cp/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Enumerable#split_up splits up a collection in slices with pad
     Failure/Error: numbers_hash.split_up(length: 3, pad: pad).should eq [[[:one, 1], [:two, 2], [:three, 3]],
       
       expected: [[[:one, 1], [:two, 2], [:three, 3]], [[:four, 4], :a, :b]]
            got: [[:one, 1, :two], [:four, 4, :a]]
       
       (compared using ==)
     # /tmp/d20131106-4393-1264cp/spec.rb:60:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) Enumerable#split_up splits up a collection in slices with step and pad
     Failure/Error: numbers_hash.split_up(length: 2, step: 3, pad: pad).should eq [[[:one, 1], [:two, 2]],
       
       expected: [[[:one, 1], [:two, 2]], [[:four, 4], :a]]
            got: [[:one, 1], [:four, 4]]
       
       (compared using ==)
     # /tmp/d20131106-4393-1264cp/spec.rb:70:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01398 seconds
9 examples, 3 failures

Failed examples:

rspec /tmp/d20131106-4393-1264cp/spec.rb:12 # Enumerable#split_up returns the processed input when a block is passed
rspec /tmp/d20131106-4393-1264cp/spec.rb:54 # Enumerable#split_up splits up a collection in slices with pad
rspec /tmp/d20131106-4393-1264cp/spec.rb:64 # Enumerable#split_up splits up a collection in slices with step and pad
Ангел Цанев
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Ангел Цанев
module Enumerable
def split_up(length:, step: length , pad: [])
result = self.dup.to_a
(step - length).times do
((result.size) / step).downto(1).each { |i| result.delete_at(i * step - 1) }
end
if (not(pad == []) and not(result.size % length == 0) )
0.upto(length - (result.size % length) - 1).each { |i| result << pad[i] unless not(pad[i]) }
end
result = result.each_slice(length).to_a
result.each{ |slice| yield(slice) if (block_given?) }
end
end
.........

Finished in 0.01313 seconds
9 examples, 0 failures
Никола Величков
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Величков
module Enumerable
def split_up (length:0, step:length, pad:[])
array = []
each_slice(step) {|subarray| array << subarray.take(length) }.to_a
pad.each {|elem| array.last << elem if array.last.length != length}
array.each {|elem| yield elem if block_given?}
end
end
.........

Finished in 0.30886 seconds
9 examples, 0 failures
Николай Хубанов
  • Коректно
  • 9 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Хубанов
module Enumerable
def split_up(length:, step: length, pad:[])
each_slice(step).map do |slice|
entry = slice.take(length)
entry += pad.take(length - slice.length) if entry.length < length
yield entry if block_given?
entry
end
end
end
.........

Finished in 0.01338 seconds
9 examples, 0 failures
Аделина Рудова
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Аделина Рудова
module Enumerable
def split_up(length:, step: length, pad: [])
converted_array = self.to_a
converted_array.concat pad[0...length - 1] unless pad.empty?
result_array = []
step_iterator = 0
while step_iterator < converted_array.length
sub_array = converted_array[step_iterator...length]
yield sub_array if block_given?
result_array << sub_array
step_iterator += step
length += step
end
result_array
end
end
...F.....

Failures:

  1) Enumerable#split_up does not mutate the input enumerable
     Failure/Error: numbers_list.should eq [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
       
       expected: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
            got: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, :a]
       
       (compared using ==)
     # /tmp/d20131106-4393-19epdm3/spec.rb:25:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01333 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20131106-4393-19epdm3/spec.rb:23 # Enumerable#split_up does not mutate the input enumerable
Кристиян Азманов
  • Некоректно
  • 3 успешни тест(а)
  • 6 неуспешни тест(а)
Кристиян Азманов
module Enumerable
def split_up(length:,step:"#{length}",pad:[])
final = []
sliced_array = ((self.each_slice("#{step}".to_i)).to_a).each {|x| final<<x.take("#{length}".to_i)}
if final[-1].length<length then final[-1]=fill_up_last_element(final[-1],pad,length) end
return final
end
def fill_up_last_element(last_element,source_array,required_length)
loop do
last_element<<source_array.shift
break if last_element.length == required_length
end
return last_element
end
end
F...FFFFF

Failures:

  1) Enumerable#split_up iterates a block (if given) for each slice
     Failure/Error: slices.should eq [[1, 2], [4, 5], [7, 8], [10, :a]]
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: []
       
       (compared using ==)
     # /tmp/d20131106-4393-vd1qfi/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Enumerable#split_up splits up a collection in slices
     Failure/Error: numbers_list.split_up(length: 3).should eq [[1, 2, 3],
       
       expected: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]
            got: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, nil, nil]]
       
       (compared using ==)
     # /tmp/d20131106-4393-vd1qfi/spec.rb:29:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) Enumerable#split_up splits up a collection in slices with step
     Failure/Error: numbers_list.split_up(length: 2, step: 3).should eq [[1, 2],
       
       expected: [[1, 2], [4, 5], [7, 8], [10]]
            got: [[1, 2], [4, 5], [7, 8], [10, nil]]
       
       (compared using ==)
     # /tmp/d20131106-4393-vd1qfi/spec.rb:45:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) Enumerable#split_up splits up a collection in slices with pad
     Failure/Error: numbers_hash.split_up(length: 3, pad: pad).should eq [[[:one, 1], [:two, 2], [:three, 3]],
       
       expected: [[[:one, 1], [:two, 2], [:three, 3]], [[:four, 4], :a, :b]]
            got: [[[:one, 1], [:two, 2], [:three, 3]], [[:four, 4], :c, nil]]
       
       (compared using ==)
     # /tmp/d20131106-4393-vd1qfi/spec.rb:60:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) Enumerable#split_up splits up a collection in slices with step and pad
     Failure/Error: numbers_hash.split_up(length: 2, step: 3, pad: pad).should eq [[[:one, 1], [:two, 2]],
       
       expected: [[[:one, 1], [:two, 2]], [[:four, 4], :a]]
            got: [[[:one, 1], [:two, 2]], [[:four, 4], :b]]
       
       (compared using ==)
     # /tmp/d20131106-4393-vd1qfi/spec.rb:70:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) Enumerable#split_up leaves the last partition with less than n items if not enough padding elements
     Failure/Error: numbers_list.split_up(length: 3, pad: not_enough).should eq [[1, 2, 3],
       
       expected: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :not_enough]]
            got: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, :not_enough, nil]]
       
       (compared using ==)
     # /tmp/d20131106-4393-vd1qfi/spec.rb:76:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01475 seconds
9 examples, 6 failures

Failed examples:

rspec /tmp/d20131106-4393-vd1qfi/spec.rb:6 # Enumerable#split_up iterates a block (if given) for each slice
rspec /tmp/d20131106-4393-vd1qfi/spec.rb:28 # Enumerable#split_up splits up a collection in slices
rspec /tmp/d20131106-4393-vd1qfi/spec.rb:44 # Enumerable#split_up splits up a collection in slices with step
rspec /tmp/d20131106-4393-vd1qfi/spec.rb:54 # Enumerable#split_up splits up a collection in slices with pad
rspec /tmp/d20131106-4393-vd1qfi/spec.rb:64 # Enumerable#split_up splits up a collection in slices with step and pad
rspec /tmp/d20131106-4393-vd1qfi/spec.rb:74 # Enumerable#split_up leaves the last partition with less than n items if not enough padding elements
Десислав Илиев
  • Некоректно
  • 6 успешни тест(а)
  • 3 неуспешни тест(а)
Десислав Илиев
module Enumerable
def split_up(length, step: length, pad: length)
size = length[:length]
step.default = size
iter_value = step[:step]
pad.default = []
pad_value = pad[:pad]
split_array = []
split_array << self.to_a[0, size].to_a
yield self.to_a[0, size].to_a if block_given?
count = iter_value
while iter_value < self.count
yield self.to_a[iter_value, size].to_a if block_given?
split_array << self.to_a[iter_value, size].to_a
iter_value += count
end
while split_array[-1].count < size and pad_value.count > 0
split_array[-1] << pad_value.shift
end
split_array
end
end
F.....FF.

Failures:

  1) Enumerable#split_up iterates a block (if given) for each slice
     Failure/Error: slices.should eq [[1, 2], [4, 5], [7, 8], [10, :a]]
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [[1, 2], [4, 5], [7, 8], [10]]
       
       (compared using ==)
     # /tmp/d20131106-4393-1r0eb76/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Enumerable#split_up splits up a collection in slices with pad
     Failure/Error: numbers_hash.split_up(length: 3, pad: pad).should eq [[[:one, 1], [:two, 2], [:three, 3]],
       
       expected: [[[:one, 1], [:two, 2], [:three, 3]], [[:four, 4], :a, :b]]
            got: [[[:one, 1], [:two, 2], [:three, 3]], [[:four, 4], :c]]
       
       (compared using ==)
     # /tmp/d20131106-4393-1r0eb76/spec.rb:60:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) Enumerable#split_up splits up a collection in slices with step and pad
     Failure/Error: numbers_hash.split_up(length: 2, step: 3, pad: pad).should eq [[[:one, 1], [:two, 2]],
       
       expected: [[[:one, 1], [:two, 2]], [[:four, 4], :a]]
            got: [[[:one, 1], [:two, 2]], [[:four, 4], :b]]
       
       (compared using ==)
     # /tmp/d20131106-4393-1r0eb76/spec.rb:70:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01423 seconds
9 examples, 3 failures

Failed examples:

rspec /tmp/d20131106-4393-1r0eb76/spec.rb:6 # Enumerable#split_up iterates a block (if given) for each slice
rspec /tmp/d20131106-4393-1r0eb76/spec.rb:54 # Enumerable#split_up splits up a collection in slices with pad
rspec /tmp/d20131106-4393-1r0eb76/spec.rb:64 # Enumerable#split_up splits up a collection in slices with step and pad
Владимир Конушлиев
  • Некоректно
  • 8 успешни тест(а)
  • 1 неуспешни тест(а)
Владимир Конушлиев
module Enumerable
def split_up(length:, step: length, pad: [])
result = []
self.each_slice(step) do |slice|
line = slice.slice(0, length)
line |= pad if line.size < length
line = line.slice(0, length)
result << line
end
result
end
end
F........

Failures:

  1) Enumerable#split_up iterates a block (if given) for each slice
     Failure/Error: slices.should eq [[1, 2], [4, 5], [7, 8], [10, :a]]
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: []
       
       (compared using ==)
     # /tmp/d20131106-4393-ih9zmq/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01312 seconds
9 examples, 1 failure

Failed examples:

rspec /tmp/d20131106-4393-ih9zmq/spec.rb:6 # Enumerable#split_up iterates a block (if given) for each slice
Веселин Генадиев
  • Некоректно
  • 7 успешни тест(а)
  • 2 неуспешни тест(а)
Веселин Генадиев
module Enumerable
def split_up(length:, step: length, pad: [])
sliced_array = []
self.find_all.each_with_index {|obj, index| index % step < length}.
each_slice(length) {|array| sliced_array << (block_given? ? yield(array): array) }
if pad.length > 0 && sliced_array.last.length < length
sliced_array.last.concat pad.take(length - sliced_array.last.length)
end
sliced_array
end
end
FF.......

Failures:

  1) Enumerable#split_up iterates a block (if given) for each slice
     Failure/Error: slices.should eq [[1, 2], [4, 5], [7, 8], [10, :a]]
       
       expected: [[1, 2], [4, 5], [7, 8], [10, :a]]
            got: [[1, 2], [4, 5], [7, 8], [10]]
       
       (compared using ==)
     # /tmp/d20131106-4393-1sm1v5t/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Enumerable#split_up returns the processed input when a block is passed
     Failure/Error: numbers_list.split_up(length: 2, step: 3, pad: pad) {}.should eq [[1, 2],
     NoMethodError:
       undefined method `length' for nil:NilClass
     # /tmp/d20131106-4393-1sm1v5t/solution.rb:6:in `split_up'
     # /tmp/d20131106-4393-1sm1v5t/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01359 seconds
9 examples, 2 failures

Failed examples:

rspec /tmp/d20131106-4393-1sm1v5t/spec.rb:6 # Enumerable#split_up iterates a block (if given) for each slice
rspec /tmp/d20131106-4393-1sm1v5t/spec.rb:12 # Enumerable#split_up returns the processed input when a block is passed