Sha256: c99e3c8b80b1f153820b61034c02f03d2c95402f8948a561c963aeb84474533b

Contents?: true

Size: 907 Bytes

Versions: 2

Compression:

Stored size: 907 Bytes

Contents

require 'facets/hash/update'
require 'test/unit'

class TC_Hash_Prime < Test::Unit::TestCase

  def test_shift_update
    a = { :a => 1, :b => 2, :c => 3 }
    b = { :a => 0, :d => 4 }
    e = { :a => 0, :b => 2, :c => 3, :d => 4 }
    assert_equal( e, a << b )
  end

  def test_update_each
    a = { :a => 1, :b => 2, :c => 3 }
    e = { :a => 2, :b => 3, :c => 4 }
    a.update_each{ |k,v| { k => v+1 } }
    assert_equal( e, a )
  end

  def test_update_keys
    h = { 'A' => 1, 'B' => 2 }
    h.update_keys{ |k| k.downcase }
    assert_equal( { 'a' => 1, 'b' => 2 }, h)
  end

  def test_update_values
    h = { 1 => 'A', 2 => 'B' }
    h.update_values{ |v| v.downcase }
    assert_equal( { 1 => 'a', 2 => 'b' }, h )
  end

  def test_replace_each
    a = { :a => 1, :b => 2, :c => 3 }
    e = { :a => 2, :b => 3, :c => 4 }
    a.replace_each{ |k,v| { k => v+1 } }
    assert_equal( e, a )
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
facets-2.4.0 test/hash/test_update.rb
facets-2.4.1 test/hash/test_update.rb