diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-06 09:08:28 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-06 09:08:28 +0000 |
commit | f15069338debcaab151b589de9bcc32acffa6ca0 (patch) | |
tree | c315767e47c948fc9404d27beff43ff06b2a5199 /spec/ruby/core/numeric | |
parent | 1777e39c2a78c969d7e86af78e381c8d00df9772 (diff) | |
download | ruby-f15069338debcaab151b589de9bcc32acffa6ca0.tar.gz |
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
Diffstat (limited to 'spec/ruby/core/numeric')
-rw-r--r-- | spec/ruby/core/numeric/shared/step.rb | 6 | ||||
-rw-r--r-- | spec/ruby/core/numeric/step_spec.rb | 8 |
2 files changed, 7 insertions, 7 deletions
diff --git a/spec/ruby/core/numeric/shared/step.rb b/spec/ruby/core/numeric/shared/step.rb index fa703b7554..f058c64a50 100644 --- a/spec/ruby/core/numeric/shared/step.rb +++ b/spec/ruby/core/numeric/shared/step.rb @@ -259,15 +259,15 @@ describe :numeric_step, :shared => true do describe "when no block is given" do it "returns an Enumerator when step is 0" do - 1.send(@method, *@step_args.call(2, 0)).should be_an_instance_of(Enumerator) + 1.send(@method, *@step_args.call(2, 0)).should be_an_instance_of(Enumerator::ArithmeticSequence) end it "returns an Enumerator when not passed a block and self > stop" do - 1.send(@method, *@step_args.call(0, 2)).should be_an_instance_of(Enumerator) + 1.send(@method, *@step_args.call(0, 2)).should be_an_instance_of(Enumerator::ArithmeticSequence) end it "returns an Enumerator when not passed a block and self < stop" do - 1.send(@method, *@step_args.call(2, 3)).should be_an_instance_of(Enumerator) + 1.send(@method, *@step_args.call(2, 3)).should be_an_instance_of(Enumerator::ArithmeticSequence) end it "returns an Enumerator that uses the given step" do diff --git a/spec/ruby/core/numeric/step_spec.rb b/spec/ruby/core/numeric/step_spec.rb index a932b4df73..54133f8810 100644 --- a/spec/ruby/core/numeric/step_spec.rb +++ b/spec/ruby/core/numeric/step_spec.rb @@ -23,23 +23,23 @@ describe "Numeric#step" do describe "when no block is given" do it "returns an Enumerator when step is 0" do - 1.step(5, 0).should be_an_instance_of(Enumerator) + 1.step(5, 0).should be_an_instance_of(Enumerator::ArithmeticSequence) end it "returns an Enumerator when step is 0.0" do - 1.step(2, 0.0).should be_an_instance_of(Enumerator) + 1.step(2, 0.0).should be_an_instance_of(Enumerator::ArithmeticSequence) end describe "returned Enumerator" do describe "size" do it "raises an ArgumentError when step is 0" do enum = 1.step(5, 0) - lambda { enum.size }.should raise_error(ArgumentError) + enum.size.should == Float::INFINITY end it "raises an ArgumentError when step is 0.0" do enum = 1.step(2, 0.0) - lambda { enum.size }.should raise_error(ArgumentError) + enum.size.should == Float::INFINITY end end end |