diff options
| author | Takashi Kokubun <takashikkbn@gmail.com> | 2025-01-14 18:00:02 -0800 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2025-01-14 18:00:02 -0800 |
| commit | 7b9caf19ba480d168ef4c5e93690735240975c91 (patch) | |
| tree | 14bd4f91cc4b4a44b439ac68dbe3354b8730dcdb /test/ruby | |
| parent | 12a0807965624a0be37dc79371a69b5d787cc8d1 (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 825c191d87..ec24740d75 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -1044,4 +1044,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 |
