Class: Propr::Runner
Instance Attribute Summary collapse
-
#maxskip ⇒ Object
readonly
Returns the value of attribute maxskip.
-
#minpass ⇒ Object
readonly
Returns the value of attribute minpass.
Instance Method Summary collapse
-
#initialize(minpass, maxskip, scale) ⇒ Runner
constructor
A new instance of Runner.
- #run(property, generator) ⇒ Object
Constructor Details
#initialize(minpass, maxskip, scale) ⇒ Runner
Returns a new instance of Runner.
5 6 7 8 |
# File 'lib/propr/runner.rb', line 5 def initialize(minpass, maxskip, scale) @minpass, @maxskip, @scale = minpass, maxskip, scale || lambda {|*_| 1 } end |
Instance Attribute Details
#maxskip ⇒ Object (readonly)
Returns the value of attribute maxskip.
3 4 5 |
# File 'lib/propr/runner.rb', line 3 def maxskip @maxskip end |
#minpass ⇒ Object (readonly)
Returns the value of attribute minpass.
3 4 5 |
# File 'lib/propr/runner.rb', line 3 def minpass @minpass end |
Instance Method Details
#run(property, generator) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/propr/runner.rb', line 10 def run(property, generator) passed = 0 skipped = 0 wrapped = Dsl::Check.wrap(generator) until passed >= @minpass or skipped >= @maxskip input, _, success = Random.run(wrapped, @scale.call(passed, skipped, @minpass, @maxskip)) # Generator should've returned an argument list. Except, for convenience, # single-argument properties should have generators which return a single # value, not an argument list, and we'll make it an argument list *here*. input = property.arity == 1 ? [input] : input if success begin result = property.call(*input) # result = property.arity == 1 ? # property.call(input) : property.call(*input) if result passed += 1 else # Falsifiable return [false, passed, skipped, input] end rescue GuardFailure => e # GuardFailure in property skipped += 1 rescue raise Failure.new($!, input, nil, passed, skipped)#, nil, location end else # GuardFailure in generator skipped += 1 end end # Might have not passed enough tests [passed >= @minpass, passed, skipped, nil] end |