Skip to content
Permalink
Browse files

Merge pull request #515 from jstepien/kernel-rand

Kernel.rand nearly passes the spec
  • Loading branch information
alex committed Mar 30, 2013
2 parents abd90ba + fc3c1f3 commit e42035ad248c1b786650d71c4d77f87694653120
Showing with 13 additions and 9 deletions.
  1. +13 −0 lib-topaz/kernel.rb
  2. +0 −9 spec/tags/core/kernel/rand_tags.txt
@@ -58,4 +58,17 @@ def to_enum(method = :each, *args)
end

alias :enum_for :to_enum

def rand(max = 1.0)
if max.is_a?(Numeric)
if max < 0
return Random.rand(-max)
elsif max.zero?
return Random.rand
elsif max.is_a?(Float) and max > 1
return Random.rand(max).ceil
end
end
Random.rand(max)
end
end
@@ -1,10 +1 @@
fails:Kernel.rand is a private method
fails:Kernel.rand returns a float if no argument is passed
fails:Kernel.rand returns an integer for an integer argument
fails:Kernel.rand returns an integer for a float argument greater than 1
fails:Kernel.rand returns a float for an argument between -1 and 1
fails:Kernel.rand ignores the sign of the argument
fails:Kernel.rand never returns a value greater or equal to 1.0 with no arguments
fails:Kernel.rand never returns a value greater or equal to any passed in max argument
fails:Kernel.rand calls to_int on its argument
fails:Kernel.rand returns a float for an range argument where max is < 1

0 comments on commit e42035a

Please sign in to comment.