Class: Set
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 19 20 21 |
# File 'lib/propr/random/set.rb', line 10 def random( = {}, m = Propr::Random) min = [:min] || 0 max = [:max] || 10 item = yield # @todo: Be sure we created enough *unique* elements m.bind(Integer.random(.merge(min: min, max: max))) do |size| m.bind(m.sequence([item]*size)) do |xs| m.unit(xs.to_set) end end end |
Instance Method Details
#random(options = {}, m = Propr::Random) ⇒ Object
2 3 4 5 6 |
# File 'lib/propr/random/set.rb', line 2 def random( = {}, m = Propr::Random) m.bind(m.rand(size)) do |index| m.unit(self.to_a[index]) end end |
#shrink ⇒ Array<Set>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/propr/shrink/set.rb', line 3 def shrink return Array.new if empty? array = to_a array.combination(size - 1).map(&:to_set).tap do |shrunken| shrunken << Set.new size.times do |n| head = array[0, n] tail = array[n+1..-1] item = array[n] shrunken.concat(item.shrink.map{|m| (head + [m] + tail).to_set }) end end end |