diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-30 06:05:57 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-30 06:05:57 +0000 |
commit | 6f6cf042d2e348e73504258fe36f4bd27694a640 (patch) | |
tree | f4c60ff021b9912c7e78d867c7102abf218c8633 /test/ruby | |
parent | e1e3d642bfaf8f8c1a94687442cf51c897f8abdf (diff) | |
download | ruby-6f6cf042d2e348e73504258fe36f4bd27694a640.tar.gz |
enumerator.c: fix arith_seq_first for Infinity
* enumerator.c (arith_seq_first): fix for Float::INFINITY.
* test/ruby/test_arithmetic_sequence.rb: add tests.
* numeric.c (ruby_float_step_size): export for internal use.
* internal.h: add prototype declaration of ruby_float_step_size.
[ruby-core:90937][Bug #15518]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_arithmetic_sequence.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_arithmetic_sequence.rb b/test/ruby/test_arithmetic_sequence.rb index b4c93d46c7..9bff9a21c4 100644 --- a/test/ruby/test_arithmetic_sequence.rb +++ b/test/ruby/test_arithmetic_sequence.rb @@ -141,12 +141,31 @@ class TestArithmeticSequence < Test::Unit::TestCase assert_equal([], seq.first(1)) assert_equal([], seq.first(3)) + seq = 1.step(10, by: 0) + assert_equal(1, seq.first) + assert_equal([1], seq.first(1)) + assert_equal([1, 1, 1], seq.first(3)) + seq = 10.0.step(-1.0, by: -2.0) assert_equal(10.0, seq.first) assert_equal([10.0], seq.first(1)) assert_equal([10.0, 8.0, 6.0], seq.first(3)) end + def test_first_bug15518 + bug15518 = '[Bug #15518]' + seq = (1 .. 10.0).step(1) + five_float_classes = Array.new(5) { Float } + assert_equal(five_float_classes, seq.first(5).map(&:class), bug15518) + assert_equal([1.0, 2.0, 3.0, 4.0, 5.0], seq.first(5), bug15518) + seq = (1 .. Float::INFINITY).step(1) + assert_equal(five_float_classes, seq.first(5).map(&:class), bug15518) + assert_equal([1.0, 2.0, 3.0, 4.0, 5.0], seq.first(5), bug15518) + seq = (1 .. Float::INFINITY).step(1r) + assert_equal(five_float_classes, seq.first(5).map(&:class), bug15518) + assert_equal([1.0, 2.0, 3.0, 4.0, 5.0], seq.first(5), bug15518) + end + def test_last seq = 1.step(10) assert_equal(10, seq.last) |