UniqueArrayArbitrary
Rasuvaeff\PropertyTesting\Arbitrary\UniqueArrayArbitrary
Class — Package: property-testing-core — Source — Version: v1.0.0-1-g88fdee2
Implements: ArbitraryInterface
Type parameters:
TElement of mixed = mixed
Generates lists of pairwise-distinct elements drawn from a delegate arbitrary, and shrinks them by length toward the empty array, then element-by-element through each element's own tree — accepting only candidates that keep the list distinct.
Distinct means !== on the values, or — with a key closure — === on the int|string key it returns for each value, so a list of value objects can be unique by one field. A key of any other type is refused with \InvalidArgumentException rather than compared by identity, which would make every element "unique" and hollow the guarantee out silently.
Generation draws a size, then draws elements, skipping duplicates. Drawing is bounded: after Arbitrary\UniqueArrayArbitrary::MAX_ATTEMPTS_PER_ELEMENT attempts per requested element the generator settles for the distinct elements found so far — the result may be smaller than the drawn size, mirroring dictOf's key-collision behaviour. An element space too small to reach the minimum size throws GenerationExhaustedException rather than hand the property a too-small list.
Constructor
__construct(
\ArbitraryInterface<\Arbitrary\TElement> $element,
int $minSize = 0,
int $maxSize = 100,
null|callable $by = NULL,
)| Parameter | Type | Default | Description |
|---|---|---|---|
$element | \ArbitraryInterface<\Arbitrary\TElement> | required | |
$minSize | int | 0 | |
$maxSize | int | 100 | |
$by | `null | callable` | NULL |
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.