Sha256: e7c985749d2d8e89c961739f6a66b24de244afe348e4b8e715536ffadeec396e

Contents?: true

Size: 1.14 KB

Versions: 16

Compression:

Stored size: 1.14 KB

Contents

require 'facets/hash/select'
require 'test/unit'

class TC_Hash_Select < Test::Unit::TestCase

  def test_select!
    # Empty hash.
    a = {}
    assert_equal(nil, a.select! {false}, "return nil if hash not changed")
    assert_equal({}, a, "hash is not changed")

    a = {}
    assert_equal(nil, a.select! {true}, "return nil if hash not changed")
    assert_equal({}, a, "hash is not changed")

      # Non-empty hash.
    a = {0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'}
    assert_equal({0 => 'a', 2 => 'c'}, a.select! {|x,y| x % 2 == 0}, "select even numbers")
    assert_equal({0 => 'a', 2 => 'c'}, a, "select even numbers")

    a = {0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'}
    assert_equal({1 => 'b'}, a.select! {|x,y| y == 'b'}, "select one member")
    assert_equal({1 => 'b'}, a, "select one member")

    a = {0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'}
    assert_equal(nil, a.select! {true}, "return nil if hash not changed")
    assert_equal({0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'}, a, "select all")

    a = {0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'}
    assert_equal({}, a.select! {false}, "select none")
    assert_equal({}, a, "select none")
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
facets-2.8.4 test/core/hash/test_select.rb
facets-2.8.3 test/core/hash/test_select.rb
facets-2.8.2 test/core/hash/test_select.rb
facets-2.8.1 test/core/hash/test_select.rb
facets-2.8.0 test/core/hash/test_select.rb
facets-2.7.0 test/core/hash/test_select.rb
facets-2.6.0 test/core/hash/test_select.rb
facets-2.4.0 test/hash/test_select.rb
facets-2.4.1 test/hash/test_select.rb
facets-2.4.3 test/core/hash/test_select.rb
facets-2.4.2 test/core/hash/test_select.rb
facets-2.4.4 test/core/hash/test_select.rb
facets-2.5.0 test/core/hash/test_select.rb
facets-2.4.5 test/core/hash/test_select.rb
facets-2.5.1 test/core/hash/test_select.rb
facets-2.5.2 test/core/hash/test_select.rb