Sha256: 610e0faed04a1c061fe567bf3f0ef1dba9d030c9daf1f90d17527c53a26a715c

Contents?: true

Size: 847 Bytes

Versions: 3

Compression:

Stored size: 847 Bytes

Contents

require_relative "../../spec_helper"

describe Array do
  around do |example|
    old_seed = srand(12072)
    example.call
    srand(old_seed)
  end

  it '#random_index' do
    20.times.collect { [].random_index }.uniq.sort.should          == [nil]
    20.times.collect { %w{a}.random_index }.uniq.sort.should       == [0]
    20.times.collect { %w{a b}.random_index }.uniq.sort.should     == [0, 1]
    20.times.collect { %w{a b c d}.random_index }.uniq.sort.should == [0, 1, 2, 3]
  end

  it '#random_element' do
    20.times.collect { [].random_element }.uniq.sort.should          == [nil]
    20.times.collect { %w{a}.random_element }.uniq.sort.should       == %w{a}
    20.times.collect { %w{a b}.random_element }.uniq.sort.should     == %w{a b}
    20.times.collect { %w{a b c d}.random_element }.uniq.sort.should == %w{a b c d}
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
more_core_extensions-1.2.0 spec/core_ext/array/random_spec.rb
more_core_extensions-1.1.2 spec/core_ext/array/random_spec.rb
more_core_extensions-1.1.1 spec/core_ext/array/random_spec.rb