From f15069338debcaab151b589de9bcc32acffa6ca0 Mon Sep 17 00:00:00 2001 From: mrkn Date: Mon, 6 Aug 2018 09:08:28 +0000 Subject: enumerator.c: Introduce Enumerator::ArithmeticSequence This commit introduces new core class Enumerator::ArithmeticSequence. Enumerator::ArithmeticSequence is a subclass of Enumerator, and represents a number generator of an arithmetic sequence. After this commit, Numeric#step and Range#step without blocks returned an ArithmeticSequence object instead of an Enumerator. This class introduces the following incompatibilities: - You can create a zero-step ArithmeticSequence, and its size is not ArgumentError, but Infinity. - You can create a negative-step ArithmeticSequence from a range. [ruby-core:82816] [Feature #13904] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_range.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/ruby/test_range.rb') diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index eada19cfb6..a845dc4929 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -222,7 +222,11 @@ class TestRange < Test::Unit::TestCase (0..).step(2) {|x| a << x; break if a.size == 10 } assert_equal([0, 2, 4, 6, 8, 10, 12, 14, 16, 18], a) - assert_raise(ArgumentError) { (0..10).step(-1) { } } + assert_kind_of(Enumerator::ArithmeticSequence, (0..10).step) + assert_kind_of(Enumerator::ArithmeticSequence, (0..10).step(2)) + assert_kind_of(Enumerator::ArithmeticSequence, (0..10).step(0.5)) + assert_kind_of(Enumerator::ArithmeticSequence, (10..0).step(-1)) + assert_raise(ArgumentError) { (0..10).step(0) { } } assert_raise(ArgumentError) { (0..).step(-1) { } } assert_raise(ArgumentError) { (0..).step(0) { } } -- cgit v1.2.3