Swarmable
Rasuvaeff\PropertyTesting\Swarmable
Interface — Package: property-testing-core — Source — Version: v1.0.0-1-g88fdee2
Implements: ArbitraryInterface
Implemented by: Arbitrary\CommandSequenceArbitrary, Arbitrary\FrequencyArbitrary, Arbitrary\OneOfArbitrary, Internal\LeafFallbackArbitrary
Type parameters:
TValue of mixed = mixed
A generator that picks among a fixed, countable set of variants and can hand back a copy of itself restricted to some of them — the seam Arbitrary\SwarmArbitrary needs to do swarm testing over it.
Positions, not values, are the currency: a variant is a value in Arbitrary\OneOfArbitrary, a [weight, arbitrary] pair in Arbitrary\FrequencyArbitrary and a command generator in Arbitrary\CommandSequenceArbitrary, and an index is the one description all three share.
Implement it on a custom choice generator to make it swarmable. Everything the restricted copy is not asked about — sizes, weights, the initial model — must survive unchanged: a swarm restricts the alphabet and nothing else.
Methods
variantCount()
variantCount(): intHow 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.
withVariants()
withVariants(list<int> $indices): selfA copy of this generator that chooses only among the variants at $indices.
$indices— Variant positions to keep, each in[0, variantCount() - 1]; an index outside that range is a programmer error and throws.