Module
poke/generator
src/poke/generator.pookaGenerate a little trouble, then make it smaller.
Generators carry their seed explicitly. Sampling never changes global random state, so a failure can be replayed even when Pooka runs tests in parallel. The Generator interface is open: applications may supply their own samples and shrinking rules. This is test data, not cryptographic randomness.
API reference
class Sample(value: a, seed: Int)
A generated value and the seed for the next draw.
value: a
aseed: Int
Int
fn(a, Int) -> poke/generator.Sample(a)interface Generator(a)
Supply deterministic samples and finite, preferably smaller candidates. Shrinkers must preserve the generator's domain. Property checking bounds the number of attempts and remembers visited candidates, even for custom rules.
sample(seed: Int, size: Int) -> Sample(a)
shrink(value: a) -> List(a)
next_seed(seed: Int) -> Int
fn(Int) -> IntAdvance a Park–Miller stream. Negative and zero seeds are normalised too.
integers(minimum: Int, maximum: Int) -> Generator(Int)
fn(Int, Int) -> poke/generator.Generator(Int)Integers within inclusive bounds, with extra visits to zero and endpoints.
let sample = generator.integers(-10, 10).sample(42, 20)
assert sample.value >= -10 && sample.value <= 10
booleans() -> Generator(Bool)
fn() -> poke/generator.Generator(Bool)Both truth values, shrinking True towards False.
elements(values: List(a)) -> Generator(a)
fn(List(a)) -> poke/generator.Generator(a)Pick from a nonempty list. Shrinking tries earlier choices.
constant(value: a) -> Generator(a)
fn(a) -> poke/generator.Generator(a)Always produce one value. There is nothing smaller to try.
list_of(element: Generator(a), maximum: Int) -> Generator(List(a))
fn(poke/generator.Generator(a), Int) -> poke/generator.Generator(List(a))Lists from length zero to min(maximum, size). Nested sampling reduces size. Shrinking tries shorter lists, then smaller individual elements.
pair(left: Generator(a), right: Generator(b)) -> Generator(#(a, b))
fn(poke/generator.Generator(a), poke/generator.Generator(b)) -> poke/generator.Generator(#(a, b))Draw both halves from the same deterministic stream; shrink either half.
map(source: Generator(a), transform: fn(a) -> b) -> Generator(b)
fn(poke/generator.Generator(a), fn(a) -> b) -> poke/generator.Generator(b)Transform a generator. Arbitrary transforms have no inverse, so mapped generators deliberately do not shrink. Implement Generator for domain rules.
strings(alphabet: List(String), maximum: Int) -> Generator(String)
fn(List(String), Int) -> poke/generator.Generator(String)Strings made from a nonempty alphabet of String fragments. Empty fragments are allowed. Strings shrink to empty because fragments may span code points.