Sha256: e6d4d8f3e7ac798f9af1199dcc6805d7a36de98e5a8c2e3cbe452778445b6236

Contents?: true

Size: 722 Bytes

Versions: 4

Compression:

Stored size: 722 Bytes

Contents

require_relative '../test_helper'

class MapCompactTest < Minitest::Test
  should "map_compact" do
    assert_equal [1, 9], [1, 2, nil, 3, 4].map_compact { |item| item**2 if (nil == item ? nil : item.odd?) }
  end

  should "map_compact to empty if nothing matches" do
    assert_equal [], {:a => 'aaa', :b => 'bbb'}.map_compact { |key, value| value if key == :c }
  end

  should "map_compact a hash" do
    assert_equal ['bbb'], {:a => 'aaa', :b => 'bbb'}.map_compact { |key, value| value if key == :b }
  end

  should "map_compact empty collection" do
    assert_equal [], [].map_compact { |item| true }
  end

  should "not map_compact false" do
    assert_equal [false], [nil, false].map_compact { |a| a }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
invoca-utils-0.1.0.pre.2 test/unit/map_compact_test.rb
invoca-utils-0.0.5 test/unit/map_compact_test.rb
invoca-utils-0.0.4 test/unit/map_compact_test.rb
invoca-utils-0.0.3 test/unit/map_compact_test.rb