Skip to content

Commit

Permalink
Showing 2 changed files with 21 additions and 107 deletions.
106 changes: 0 additions & 106 deletions spec/truffle/tags/core/numeric/step_tags.txt
Original file line number Diff line number Diff line change
@@ -1,116 +1,10 @@
fails:Numeric#step with keyword arguments doesn't raise an error when step is 0
fails:Numeric#step with keyword arguments doesn't raise an error when step is 0.0
fails:Numeric#step with keyword arguments should loop over self when step is 0 or 0.0
fails:Numeric#step with keyword arguments defaults to step = 1
fails:Numeric#step with keyword arguments does not rescue TypeError exceptions
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size should return infinity_value when step is 0
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size should return infinity_value when step is 0.0
fails:Numeric#step with keyword arguments when self, stop and step are Fixnums yields only Fixnums
fails:Numeric#step with keyword arguments when self, stop and step are Fixnums with a positive step yields while increasing self by step until stop is reached
fails:Numeric#step with keyword arguments when self, stop and step are Fixnums with a positive step yields once when self equals stop
fails:Numeric#step with keyword arguments when self, stop and step are Fixnums with a positive step does not yield when self is greater than stop
fails:Numeric#step with keyword arguments when self, stop and step are Fixnums with a negative step yields while decreasing self by step until stop is reached
fails:Numeric#step with keyword arguments when self, stop and step are Fixnums with a negative step yields once when self equals stop
fails:Numeric#step with keyword arguments when self, stop and step are Fixnums with a negative step does not yield when self is less than stop
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float yields Floats even if only self is a Float
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float yields Floats even if only stop is a Float
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float yields Floats even if only step is a Float
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a positive step yields while increasing self by step while < stop
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a positive step yields once when self equals stop
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a positive step does not yield when self is greater than stop
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a positive step is careful about not yielding a value greater than limit
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a negative step yields while decreasing self by step while self > stop
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a negative step yields once when self equals stop
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a negative step does not yield when self is less than stop
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a negative step is careful about not yielding a value smaller than limit
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a positive Infinity step yields once if self < stop
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a positive Infinity step yields once when stop is Infinity
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a positive Infinity step yields once when self equals stop
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a positive Infinity step yields once when self and stop are Infinity
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a positive Infinity step does not yield when self > stop
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a positive Infinity step does not yield when stop is -Infinity
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a negative Infinity step yields once if self > stop
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a negative Infinity step yields once if stop is -Infinity
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a negative Infinity step yields once when self equals stop
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a negative Infinity step yields once when self and stop are Infinity
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a negative Infinity step does not yield when self > stop
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a negative Infinity step does not yield when stop is Infinity
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a Infinity stop and a positive step does not yield when self is infinity
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a Infinity stop and a negative step does not yield when self is negative infinity
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a Infinity stop and a negative step does not yield when self is positive infinity
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a negative Infinity stop and a positive step does not yield when self is negative infinity
fails:Numeric#step with keyword arguments when at least one of self, stop or step is a Float with a negative Infinity stop and a negative step does not yield when self is negative infinity
fails:Numeric#step with keyword arguments when step is a String with self and stop as Floats raises an when step is a numeric representation
fails:Numeric#step with keyword arguments when step is a String with self and stop as Floats raises an with step as an alphanumeric string
fails:Numeric#step with keyword arguments when no block is given returns an Enumerator that uses the given step
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an when step is a numeric representation
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an with step as an alphanumeric string
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when self, stop and step are Fixnums and step is positive returns the difference between self and stop divided by the number of steps
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when self, stop and step are Fixnums and step is positive returns 0 if value > limit
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when self, stop and step are Fixnums and step is negative returns the difference between self and stop divided by the number of steps
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when self, stop and step are Fixnums and step is negative returns 0 if value < limit
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is positive returns the difference between self and stop divided by the number of steps
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is positive returns 0 if value > limit
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is positive returns 1 if step is infinity_value
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is negative returns the difference between self and stop divided by the number of steps
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is negative returns 0 if value < limit
fails:Numeric#step with keyword arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is negative returns 1 if step is infinity_value
fails:Numeric#step with mixed arguments doesn't raise an error when step is 0
fails:Numeric#step with mixed arguments doesn't raise an error when step is 0.0
fails:Numeric#step with mixed arguments should loop over self when step is 0 or 0.0
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size should return infinity_value when step is 0
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size should return infinity_value when step is 0.0
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums yields only Fixnums
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums with a positive step yields while increasing self by step until stop is reached
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums with a positive step yields once when self equals stop
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums with a positive step does not yield when self is greater than stop
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums with a negative step yields while decreasing self by step until stop is reached
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums with a negative step yields once when self equals stop
fails:Numeric#step with mixed arguments when self, stop and step are Fixnums with a negative step does not yield when self is less than stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float yields Floats even if only self is a Float
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float yields Floats even if only stop is a Float
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float yields Floats even if only step is a Float
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive step yields while increasing self by step while < stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive step yields once when self equals stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive step does not yield when self is greater than stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive step is careful about not yielding a value greater than limit
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative step yields while decreasing self by step while self > stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative step yields once when self equals stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative step does not yield when self is less than stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative step is careful about not yielding a value smaller than limit
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive Infinity step yields once if self < stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive Infinity step yields once when stop is Infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive Infinity step yields once when self equals stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive Infinity step yields once when self and stop are Infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive Infinity step does not yield when self > stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a positive Infinity step does not yield when stop is -Infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity step yields once if self > stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity step yields once if stop is -Infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity step yields once when self equals stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity step yields once when self and stop are Infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity step does not yield when self > stop
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity step does not yield when stop is Infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a Infinity stop and a positive step does not yield when self is infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a Infinity stop and a negative step does not yield when self is negative infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a Infinity stop and a negative step does not yield when self is positive infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity stop and a positive step does not yield when self is negative infinity
fails:Numeric#step with mixed arguments when at least one of self, stop or step is a Float with a negative Infinity stop and a negative step does not yield when self is negative infinity
fails:Numeric#step with mixed arguments when step is a String with self and stop as Fixnums raises an when step is a numeric representation
fails:Numeric#step with mixed arguments when step is a String with self and stop as Fixnums raises an with step as an alphanumeric string
fails:Numeric#step with mixed arguments when step is a String with self and stop as Floats raises an when step is a numeric representation
fails:Numeric#step with mixed arguments when step is a String with self and stop as Floats raises an with step as an alphanumeric string
fails:Numeric#step with mixed arguments when no block is given returns an Enumerator that uses the given step
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when step is a String with self and stop as Fixnums raises an when step is a numeric representation
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when step is a String with self and stop as Fixnums raises an with step as an alphanumeric string
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an when step is a numeric representation
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when step is a String with self and stop as Floats raises an with step as an alphanumeric string
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop and step are Fixnums and step is positive returns the difference between self and stop divided by the number of steps
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop and step are Fixnums and step is positive returns 0 if value > limit
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop and step are Fixnums and step is negative returns the difference between self and stop divided by the number of steps
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop and step are Fixnums and step is negative returns 0 if value < limit
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is positive returns the difference between self and stop divided by the number of steps
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is positive returns 0 if value > limit
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is positive returns 1 if step is infinity_value
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is negative returns the difference between self and stop divided by the number of steps
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is negative returns 0 if value < limit
fails:Numeric#step with mixed arguments when no block is given returned Enumerator size when self, stop or step is a Float and step is negative returns 1 if step is infinity_value
22 changes: 21 additions & 1 deletion truffle/src/main/ruby/core/numeric.rb
Original file line number Diff line number Diff line change
@@ -57,7 +57,27 @@ def <=>(other)
return nil
end

def step(limit, step=1)
def step(limit = undefined, step = undefined, by: undefined, to: undefined)
limit = if !undefined.equal?(limit) && !undefined.equal?(to)
raise ArgumentError, "to is given twice"
elsif !undefined.equal?(limit)
limit
elsif !undefined.equal?(to)
to
else
nil
end
step = if !undefined.equal?(step) && !undefined.equal?(by)
raise ArgumentError, "step is given twice"
elsif !undefined.equal?(step)
step
elsif !undefined.equal?(by)
by
else
1
end


unless block_given?
return to_enum(:step, limit, step) do
Rubinius::Mirror::Numeric.reflect(self).step_size(limit, step)

0 comments on commit 982fa88

Please sign in to comment.