Class: Array

Inherits:
Object show all
Defined in:
lib/propr/random/array.rb,
lib/propr/shrink/array.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.random(options = {}, m = Propr::Random) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/propr/random/array.rb', line 10

def random(options = {}, m = Propr::Random)
  min  = options[:min] || 0
  max  = options[:max] || 10
  item = yield

  m.bind(Integer.random(min: min, max: max, center: min)) do |size|
    m.sequence([item]*size)
  end
end

Instance Method Details

#random(options = {}, m = Propr::Random) ⇒ Object



2
3
4
5
6
# File 'lib/propr/random/array.rb', line 2

def random(options = {}, m = Propr::Random)
  m.bind(m.rand(size)) do |index|
    m.unit(self[index])
  end
end

#shrinkArray<Array>

Returns:



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/propr/shrink/array.rb', line 3

def shrink
  return Array.new if empty?

  combination(size - 1).to_a.tap do |shrunken|
    shrunken << []
    size.times do |n|
      head = self[0, n]
      tail = self[n+1..-1]
      item = self[n]
      shrunken.concat(item.shrink.map{|m| head + [m] + tail })
    end
  end
end