Skip to content

Commit

Permalink
Fix sized enumerators of Numeric#step with Infinity (#3683)
Browse files Browse the repository at this point in the history
* Add specs for sized enumerator of Numeric#step with infinity limit

* Fix sized enumerator of Numeric#step with Infinity
kachick authored and brixen committed Jul 22, 2016
1 parent 8721492 commit cf086d9
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/numeric_mirror.rb
Original file line number Diff line number Diff line change
@@ -29,6 +29,14 @@ def step_size(limit, step, to, by)
asc = values[3]
is_float = values[4]

if limit == Float::INFINITY
if step == Float::INFINITY
return 1
else
return Float::INFINITY
end
end

return Float::INFINITY if step == 0

if is_float
10 changes: 9 additions & 1 deletion spec/ruby/core/numeric/step_spec.rb
Original file line number Diff line number Diff line change
@@ -72,6 +72,14 @@
it "should return infinity_value when step is 0.0" do
1.step(to: 2, by: 0.0).size.should == infinity_value
end

it "should return infinity_value when the limit is Float::INFINITY" do
1.step(to: Float::INFINITY, by: 42).size.should == infinity_value
end

it "should return 1 when the both limit and step are Float::INFINITY" do
1.step(to: Float::INFINITY, by: Float::INFINITY).size.should == 1
end
end
end
end
@@ -130,7 +138,7 @@
# a mix of positional and keyword arguments.
# It's needed to test numeric_step behaviour with positional mixed with
# keyword arguments.
@step_args = ->(*args) do
@step_args = ->(*args) do
if args.size == 2
[args[0], {by: args[1]}]
else

0 comments on commit cf086d9

Please sign in to comment.