diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-17 15:08:33 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-17 15:08:33 +0000 |
commit | d5595a96272419a495e3766dc9c96b5884c00efd (patch) | |
tree | 4d6b6911dd87338b8ec012e07ef56853fc9cf30c /test | |
parent | 41d002bbad90e2c290d3854a9543c907e86ce210 (diff) | |
download | ruby-d5595a96272419a495e3766dc9c96b5884c00efd.tar.gz |
Optimize enum_sum for a range from int to int
* enum.c (enum_sum): Optimize for a range from int to int.
* test/ruby/test_enum.rb (test_range_sum): Move from test_range.rb,
and add assertions for some conditions.
* test/ruby/test_enum.rb (test_hash_sum): Move from test_hash.rb.
* test/ruby/test_hash.rb, test/ruby/test_range.rb: Remove test_sum.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55034 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_enum.rb | 16 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 5 | ||||
-rw-r--r-- | test/ruby/test_range.rb | 5 |
3 files changed, 16 insertions, 10 deletions
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index ed464a285e..df75a80c50 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -905,4 +905,20 @@ class TestEnumerable < Test::Unit::TestCase assert_equal(6, [1r, 2, 3r].each.sum) EOS end + + def test_hash_sum + histogram = { 1 => 6, 2 => 4, 3 => 3, 4 => 7, 5 => 5, 6 => 4 } + assert_equal(100, histogram.sum {|v, n| v * n }) + end + + def test_range_sum + assert_int_equal(55, (1..10).sum) + assert_float_equal(55.0, (1..10).sum(0.0)) + assert_int_equal(90, (5..10).sum {|v| v * 2 }) + assert_float_equal(90.0, (5..10).sum(0.0) {|v| v * 2 }) + assert_int_equal(0, (2..0).sum) + assert_int_equal(5, (2..0).sum(5)) + assert_int_equal(2, (2..2).sum) + assert_int_equal(42, (2...2).sum(42)) + end end diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 03a712d85b..6a8e7f0423 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1415,11 +1415,6 @@ 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(*) diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index 431ed0dc30..2bff105936 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -631,9 +631,4 @@ class TestRange < Test::Unit::TestCase end (a.."c").each {|x, &b| assert_nil(b)} end - - def test_sum - assert_equal(55, (1..10).sum) - assert_equal(110, (1..10).sum {|v| v * 2 }) - end end |