summaryrefslogtreecommitdiff
path: root/test/ruby/test_numeric.rb
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-29 12:07:33 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-29 12:07:33 +0000
commit74d6b68229bd9cd85bc412309aa1a17c9529b374 (patch)
tree786d0e5492a986565a3d21dfd0b636851626344e /test/ruby/test_numeric.rb
parent60eeeb70df15cc77724b454d40e02d040da8f1f1 (diff)
merge revision(s) r45187,r45205,r45206,r45212,r45213: [Backport #9570]
* numeric.c (ruby_num_interval_step_size): check signs and get rid of implementation dependent behavior of negative division. [ruby-core:61106] [Bug #9570] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@46226 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_numeric.rb')
-rw-r--r--test/ruby/test_numeric.rb23
1 files changed, 19 insertions, 4 deletions
diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb
index f2c1a51ba2..f3fc663377 100644
--- a/test/ruby/test_numeric.rb
+++ b/test/ruby/test_numeric.rb
@@ -223,6 +223,8 @@ class TestNumeric < Test::Unit::TestCase
end
def test_step
+ i, bignum = 32, 1 << 30
+ bignum <<= (i <<= 1) - 32 until bignum.is_a?(Bignum)
assert_raise(ArgumentError) { 1.step(10, 1, 0) { } }
assert_raise(ArgumentError) { 1.step(10, 1, 0).size }
assert_raise(ArgumentError) { 1.step(10, 0) { } }
@@ -238,6 +240,17 @@ class TestNumeric < Test::Unit::TestCase
assert_nothing_raised { 1.step(by: nil) }
assert_nothing_raised { 1.step(by: nil).size }
+ assert_equal(bignum*2+1, (-bignum).step(bignum, 1).size)
+ assert_equal(bignum*2, (-bignum).step(bignum-1, 1).size)
+
+ assert_equal(10+1, (0.0).step(10.0, 1.0).size)
+
+ i, bigflo = 1, bignum.to_f
+ i <<= 1 until (bigflo - i).to_i < bignum
+ bigflo -= i >> 1
+ assert_equal(bigflo.to_i, (0.0).step(bigflo-1.0, 1.0).size)
+ assert_operator((0.0).step(bignum.to_f, 1.0).size, :>=, bignum) # may loose precision
+
assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 10]
assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, to: 10]
assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, to: 10, by: nil]
@@ -248,15 +261,17 @@ class TestNumeric < Test::Unit::TestCase
assert_step [10, 8, 6, 4, 2], [10, to: 1, by: -2]
assert_step [1.0, 3.0, 5.0, 7.0, 9.0], [1.0, 10.0, 2.0]
assert_step [1.0, 3.0, 5.0, 7.0, 9.0], [1.0, to: 10.0, by: 2.0]
- assert_step [1], [1, 10, 2**32]
- assert_step [1], [1, to: 10, by: 2**32]
+ assert_step [1], [1, 10, bignum]
+ assert_step [1], [1, to: 10, by: bignum]
+ assert_step [], [2, 1, 3]
+ assert_step [], [-2, -1, -3]
assert_step [3, 3, 3, 3], [3, by: 0], inf: true
- assert_step [10], [10, 1, -(2**32)]
+ assert_step [10], [10, 1, -bignum]
assert_step [], [1, 0, Float::INFINITY]
assert_step [], [0, 1, -Float::INFINITY]
- assert_step [10], [10, to: 1, by: -(2**32)]
+ assert_step [10], [10, to: 1, by: -bignum]
assert_step [10, 11, 12, 13], [10], inf: true
assert_step [10, 9, 8, 7], [10, by: -1], inf: true