kotest-assertions / io.kotest.properties / next

next

fun <T> Gen<T>.next(predicate: (T) -> Boolean = { true }, seed: Long?): T
Deprecated: Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0. Use Arb.single()

Draws a random value from this generator

This method will draw a single value from the random values, that matches predicate (defaults to every value)

This expects that 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 constants pool. Only random values.

val gen = Gen.string()
val generatedValue: String = gen.next()
val filteredValue: String = gen.next { it != "hello" }
fun <T> Gen<T>.next(predicate: (T) -> Boolean = { true }): T
Deprecated: Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0

Return
the result of calling next with the given predicate defaulting seed to null