Sha256: 28068ace8eaa4dc43d6087b5ce9af540f5bd9391adde7992287c45b4c4fceab6

Contents?: true

Size: 750 Bytes

Versions: 3

Compression:

Stored size: 750 Bytes

Contents

require 'minitest/autorun'
require 'shenanigans/array/reductions'

class ArrayReductions < MiniTest::Unit::TestCase
  TEST_ARRAY = [*1..4]

  def test_reductions_without_params_or_block
    assert_raises(ArgumentError) { TEST_ARRAY.reductions }
  end

  def test_reductions_operator_only
    assert TEST_ARRAY.reductions(:+) == [1,3,6,10]
  end

  def test_reductions_initial_only
    assert TEST_ARRAY.reductions(50) { |acc,b| acc+b} == [50,51,53,56,60]
  end

  def test_reductions_inital_and_operator
    assert TEST_ARRAY.reductions(50, :+) == [50,51,53,56,60]
  end

  def test_reductions_without_params
    assert TEST_ARRAY.reductions { |acc,b| acc+b} == [1,3,6,10]
    assert %w(a b c).reductions { |s1, s2| s1+s2 } == %w(a ab abc)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shenanigans-1.0.13 test/array/test_reductions.rb
shenanigans-1.0.11 test/array/test_reductions.rb
shenanigans-1.0.10 test/array/test_reductions.rb