Skip to content

MappedArbitrary ​

Rasuvaeff\PropertyTesting\Arbitrary\MappedArbitrary

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

Implements: Enumerable, ArbitraryInterface

Type parameters:

  • TInner of mixed = mixed
  • TOutput of mixed = mixed

Transforms each value produced by a delegate arbitrary through a pure function.

The whole shrink tree is mapped: shrinking happens in the inner (source) domain and the function is re-applied to every candidate, so the shrunk counterexample is reported in the transformed domain. The function must be pure — it runs once per generated value and once per visited candidate.

Constructor ​

php
__construct(
    \ArbitraryInterface<\Arbitrary\TInner> $inner,
    callable $map,
)
ParameterTypeDefaultDescription
$inner\ArbitraryInterface<\Arbitrary\TInner>required
$mapcallablerequired

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.

domainSize() ​

php
domainSize(): ?int

The source's size: a map that sends two source values to one output walks both, so this is an upper bound on the distinct outputs.

enumerate() ​

php
enumerate(): iterable

Every value of the domain, once each, as a shrinkable node with the same tree generate() would give it, in a fixed order that does not depend on any seed. Only meaningful when domainSize() is not null; an implementation may throw otherwise.

Documentation inherited from Enumerable.

Throws:

  • LogicException — When the source has no finite domain (\Rasuvaeff\PropertyTesting\Arbitrary\domainSize() is null).