kotest-property / io.kotest.property / Gen

Gen

interface Gen<out A>

A Gen is responsible for providing values to be used in property testing. You can think of it as like an input stream for values. Each arg will provide data for a specific type .

Gens can be created in two ways: with arbitrary (random) values from instances of Arb and exhaustive values over a closed space from instances of Exhaustive.

Arbs generate random values across a given space. The values may be repeated, and some values may never be generated at all. For example generating 1000 random integers between 0 and Int.MAX will clearly not return all possible values, and some values may happen to be generated more than once.

Exhaustives generate all values from a given space. This is useful when you want to ensure every value in that space is used. For instance for enum values, it is usually more helpful to ensure each enum is used, rather than picking randomly from the enums values.

Both types of gens can be mixed and matched in property tests. For example, you could test a function with 100 random positive integers (arbitrary) alongside every even number from 0 to 200 (exhaustive).

Functions

generate

abstract fun generate(rs: RandomSource): Sequence<Sample<A>>

minIterations

The minimum iteration count required for this Gen to be invoked. Requesting a property test with fewer than this cound will result in an exception.

abstract fun minIterations(): Int

Extension Functions

merge

Returns a new Gen which will merge the values from this gen and the values of the supplied gen together, taking one from each in turn.

fun <A, B : A> Gen<A>.merge(other: Gen<B>): Gen<A>

Inheritors

Arb

An Arb (for arbitrary) is a provider of property test data in two categories: edgecases and samples.

interface Arb<A> : Gen<A>

Exhaustive

An exhaustive is a type of Gen which generates an exhaustive set of values from a defined range.

interface Exhaustive<A> : Gen<A>