Skip to content

FilteredArbitrary

Rasuvaeff\PropertyTesting\Arbitrary\FilteredArbitrary

ClassPackage: property-testing-coreSourceVersion: v0.1.0-12-g86ead85

Implements: ArbitraryInterface

Type parameters:

  • TInner of mixed = mixed

Generates values from a delegate arbitrary, retrying until a predicate holds.

Filtering is bounded: after Arbitrary\self::MAX_ATTEMPTS consecutive rejections the generator throws GenerationExhausted rather than yield a value that fails the predicate — a property never receives an out-of-domain input. Use Assume::that() inside the property when the rejection rate is high, which skips discarded runs cleanly, or Gen::flatMap() to construct dependent values without filtering at all.

Shrinking walks the inner value's tree, keeping only branches whose value satisfies the predicate (a rejected candidate's subtree is pruned with it).

Constructor

php
__construct(
    \ArbitraryInterface<\Arbitrary\TInner> $inner,
    callable $predicate,
)
ParameterTypeDefaultDescription
$inner\ArbitraryInterface<\Arbitrary\TInner>required
$predicatecallablerequired

Methods

generate()

php
generate(Random $random): Shrinkable

Produce one random value from this arbitrary's space, together with its shrink tree. Candidates must be ordered most aggressive first (typically toward a zero/empty/identity element) and every branch of the tree must be finite, so shrinking terminates.

Documentation inherited from ArbitraryInterface.