Skip to content

Commit cf086d9

Browse files
kachickbrixen
authored andcommittedJul 22, 2016
Fix sized enumerators of Numeric#step with Infinity (#3683)
* Add specs for sized enumerator of Numeric#step with infinity limit * Fix sized enumerator of Numeric#step with Infinity
1 parent 8721492 commit cf086d9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎core/numeric_mirror.rb

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ def step_size(limit, step, to, by)
2929
asc = values[3]
3030
is_float = values[4]
3131

32+
if limit == Float::INFINITY
33+
if step == Float::INFINITY
34+
return 1
35+
else
36+
return Float::INFINITY
37+
end
38+
end
39+
3240
return Float::INFINITY if step == 0
3341

3442
if is_float

‎spec/ruby/core/numeric/step_spec.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@
7272
it "should return infinity_value when step is 0.0" do
7373
1.step(to: 2, by: 0.0).size.should == infinity_value
7474
end
75+
76+
it "should return infinity_value when the limit is Float::INFINITY" do
77+
1.step(to: Float::INFINITY, by: 42).size.should == infinity_value
78+
end
79+
80+
it "should return 1 when the both limit and step are Float::INFINITY" do
81+
1.step(to: Float::INFINITY, by: Float::INFINITY).size.should == 1
82+
end
7583
end
7684
end
7785
end
@@ -130,7 +138,7 @@
130138
# a mix of positional and keyword arguments.
131139
# It's needed to test numeric_step behaviour with positional mixed with
132140
# keyword arguments.
133-
@step_args = ->(*args) do
141+
@step_args = ->(*args) do
134142
if args.size == 2
135143
[args[0], {by: args[1]}]
136144
else

0 commit comments

Comments
 (0)