Skip to content

FrequencyArbitrary

Rasuvaeff\PropertyTesting\Arbitrary\FrequencyArbitrary

ClassPackage: property-testing-coreSourceVersion: v0.1.0-12-g86ead85

Implements: ArbitraryInterface

Type parameters:

  • TValue of mixed = mixed

Weighted choice among several arbitraries: each [weight, arbitrary] pair is picked with probability proportional to its (positive integer) weight, then the chosen arbitrary produces the value.

The chosen branch's shrink tree is returned as-is, so shrinking stays within the branch that actually generated the value.

Constructor

php
__construct(
    iterable $pairs,
)
ParameterTypeDefaultDescription
$pairsiterablerequiredEach item must be [int $weight, ArbitraryInterface $arbitrary] with $weight >= 1.

Methods

generate()

php
generate(Random $random): Shrinkable

Produce 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.