FilteredArbitrary
Rasuvaeff\PropertyTesting\Arbitrary\FilteredArbitrary
Class — Package: property-testing-core — Source — Version: v1.0.0-1-g88fdee2
Implements: Enumerable, ArbitraryInterface
Type parameters:
TInner of mixed = mixed
Generates values from a delegate arbitrary, retrying until a predicate holds.
Filtering is bounded: after Arbitrary\FilteredArbitrary::MAX_ATTEMPTS consecutive rejections the generator throws GenerationExhaustedException 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.
domainSize()
domainSize(): ?intThe source's size — an upper bound, since the predicate is only applied while walking.
enumerate()
enumerate(): iterableEvery value of the domain, once each, as a shrinkable node with the same tree generate() would give it, in a fixed order that does not depend on any seed. Only meaningful when domainSize() is not null; an implementation may throw otherwise.
Documentation inherited from Enumerable.
Throws:
LogicException— When the source has no finite domain (\Rasuvaeff\PropertyTesting\Arbitrary\domainSize() is null).