PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/core/hash/test_select.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 35 lines | 24 code | 9 blank | 2 comment | 5 complexity | c14819ade05b5fd982c1a171bf4369eb MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. require 'facets/hash/select'
  2. require 'test/unit'
  3. class TC_Hash_Select < Test::Unit::TestCase
  4. def test_select!
  5. # Empty hash.
  6. a = {}
  7. assert_equal(nil, a.select! {false}, "return nil if hash not changed")
  8. assert_equal({}, a, "hash is not changed")
  9. a = {}
  10. assert_equal(nil, a.select! {true}, "return nil if hash not changed")
  11. assert_equal({}, a, "hash is not changed")
  12. # Non-empty hash.
  13. a = {0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'}
  14. assert_equal({0 => 'a', 2 => 'c'}, a.select! {|x,y| x % 2 == 0}, "select even numbers")
  15. assert_equal({0 => 'a', 2 => 'c'}, a, "select even numbers")
  16. a = {0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'}
  17. assert_equal({1 => 'b'}, a.select! {|x,y| y == 'b'}, "select one member")
  18. assert_equal({1 => 'b'}, a, "select one member")
  19. a = {0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'}
  20. assert_equal(nil, a.select! {true}, "return nil if hash not changed")
  21. assert_equal({0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'}, a, "select all")
  22. a = {0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'}
  23. assert_equal({}, a.select! {false}, "select none")
  24. assert_equal({}, a, "select none")
  25. end
  26. end