Skip to content

OneOfArbitrary ​

Rasuvaeff\PropertyTesting\Arbitrary\OneOfArbitrary

Class — Package: property-testing-core — Source — Version: v1.0.0-1-g88fdee2

Implements: Swarmable, Enumerable, ArbitraryInterface

Type parameters:

  • TValue of mixed = mixed

Picks a value uniformly at random from a fixed set.

Values are used verbatim: an ArbitraryInterface among them is rejected rather than handed to the body as data. Earlier values are considered "smaller": a failing value shrinks through the distinct values listed before it, so put simpler values first. Because the index strictly decreases on every step, shrinking terminates even when several values keep failing. Use this for enumerations and small tagged unions.

Constructor ​

php
__construct(
    \Arbitrary\TValue $values,
)
ParameterTypeDefaultDescription
$valuesArbitrary\TValuerequired

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.

variantCount() ​

php
variantCount(): int

How many variants this generator chooses among. Must be positive: a choice generator with nothing to choose from is not a choice, and Arbitrary\SwarmArbitrary rejects a source that reports otherwise rather than drawing from an empty alphabet. Deliberately typed int and not int<1, max> — the bound is a promise implementations make, and a swarm still checks it at runtime because it cannot analyse the implementations it will be handed.

Documentation inherited from Swarmable.

domainSize() ​

php
domainSize(): int

How many distinct values enumerate() walks, or null when the domain is not finite in this configuration. Saturates at PHP_INT_MAX rather than overflowing — a budget compares against it, nothing computes with it. An upper bound is acceptable where the exact count is not known without walking (a filter over a finite source).

Documentation inherited from Enumerable.

enumerate() ​

php
enumerate(): iterable

In the listed order; a value listed twice is walked twice.

withVariants() ​

php
withVariants(list<int> $indices): self

A copy of this generator that chooses only among the variants at $indices.

Documentation inherited from Swarmable.

  • $indices — Variant positions to keep, each in [0, variantCount() - 1].

Throws:

  • InvalidArgumentException — When an index falls outside the values.