public Gen<T>
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 | Interface and Description |
|---|---|
static class |
Gen.Companion |
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 . |
| Modifier and Type | Field and Description |
|---|---|
static Gen.Companion |
Companion |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Iterable<T> |
constants()
Returns the values that should always be used
if this generator is to give complete coverage.
|
Gen<T> |
filter(kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> pred)
Create a new
interface Gen by filtering the output of this gen. |
Gen<T> |
filterNot(kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> f) |
<U> Gen<U> |
flatMap(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. |
<U> Gen<U> |
map(kotlin.jvm.functions.Function1<? super T,? extends U> f)
Create a new
interface Gen by mapping the output of this gen. |
<U extends T> |
merge(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. |
T |
next(kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> predicate)
Draws a random value from this generator
|
java.lang.String |
nextPrintableString(int length) |
Gen<T> |
orNull()
Create a new
interface Gen which will return the values of this gen plus null. |
kotlin.sequences.Sequence<T> |
random()
Generate a random sequence of type T, that is compatible
with the constraints of this generator.
|
Shrinker<T> |
shrinker() |
java.util.List<T> |
take(int amount)
Draws amount values from this generator
|
static Gen.Companion Companion
java.lang.Iterable<T> constants()
Returns the values that should always be used if this generator is to give complete coverage.
kotlin.sequences.Sequence<T> random()
Generate a random sequence of type T, that is compatible with the constraints of this generator.
Shrinker<T> shrinker()
Gen<T> filter(kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> pred)
Create a new interface Gen by filtering the output of this gen.
interface GenGen<T> filterNot(kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> f)
<U> Gen<U> flatMap(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 Gen<U> Gen<U> map(kotlin.jvm.functions.Function1<? super T,? extends U> f)
Create a new interface Gen by mapping the output of this gen.
interface GenGen<T> orNull()
Create a new interface Gen which will return the values of this gen plus null.
interface Gen<U extends T> Gen<T> merge(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 Genjava.lang.String nextPrintableString(int length)
java.util.List<T> take(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.randomT next(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