diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-10 05:02:02 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-10 05:02:02 +0000 |
commit | d68c3ecf98bf3b5802a6b0f9a6bcf7825addd9e5 (patch) | |
tree | 95a8b3e8116776990c19e5cacd5af0af59f898c7 /test/ruby/test_hash.rb | |
parent | f11a85c72600026f6e26afe6dda2548c785ce1d3 (diff) |
hash.c: compare methods
* hash.c (rb_hash_{le,lt,ge,gt}): new methods, Hash#<=, Hash#<,
Hash#>=, Hash#>, to test if all elements of a hash are also
included in another hash, and vice versa.
[ruby-core:68561] [Feature #10984]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_hash.rb')
-rw-r--r-- | test/ruby/test_hash.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index ee51c8ed7d..4f48d3b90c 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1308,6 +1308,31 @@ class TestHash < Test::Unit::TestCase assert_nil(h.dig(:c, 1)) end + def test_cmp + h1 = {a:1, b:2} + h2 = {a:1, b:2, c:3} + + assert_operator(h1, :<=, h1) + assert_operator(h1, :<=, h2) + assert_not_operator(h2, :<=, h1) + assert_operator(h2, :<=, h2) + + assert_operator(h1, :>=, h1) + assert_not_operator(h1, :>=, h2) + assert_operator(h2, :>=, h1) + assert_operator(h2, :>=, h2) + + assert_not_operator(h1, :<, h1) + assert_operator(h1, :<, h2) + assert_not_operator(h2, :<, h1) + assert_not_operator(h2, :<, h2) + + assert_not_operator(h1, :>, h1) + assert_not_operator(h1, :>, h2) + assert_operator(h2, :>, h1) + assert_not_operator(h2, :>, h2) + end + class TestSubHash < TestHash class SubHash < Hash def reject(*) |