From 161ece479598629f4ace4fa23bfea7bc1331a8a0 Mon Sep 17 00:00:00 2001 From: mrkn Date: Thu, 24 Jan 2019 05:30:42 +0000 Subject: numeric.c: Fix negative step with float components * numeric.c (ruby_float_step): fix negative step with float components. * test/ruby/test_numeric.c (test_step_bug15537): add tests. * test/ruby/test_range.c (test_step_bug15537): add tests. [Bug #15537] [ruby-core:91101] From: shuujii (Shuji KOBAYASHI) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_numeric.rb | 14 ++++++++++++++ test/ruby/test_range.rb | 5 +++++ 2 files changed, 19 insertions(+) (limited to 'test') diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb index e48c3448e8..f48bce5411 100644 --- a/test/ruby/test_numeric.rb +++ b/test/ruby/test_numeric.rb @@ -339,6 +339,20 @@ class TestNumeric < Test::Unit::TestCase assert_step [bignum]*4, [bignum, by: 0, to: 0], inf: true end + def test_step_bug15537 + assert_step [10.0, 8.0, 6.0, 4.0, 2.0], [10.0, 1, -2] + assert_step [10.0, 8.0, 6.0, 4.0, 2.0], [10.0, to: 1, by: -2] + assert_step [10.0, 8.0, 6.0, 4.0, 2.0], [10.0, 1, -2] + assert_step [10.0, 8.0, 6.0, 4.0, 2.0], [10, to: 1.0, by: -2] + assert_step [10.0, 8.0, 6.0, 4.0, 2.0], [10, 1.0, -2] + + assert_step [10.0, 9.0, 8.0, 7.0], [10, by: -1.0], inf: true + assert_step [10.0, 9.0, 8.0, 7.0], [10, by: -1.0, to: nil], inf: true + assert_step [10.0, 9.0, 8.0, 7.0], [10, nil, -1.0], inf: true + assert_step [10.0, 9.0, 8.0, 7.0], [10.0, by: -1], inf: true + assert_step [10.0, 9.0, 8.0, 7.0], [10.0, nil, -1], inf: true + end + def test_num2long assert_raise(TypeError) { 1 & nil } assert_raise(TypeError) { 1 & 1.0 } diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index 65f3a8974d..6a2081fcd2 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -322,6 +322,11 @@ class TestRange < Test::Unit::TestCase assert_equal(["a", "b", "c"], a) end + def test_step_bug15537 + assert_equal([10.0, 9.0, 8.0, 7.0], (10 ..).step(-1.0).take(4)) + assert_equal([10.0, 9.0, 8.0, 7.0], (10.0 ..).step(-1).take(4)) + end + def test_percent_step aseq = (1..10) % 2 assert_equal(Enumerator::ArithmeticSequence, aseq.class) -- cgit v1.2.3