CompositeArbitrary
Rasuvaeff\PropertyTesting\Arbitrary\CompositeArbitrary
Class — Package: property-testing-core — Source — Version: v1.0.0-1-g88fdee2
Implements: ArbitraryInterface
Type parameters:
T of mixed = mixed
A value built by a body that draws several dependent values through a Draw, shrinking the draws rather than the result: each candidate re-executes the body with one recorded draw replaced by a candidate of its own tree, the draws before it replayed as they were, and the draws after it made again — each from a stream of its own position, so a later draw whose generator did not change comes back as it was, and one whose generator did change (a max drawn above a shrunk min) is re-drawn from its own stream through the new range rather than replayed as a node of the old one. Earlier draws shrink first.
The body sees no randomness other than what Draw::draw() hands it, and every stream derives from one seed captured at generation time, so a candidate is a pure function of the tape it is given. A body that refuses a shrunk prefix — throws an Exception for it, as a validating constructor does — marks that candidate as no value at all: it is skipped with its subtree, the way Shrinkable::map() skips a refused candidate. An Error propagates.
A re-executed body can draw more than the original did, so the tree has no finite bound of its own: descent depth is capped at $maxDepth — by default Arbitrary\CompositeArbitrary::MAX_DEPTH, the number the runner applies to in-body draws. Below the cap every branch is finite and no candidate equals its parent.
Constructor
__construct(
callable $body,
positive-int $maxDepth = 1000,
)| Parameter | Type | Default | Description |
|---|---|---|---|
$body | callable | required | Builds one value from the draws it takes through the seam. |
$maxDepth | positive-int | 1000 | Accepted-step bound of one descent through the tape. |
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.
$random— The run's stream; one seed is taken from it for the whole subtree.