diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-17 13:58:46 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-17 13:58:46 +0000 |
commit | eb4208cf38c45d9e1ea00b072e65313d803cd816 (patch) | |
tree | 7fca575e53a48e43b015df51e43e8fb8e26f6a62 /test/ruby/test_hash.rb | |
parent | 46e13b876cf8840ea1a030e9779944e677605ead (diff) | |
download | ruby-eb4208cf38c45d9e1ea00b072e65313d803cd816.tar.gz |
Implement Enumerable#sum
* enum.c (enum_sum): Implement Enumerable#sum.
* test/ruby/test_enum.rb (test_sum): Test sum for Enumerable.
* test/ruby/test_hash.rb (test_sum): Test sum for Hash.
* test/ruby/test_range.rb (test_sum): Test sum for Range.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55032 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_hash.rb')
-rw-r--r-- | test/ruby/test_hash.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 6a8e7f0423..03a712d85b 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1415,6 +1415,11 @@ class TestHash < Test::Unit::TestCase assert_equal([10, 20, 30], [1, 2, 3].map(&h)) end + def test_sum + histogram = { 1 => 6, 2 => 4, 3 => 3, 4 => 7, 5 => 5, 6 => 4 } + assert_equal(100, histogram.sum {|v, n| v * n }) + end + class TestSubHash < TestHash class SubHash < Hash def reject(*) |