interface Gen<T>A Generator, or 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, Int.MAX_VALUE and Int.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.
concat |
Returns a new [Gen] which will return the values from this gen and only once values of this gen exhaust it will return the values from the supplied gen. The supplied gen must be a subtype of the type of this gen. open fun <U : T> |
constants |
Returns the values that should always be used if this generator is to give complete coverage. abstract fun |
filter |
Create a new Gen by filtering the output of this gen. open fun |
filterNot |
open fun |
flatMap |
Create a new Gen by mapping the output of this gen. open fun <U> |
map |
Create a new Gen by mapping the output of this gen. open fun <U> |
merge |
Returns a new [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. open fun <U : T> |
orNull |
Create a new Gen which will return the values of this gen plus null. open fun |
random |
Generate a random sequence of type T, that is compatible with the constraints of this generator. abstract fun |
shrinker |
open fun |
assertAll |
fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>. |
assertNone |
fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>. |
filterIsInstance |
Create a new Gen by keeping only instances of U generated by this gen. This is useful if you have a type hierarchy and only want to retain a particular subtype. fun <T, U : T> Gen<T>. |
forAll |
fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>. |
forNone |
fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>. |
next |
Draws a random value from this generator fun <T> Gen<T>.fun <T> Gen<T>. |
take |
Draws amount values from this generator fun <T> Gen<T>. |
uniqueRandoms |
Creates a sequence of unique values from the contents of random, using seed to seed the random function. fun <T> Gen<T>. |
verifyAll |
fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>. |
verifyNone |
fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>.fun <A> Gen<A>. |
bigInteger |
fun Gen.Companion. |
bind |
fun <A, T> Gen.Companion.fun <A, B, T> Gen.Companion.fun <A, B, C, T> Gen.Companion.fun <A, B, C, D, T> Gen.Companion.fun <A, B, C, D, E, T> Gen.Companion.fun <A, B, C, D, E, F, T> Gen.Companion.fun <A, B, C, D, E, F, G, T> Gen.Companion. |
bool |
Returns both boolean values fun Gen.Companion. |
byte |
Returns a stream of values where each value is a randomly chosen Byte. The values always returned include the following edge cases: [Byte.MIN_VALUE, Byte.MAX_VALUE, 0] fun Gen.Companion. |
char |
Returns a stream of randomly-chosen Chars. Custom characters can be generated by providing CharRanges. Distribution will be even across the ranges of Chars. For example: Gen.char('A'..'C', 'D'..'E') Ths will choose A, B, C, D, and E each 20% of the time. fun Gen.Companion.
Returns a stream of randomly-chosen Chars. Custom characters can be generated by providing a list of CharRanges. Distribution will be even across the ranges of Chars. For example: Gen.char(listOf('A'..'C', 'D'..'E') Ths will choose A, B, C, D, and E each 20% of the time. fun Gen.Companion. |
choose |
Returns a stream of values, where each value is a random Int between the given min and max. fun Gen.Companion.
Returns a stream of values, where each value is a Long between the given min and max. fun Gen.Companion.
Returns a stream of values based on weights: fun <T : Any> Gen.Companion. |
constant |
Returns a [Gen] which always returns the same value. fun <T> Gen.Companion. |
create |
Returns a stream of values, where each value is generated from the given function fun <T> Gen.Companion. |
default |
fun <T> Gen.Companion. |
double |
Returns a stream of values where each value is a randomly chosen Double. fun Gen.Companion. |
duration |
Generates a stream of random Durations fun Gen.Companion. |
enum |
fun <T : Enum<T>> Gen.Companion. |
factors |
fun Gen.Companion. |
file |
Returns a stream of values where each value is a randomly chosen created File object. The file objects do not necessarily exist on disk. fun Gen.Companion.
Returns a stream of values where each value is a randomly chosen File object from given directory. If the Directory does not exist, an empty sequence will be returned instead. If recursive is true(default value is false) it gives files from inner directories as well recursively. fun Gen.Companion. |
float |
Returns a stream of values where each value is a randomly chosen Float. fun Gen.Companion. |
forClassName |
fun Gen.Companion.forClassName(className: String): Gen<*> |
from |
Adapts a list into a generator, where random values will be picked. May not choose every item in the list. fun <T> Gen.Companion.fun <T> Gen.Companion. |
int |
Returns a stream of values where each value is a randomly chosen Int. The values always returned include the following edge cases: [Int.MIN_VALUE, Int.MAX_VALUE, 0, 1, -1] fun Gen.Companion. |
list |
Returns a stream of values, where each value is a list of values generated by the underlying generator. fun <T> Gen.Companion. |
localDate |
Generates a stream of random LocalDates fun Gen.Companion. |
localDateTime |
Generates a stream of random LocalDateTimes fun Gen.Companion. |
localTime |
Generates a stream of random LocalTimes fun Gen.Companion. |
long |
Returns a stream of values where each value is a randomly chosen long. The values returned always include the following edge cases: [Long.MIN_VALUE, Long.MAX_VALUE, 0, 1, -1] fun Gen.Companion. |
map |
Returns a stream of values, where each value is a Map, which contains keys and values generated from the underlying generators. fun <K, V> Gen.Companion.fun <K, V> Gen.Companion. |
multiples |
fun Gen.Companion. |
nats |
Returns a stream of values where each value is a randomly chosen natural number. The values returned always include the following edge cases: Int.MAX_VALUE fun Gen.Companion. |
negativeDoubles |
fun Gen.Companion. |
negativeIntegers |
Returns a stream of values where each value is a randomly chosen negative value. The values returned always include the following edge cases: Int.MIN_VALUE fun Gen.Companion. |
numericDoubles |
Returns a Gen which is the same as Gen.double but does not include +INFINITY, -INFINITY or NaN. fun Gen.Companion. |
numericFloats |
Returns a Gen which is the same as Gen.float but does not include +INFINITY, -INFINITY or NaN. fun Gen.Companion. |
oneOf |
fun <A> Gen.Companion.oneOf(vararg gens: Gen<out A>): Gen<A> |
pair |
Returns a stream of values, where each value is a pair generated by the underlying generators. fun <K, V> Gen.Companion. |
period |
Generates a stream of random Periods fun Gen.Companion. |
positiveDoubles |
fun Gen.Companion. |
positiveIntegers |
Returns a stream of values where each value is a randomly chosen positive value. The values returned always include the following edge cases: Int.MAX_VALUE fun Gen.Companion. |
regex |
fun Gen.Companion.fun Gen.Companion. |
samples |
Returns a Gen which returns the sample values in the same order as they are passed in, once all sample values are used it repeats elements from start. fun <T> Gen.Companion. |
set |
Returns a stream of values, where each value is a set of values generated by the given generator. fun <T> Gen.Companion. |
short |
Returns a stream of values where each value is a randomly chosen Short. The values always returned include the following edge cases: [Short.MIN_VALUE, Short.MAX_VALUE, 0] fun Gen.Companion. |
string |
Returns a stream of values where each value is a random printed string. fun Gen.Companion. |
triple |
Returns a [Gen] where each value is a [Triple] generated by a value from each of three supplied generators. fun <A, B, C> Gen.Companion. |
ubyte |
Returns a stream of values where each value is a randomly chosen UByte. The values always returned include the following edge cases: [UByte.MIN_VALUE, UByte.MAX_VALUE] fun Gen.Companion.ubyte(): Gen<Byte> |
uint |
Returns a stream of values where each value is a randomly chosen UInt. The values always returned include the following edge cases: [UInt.MIN_VALUE, UInt.MAX_VALUE] fun Gen.Companion.uint(): Gen<UInt> |
ulong |
Returns a stream of values where each value is a randomly chosen ULong. The values returned always include the following edge cases: [ULong.MIN_VALUE, ULong.MAX_VALUE] fun Gen.Companion.ulong(): Gen<ULong> |
ushort |
Returns a stream of values where each value is a randomly chosen UShort. The values always returned include the following edge cases: [UShort.MIN_VALUE, UShort.MAX_VALUE] fun Gen.Companion. |
uuid |
fun Gen.Companion. |
BigIntegerGen |
class BigIntegerGen : Gen<BigInteger> |
RegexpGen |
class RegexpGen : Gen<String> |