Sha256: 9c222b825a734ce8eac946caebd5b52373fe8c548e3b0a13047e707118c8fadc

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

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_01
    h = { 'A' => 1, 'B' => 2 }
    h.update_keys{ |k| k.downcase }
    assert_equal( { 'a' => 1, 'b' => 2 }, h)
  end

  def test_update_keys_02
    h = { :a => 1, :b => 2 }
    h.update_keys{ |k| "#{k}!" }
    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

4 entries across 4 versions & 1 rubygems

Version Path
facets-2.4.2 test/core/hash/test_update.rb
facets-2.4.3 test/core/hash/test_update.rb
facets-2.4.4 test/core/hash/test_update.rb
facets-2.4.5 test/core/hash/test_update.rb