Class: Pbt::Check::Property
- Inherits:
-
Object
- Object
- Pbt::Check::Property
- Defined in:
- lib/pbt/check/property.rb
Overview
Represents a property to be tested. This class holds an arbitrary to generate values and a predicate to test them.
Instance Method Summary collapse
-
#generate(rng) ⇒ Object
Generate a next value to test.
-
#initialize(arb, &predicate) ⇒ Property
constructor
A new instance of Property.
-
#run(val) ⇒ void
Run the predicate with the generated ‘val`.
-
#run_in_ractor(val) ⇒ Ractor
Run the predicate with the generated ‘val` in a Ractor.
-
#shrink(val) ⇒ Enumerator<Object>
Shrink the ‘val` to a smaller one.
Constructor Details
permalink #initialize(arb, &predicate) ⇒ Property
Returns a new instance of Property.
10 11 12 13 |
# File 'lib/pbt/check/property.rb', line 10 def initialize(arb, &predicate) @arb = arb @predicate = predicate end |
Instance Method Details
permalink #generate(rng) ⇒ Object
Generate a next value to test.
19 20 21 |
# File 'lib/pbt/check/property.rb', line 19 def generate(rng) @arb.generate(rng) end |
permalink #run(val) ⇒ void
This method returns an undefined value.
Run the predicate with the generated ‘val`.
36 37 38 39 40 41 42 |
# File 'lib/pbt/check/property.rb', line 36 def run(val) if val.is_a?(Hash) @predicate.call(**val) else @predicate.call(val) end end |
permalink #run_in_ractor(val) ⇒ Ractor
Run the predicate with the generated ‘val` in a Ractor. This is used only for parallel testing with Ractors.
49 50 51 |
# File 'lib/pbt/check/property.rb', line 49 def run_in_ractor(val) Ractor.new(val, &@predicate) end |
permalink #shrink(val) ⇒ Enumerator<Object>
Shrink the ‘val` to a smaller one. This is used to find the smallest failing case after a failure.
28 29 30 |
# File 'lib/pbt/check/property.rb', line 28 def shrink(val) @arb.shrink(val) end |