DictionaryArbitrary
Rasuvaeff\PropertyTesting\Arbitrary\DictionaryArbitrary
Class — Package: property-testing-core — Source — Version: v0.1.0-12-g86ead85
Implements: ArbitraryInterface
Type parameters:
TKey of array-key = mixedTValue of mixed = mixed
Generates associative arrays (maps) whose keys come from a key arbitrary and whose values come from a value arbitrary, then shrinks them by size toward the empty map and value-by-value through each value's own shrink tree (keys are never shrunk).
Keys must be PHP array keys (int or string); a key arbitrary that produces anything else is a configuration error and throws. Generation draws a size, then draws distinct keys (each paired with a value) up to an attempt budget, so seeded runs are reproducible. When the key space runs out of fresh keys the map may be smaller than the drawn size, but it is NEVER smaller than $minSize: an unreachable minimum throws GenerationExhausted rather than hand the property a too-small map.
Constructor
__construct(
\ArbitraryInterface<\Arbitrary\TKey> $key,
\ArbitraryInterface<\Arbitrary\TValue> $value,
int $minSize = 0,
int $maxSize = 100,
)| Parameter | Type | Default | Description |
|---|---|---|---|
$key | \ArbitraryInterface<\Arbitrary\TKey> | required | |
$value | \ArbitraryInterface<\Arbitrary\TValue> | required | |
$minSize | int | 0 | |
$maxSize | int | 100 |
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.