Skip to content

SubsetArbitrary

Rasuvaeff\PropertyTesting\Arbitrary\SubsetArbitrary

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

Implements: ArbitraryInterface

Type parameters:

  • TValue of mixed = mixed

Generates subsets of a fixed ordered set: every result is a list of distinct elements of the source list, in the source list's order. Distribution is uniform over the allowed sizes first (each size in [minSize, maxSize] is equally likely), then uniform over the combinations of that size — small and large subsets appear equally often, which a uniform-over-all-subsets draw would not give.

Shrinking reduces the subset's size first (empty set, halved prefixes, single-element removals), then moves each kept element toward earlier positions of the source list — the minimal falsifying subset therefore gravitates to a short prefix of the source. Every candidate strictly decreases the pair (size, sum of source positions), so the descent is finite by construction; no filtering, no discards.

Constructor

php
__construct(
    list<\Arbitrary\TValue> $values,
    int $minSize = 0,
    ?int $maxSize = NULL,
)
ParameterTypeDefaultDescription
$valueslist<\Arbitrary\TValue>requiredThe source set, as an ordered list. Duplicates (strict comparison) are rejected — a set has no duplicate members.
$minSizeint0
$maxSize?intNULLNull means the full source size.

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.