FilteredArbitrary
Rasuvaeff\PropertyTesting\Arbitrary\FilteredArbitrary
Class — Package: property-testing-core — Source — Version: 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
__construct(
\ArbitraryInterface<\Arbitrary\TInner> $inner,
callable $predicate,
)| Parameter | Type | Default | Description |
|---|---|---|---|
$inner | \ArbitraryInterface<\Arbitrary\TInner> | required | |
$predicate | callable | required |
Methods
generate()
generate(Random $random): ShrinkableProduce 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.