diff options
| author | Takashi Kokubun <takashikkbn@gmail.com> | 2025-02-13 18:01:42 -0800 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2025-02-13 18:01:42 -0800 |
| commit | bc359b9971088ff921e26346f395c70640654e9e (patch) | |
| tree | 4c1e399623c70a216d847935d9294da2db71206b /test/ruby | |
| parent | b65cea74295358265dfabc9e1f4d107b21e58e58 (diff) | |
merge revision(s) b176d4f52e4af67654814dab3e9c5f4bf9170e54: [Backport #21008]
[Bug #21008] Normalize before sum to float
After switching to `Float`-mode when summing `Numeric` objects,
normalization for `Float` is still needed.
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_enumerator.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 7599d43463..cd62cd8acb 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -1043,4 +1043,19 @@ class TestEnumerator < Test::Unit::TestCase assert_raise(FrozenError) { e.feed 1 } assert_raise(FrozenError) { e.rewind } end + + def test_sum_of_numeric + num = Class.new(Numeric) do + attr_reader :to_f + def initialize(val) + @to_f = Float(val) + end + end + + ary = [5, 10, 20].map {|i| num.new(i)} + + assert_equal(35.0, ary.sum) + enum = ary.each + assert_equal(35.0, enum.sum) + end end |
