Sha256: 32e37ef92285e6104672409cd2e0dd93b36b0ba9945338ab97df3ad26c4d45e1

Contents?: true

Size: 1.58 KB

Versions: 52

Compression:

Stored size: 1.58 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

describe "Kernel.rand" do
  it "is a private method" do
    Kernel.should have_private_instance_method(:rand)
  end

  it "returns a float if no argument is passed" do
    rand.should be_kind_of(Float)
  end

  it "returns an integer for an integer argument" do
    rand(77).should be_kind_of(Integer)
  end

  it "returns an integer for a float argument greater than 1" do
    rand(1.3).should be_kind_of(Integer)
  end

  it "returns a float for an argument between -1 and 1" do
    rand(-0.999).should be_kind_of(Float)
    rand(-0.01).should be_kind_of(Float)
    rand(0).should be_kind_of(Float)
    rand(0.01).should be_kind_of(Float)
    rand(0.999).should be_kind_of(Float)
  end

  it "ignores the sign of the argument" do
    [0, 1, 2, 3].should include(rand(-4))
  end

  it "never returns a value greater or equal to 1.0 with no arguments" do
    1000.times do
      (0...1.0).should include(rand)
    end
  end

  it "never returns a value greater or equal to any passed in max argument" do
    1000.times do
      (0...100).to_a.should include(rand(100))
    end
  end

  ruby_version_is ""..."1.9" do
    it "calls to_i on its argument" do
      l = mock('limit')
      l.should_receive(:to_i).and_return 7

      rand l
    end
  end

  ruby_version_is "1.9" do
    it "calls to_int on its argument" do
      l = mock('limit')
      l.should_receive(:to_int).and_return 7

      rand l
    end
  end
end

describe "Kernel#rand" do
  it "needs to be reviewed for spec completeness"
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/core/kernel/rand_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/core/kernel/rand_spec.rb