Class: Forall::Input::Some

Inherits:
Forall::Input show all
Defined in:
lib/forall/input.rb

Overview

Randomized sample of possible input values

Instance Method Summary collapse

Methods inherited from Forall::Input

build, exhaustive, sampled, #shrink

Constructor Details

#initialize(block) ⇒ Some

Returns a new instance of Some.



83
84
85
86
# File 'lib/forall/input.rb', line 83

def initialize(block)
  @block  = block
  @shrink = nil
end

Instance Method Details

#each(random, *args) ⇒ Object



100
101
102
103
104
# File 'lib/forall/input.rb', line 100

def each(random, *args)
  while true
    yield @block.call(random, *args)
  end
end

#exhaustive?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/forall/input.rb', line 88

def exhaustive?
  false
end

#sample(random, count: nil) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/forall/input.rb', line 92

def sample(random, count: nil)
  if count.nil?
    @block.call(random)
  else
    count.times.map { @block.call(random) }
  end
end