aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-10 04:49:44 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-10 04:49:44 +0000
commitbe1c0d1b8392d654d9d96d70a85a05ab5ccd1435 (patch)
tree1ee784756c3550c20b99cf618326d591689cc849 /test/ruby
parent7afd473380ed5d5828c7deaf832f3adca2e133de (diff)
downloadruby-be1c0d1b8392d654d9d96d70a85a05ab5ccd1435.tar.gz
enumerator.c: fix for non-integral argument for ArithmeticSequence#last
This fixes a bug of Enumerator::ArithmeticSequence#last in the case that a non-integral argument is passed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_arithmetic_sequence.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/ruby/test_arithmetic_sequence.rb b/test/ruby/test_arithmetic_sequence.rb
index fcabc8a8c7..a9978733fa 100644
--- a/test/ruby/test_arithmetic_sequence.rb
+++ b/test/ruby/test_arithmetic_sequence.rb
@@ -195,6 +195,30 @@ class TestArithmeticSequence < Test::Unit::TestCase
assert_equal([2.0, 0.0, -2.0], seq.last(3))
end
+ def test_last_with_float
+ res = (1..3).step(2).last(2.0)
+ assert_equal([1, 3], res)
+ assert_instance_of Integer, res[0]
+ assert_instance_of Integer, res[1]
+
+ res = (1..3).step(2).last(5.0)
+ assert_equal([1, 3], res)
+ assert_instance_of Integer, res[0]
+ assert_instance_of Integer, res[1]
+ end
+
+ def test_last_with_rational
+ res = (1..3).step(2).last(2r)
+ assert_equal([1, 3], res)
+ assert_instance_of Integer, res[0]
+ assert_instance_of Integer, res[1]
+
+ res = (1..3).step(2).last(10/2r)
+ assert_equal([1, 3], res)
+ assert_instance_of Integer, res[0]
+ assert_instance_of Integer, res[1]
+ end
+
def test_to_a
assert_equal([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1.step(10).to_a)
assert_equal([1, 3, 5, 7, 9], 1.step(10, 2).to_a)