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