1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
mrkn 2019-01-30 06:05:57 +00:00
parent e1e3d642bf
commit 6f6cf042d2
4 changed files with 137 additions and 12 deletions

View file

@ -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)