public static class Gen.DefaultImpls
A Generator, or interface Gen is responsible for generating data
to be used in property testing. Each generator will
generate data for a specific type .
The idea behind property testing is the testing framework will automatically test a range of different values, including edge cases and random values.
There are two types of values to consider.
The first are values that should always be included - those edge cases values which are common sources of bugs. For example, a generator for Ints should always include values like zero, minus 1, positive 1, Integer.MAX_VALUE and Integer.MIN_VALUE.
Another example would be for a generator for enums. That should include all the values of the enum to ensure each value is tested.
The second set of values are random values, which are used to give us a greater breadth of values tested. The Int generator example should return a random int from across the entire integer range.
interface Gen,
Int,
Int| Modifier and Type | Method and Description |
|---|---|
static Gen<T> |
filter(Gen<T> $this,
kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> pred)
Create a new
interface Gen by filtering the output of this gen. |
static Gen<T> |
filterNot(Gen<T> $this,
kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> f) |
static <U> Gen<U> |
flatMap(Gen<T> $this,
kotlin.jvm.functions.Function1<? super T,? extends arrow.Kind<io.kotlintest.properties.ForGen,? extends U>> f)
Create a new
interface Gen by mapping the output of this gen. |
static <U> Gen<U> |
map(Gen<T> $this,
kotlin.jvm.functions.Function1<? super T,? extends U> f)
Create a new
interface Gen by mapping the output of this gen. |
static <U> Gen<T> |
merge(Gen<T> $this,
Gen<U> gen)
Returns a new [
interface Gen] which will return the values from this gen and the values of
the supplied gen together. The supplied gen must be a subtype of the
type of this gen. |
static T |
next(Gen<T> $this,
kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> predicate)
Draws a random value from this generator
|
static java.lang.String |
nextPrintableString(Gen<T> $this,
int length) |
static Gen<T> |
orNull(Gen<T> $this)
Create a new
interface Gen which will return the values of this gen plus null. |
static Shrinker<T> |
shrinker(Gen<T> $this) |
static java.util.List<T> |
take(Gen<T> $this,
int amount)
Draws amount values from this generator
|
public static Gen<T> filter(Gen<T> $this, kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> pred)
Create a new interface Gen by filtering the output of this gen.
interface Genpublic static Gen<T> filterNot(Gen<T> $this, kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> f)
public static <U> Gen<U> flatMap(Gen<T> $this, kotlin.jvm.functions.Function1<? super T,? extends arrow.Kind<io.kotlintest.properties.ForGen,? extends U>> f)
Create a new interface Gen by mapping the output of this gen.
interface Genpublic static <U> Gen<U> map(Gen<T> $this, kotlin.jvm.functions.Function1<? super T,? extends U> f)
Create a new interface Gen by mapping the output of this gen.
interface Genpublic static Gen<T> orNull(Gen<T> $this)
Create a new interface Gen which will return the values of this gen plus null.
interface Genpublic static <U> Gen<T> merge(Gen<T> $this, Gen<U> gen)
Returns a new [interface Gen] which will return the values from this gen and the values of
the supplied gen together. The supplied gen must be a subtype of the
type of this gen.
interface Genpublic static java.lang.String nextPrintableString(Gen<T> $this, int length)
public static java.util.List<T> take(Gen<T> $this, int amount)
Draws amount values from this generator
This method will draw values from the generator until it generates amount values. This first draws from the
Gen.constants pool, and if necessary starts drawing from the Gen.random pool.
This is useful if you want the generated values, but don't want to execute a property test over them (for example, by using assertAll or forAll
val gen = Gen.string()
val generatedValues: List = gen.take(20)
Gen.constants,
Gen.randompublic static T next(Gen<T> $this, kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> predicate)
Draws a random value from this generator
This method will draw a single value from the Gen.random values, that matches predicate (defaults to every
value)
This expects that Gen.random will return an infinite, random sequence. Due to this, a call to Sequence.first is
made. As usually random is infinite, this should always return a different value. For fixed sequences, this will
always return the first value of the sequence.
This is useful if you want a randomized value, but don't want to execute a property test over them (for example, by using assertAll or forAll).
IMPORTANT: This will not draw from the Gen.constants pool. Only Gen.random values.
val gen = Gen.string()
val generatedValue: String = gen.next()
val filteredValue: String = gen.next { it != "hello" }
Gen.random,
Gen.random,
Sequence.first,
Gen.constants,
Gen.random