kotest-property / io.kotest.property.arbitrary

Package io.kotest.property.arbitrary

Types

Arb

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

interface Arb<A> : Gen<A>

BasicArb

interface BasicArb<A> : Arb<A>

DoubleShrinker

object DoubleShrinker : Shrinker<Double>

FloatShrinker

object FloatShrinker : Shrinker<Float>

IntShrinker

object IntShrinker : Shrinker<Int>

ListShrinker

class ListShrinker<A> : Shrinker<List<A>>

LongShrinker

object LongShrinker : Shrinker<Long>

MapShrinker

class MapShrinker<K, V> : Shrinker<Map<K, V>>

MultiplesShrinker

class MultiplesShrinker : Shrinker<Int>

StringShrinker

object StringShrinker : Shrinker<String>

TypeReference

abstract class TypeReference<T> : Comparable<TypeReference<T>>

Properties

ByteShrinker

val ByteShrinker: Shrinker<Byte>

ShortShrinker

val ShortShrinker: Shrinker<Short>

UShortShrinker

val UShortShrinker: Shrinker<UShort>

Functions

arb

Creates a new Arb that performs no shrinking, and generates each value from successive invocations of the given function f.

fun <A> arb(edgecases: List<A> = emptyList(), f: (RandomSource) -> A): Arb<A>

Creates a new Arb that performs shrinking using the supplied shrinker and generates each value from successive invocations of the given function f.

fun <A> arb(shrinker: Shrinker<A>, f: (RandomSource) -> A): Arb<A>
fun <A> arb(shrinker: Shrinker<A>, edgecases: List<A> = emptyList(), f: (RandomSource) -> A): Arb<A>

bimap

fun <A, B> Shrinker<A>.bimap(f: (B) -> A, g: (A) -> B): Shrinker<B>

defaultForClass

fun <A> defaultForClass(kClass: KClass<*>): Arb<A>?

distinct

Returns a new Arb which ensures only unique values are generated by keeping track of previously generated values.

fun <A> Arb<A>.distinct(): Arb<A>

filter

Returns a new Arb which takes its elements from the receiver and filters them using the supplied predicate. This gen will continue to request elements from the underlying gen until one satisfies the predicate.

fun <A> Arb<A>.filter(predicate: (A) -> Boolean): Arb<A>

filterIsInstance

Create a new Arb by keeping only instances of B generated by this gen. This is useful if you have a type hierarchy and only want to retain a particular subtype.

fun <A, B : A> Arb<A>.filterIsInstance(): Arb<B>

filterNot

fun <A> Arb<A>.filterNot(f: (A) -> Boolean): Arb<A>

flatMap

Returns a new Arb which takes its elements from the receiver and flat maps them using the supplied function.

fun <A, B> Arb<A>.flatMap(f: (A) -> Arb<B>): Arb<B>

map

Returns a new Arb which takes its elements from the receiver and maps them using the supplied function.

fun <A, B> Arb<A>.map(f: (A) -> B): Arb<B>

next

fun <A> Arb<A>.next(rs: RandomSource = RandomSource.Default): A

Draws a random value from this generator

fun <A> Arb<A>.next(predicate: (A) -> Boolean = { true }, random: RandomSource?): A

single

Returns a single value generated from this arb ignoring edgecases.

fun <A> Arb<A>.single(rs: RandomSource = RandomSource.Default): A

take

Returns a sequence of size count from values generated from this arb.

fun <A> Arb<A>.take(count: Int, rs: RandomSource = RandomSource.Default): Sequence<A>

targetDefaultForClass

fun <A> targetDefaultForClass(): Arb<A>?

Companion Object Functions

bigInt

fun Arb.Companion.bigInt(range: IntRange): Arb<BigInteger>

bind

fun <A, T> Arb.Companion.bind(arbA: Arb<A>, createFn: (A) -> T): Arb<T>
fun <A, B, T> Arb.Companion.bind(arbA: Arb<A>, arbB: Arb<B>, createFn: (A, B) -> T): Arb<T>
fun <A, B, C, T> Arb.Companion.bind(arbA: Arb<A>, arbB: Arb<B>, arbC: Arb<C>, createFn: (A, B, C) -> T): Arb<T>
fun <A, B, C, D, T> Arb.Companion.bind(arbA: Arb<A>, arbB: Arb<B>, arbC: Arb<C>, arbD: Arb<D>, createFn: (A, B, C, D) -> T): Arb<T>
fun <A, B, C, D, E, T> Arb.Companion.bind(arbA: Arb<A>, arbB: Arb<B>, arbC: Arb<C>, arbD: Arb<D>, arbE: Arb<E>, createFn: (A, B, C, D, E) -> T): Arb<T>
fun <A, B, C, D, E, F, T> Arb.Companion.bind(arbA: Arb<A>, arbB: Arb<B>, arbC: Arb<C>, arbD: Arb<D>, arbE: Arb<E>, arbF: Arb<F>, createFn: (A, B, C, D, E, F) -> T): Arb<T>
fun <A, B, C, D, E, F, G, T> Arb.Companion.bind(arbA: Arb<A>, arbB: Arb<B>, arbC: Arb<C>, arbD: Arb<D>, arbE: Arb<E>, arbF: Arb<F>, arbG: Arb<G>, createFn: (A, B, C, D, E, F, G) -> T): Arb<T>

bool

fun Arb.Companion.bool(): Arb<Boolean>

byte

The edge cases are [Byte.MIN_VALUE, Byte.MAX_VALUE, 0]

fun Arb.Companion.byte(): Arb<Byte>

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 Arb.Companion.char(range: CharRange, vararg ranges: CharRange): Arb<Char>

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 Arb.Companion.char(ranges: List<CharRange> = CharSets.BASIC_LATIN): Arb<Char>

choice

Randomly selects one of the given generators to generate the next element. The input must be non-empty.

fun <A> Arb.Companion.choice(vararg gens: Gen<A>): Arb<A>

choose

Returns a stream of values based on weights:

fun <A : Any> Arb.Companion.choose(a: Pair<Int, A>, b: Pair<Int, A>, vararg cs: Pair<Int, A>): Arb<A>

constant

fun <A> Arb.Companion.constant(a: A): Arb<A>

create

Returns an Arb where each value is generated from the given function.

fun <A> Arb.Companion.create(fn: (RandomSource) -> A): Arb<A>

date

fun Arb.Companion.date(minYear: Int = 1970, maxYear: Int = 2030): <ERROR CLASS>
fun Arb.Companion.date(yearRange: IntRange): <ERROR CLASS>

datetime

fun Arb.Companion.datetime(minYear: Int = 1970, maxYear: Int = 2030): <ERROR CLASS>
fun Arb.Companion.datetime(yearRange: IntRange): <ERROR CLASS>

default

fun <A> Arb.Companion.default(): Arb<A>

double

Returns an Arb where each value is a randomly chosen Double.

fun Arb.Companion.double(): Arb<Double>

element

Returns an Arb whose values are chosen randomly from those in the supplied collection. May not cover all items. If you want an exhaustive selection from the list, see Exhaustive.collection

fun <T> Arb.Companion.element(collection: Collection<T>): Arb<T>

email

fun Arb.Companion.email(usernameSize: IntRange = 3..10, domainSize: IntRange = 3..10): Arb<String>

enum

fun <T : Enum<T>> Arb.Companion.enum(): Arb<T>

factors

fun Arb.Companion.factors(k: Int): Arb<Int>

file

Returns an Arb where each value is a randomly created File object. The file objects do not necessarily exist on disk.

fun Arb.Companion.file(): Arb<File>

Returns an Arb 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.

fun Arb.Companion.file(directoryName: String, recursive: Boolean = false): Arb<File>

float

Returns an Arb where each value is a Float.

fun Arb.Companion.float(): Arb<Float>

forClass

fun <A> Arb.Companion.forClass(kClass: KClass<*>): Arb<A>

int

fun Arb.Companion.int(min: Int, max: Int): Arb<Int>

Returns an Arb where each value is a randomly chosen Int in the given range. The edgecases are: [Int.MIN_VALUE, Int.MAX_VALUE, 0, 1, -1]

fun Arb.Companion.int(range: IntRange = Int.MIN_VALUE..Int.MAX_VALUE): Arb<Int>

lines

fun Arb.Companion.lines(file: File, charset: Charset = Charsets.UTF_8): Arb<String>

list

Returns an Arb whose of values are a list of values generated by the given generator. The size of each list is determined randomly by the specified range.

fun <A> Arb.Companion.list(gen: Gen<A>, range: IntRange = 0..100): Arb<List<A>>

localDate

Arberates a stream of random LocalDates

fun Arb.Companion.localDate(minYear: Int = 1970, maxYear: Int = 2030): Arb<LocalDate>

localDateTime

Arberates a stream of random LocalDateTimes

fun Arb.Companion.localDateTime(minYear: Int = 1970, maxYear: Int = 2030): Arb<LocalDateTime>

localTime

Arberates a stream of random LocalTimes

fun Arb.Companion.localTime(): Arb<LocalTime>

long

fun Arb.Companion.long(min: Long = Long.MIN_VALUE, max: Long = Long.MAX_VALUE): Arb<Long>
fun Arb.Companion.long(range: LongRange = Long.MIN_VALUE..Long.MAX_VALUE): Arb<Long>

map

Returns an Arb where each generated value is a map, with the entries of the map drawn from the given pair generating arb. The size of each generated map is a random value between the specified min and max bounds.

fun <K, V> Arb.Companion.map(arb: Arb<Pair<K, V>>, minSize: Int = 1, maxSize: Int = 100): Arb<Map<K, V>>

Returns an Arb where each generated value is a map, with the entries of the map drawn by combining values from the key gen and value gen. The size of each generated map is a random value between the specified min and max bounds.

fun <K, V> Arb.Companion.map(keyArb: Arb<K>, valueArb: Arb<V>, minSize: Int = 1, maxSize: Int = 100): Arb<Map<K, V>>

multiples

Returns an Arb where each generated value is a multiple of k between 0 to the specified max.

fun Arb.Companion.multiples(k: Int, max: Int): Arb<Int>

nats

Returns an Arb where each value is a randomly chosen natural integer. The edge cases are: Int.MAX_VALUE

fun Arb.Companion.nats(max: Int = Int.MAX_VALUE): Arb<Int>

negativeDoubles

fun Arb.Companion.negativeDoubles(): Arb<Double>

negativeInts

Returns an Arb where each value is a randomly chosen negative integer. The edge cases are: Int.MIN_VALUE

fun Arb.Companion.negativeInts(min: Int = Int.MIN_VALUE): Arb<Int>

numericDoubles

Returns an Arb which is the same as double but does not include +INFINITY, -INFINITY or NaN.

fun Arb.Companion.numericDoubles(from: Double = Double.MIN_VALUE, to: Double = Double.MAX_VALUE): Arb<Double>

numericFloats

Returns an Arb which is the same as float but does not include +INFINITY, -INFINITY or NaN.

fun Arb.Companion.numericFloats(from: Float = Float.MIN_VALUE, to: Float = Float.MAX_VALUE): Arb<Float>

pair

fun <K, V> Arb.Companion.pair(k: Arb<K>, v: Arb<V>): Arb<Pair<K, V>>

period

Arberates a random Periods.

fun Arb.Companion.period(maxYear: Int = 10): Arb<Period>

positiveDoubles

fun Arb.Companion.positiveDoubles(): Arb<Double>

positiveInts

Returns an Arb where each value is a randomly chosen positive integer. The edge cases are: Int.MAX_VALUE

fun Arb.Companion.positiveInts(max: Int = Int.MAX_VALUE): Arb<Int>

regex

fun Arb.Companion.regex(regex: String): Arb<String!>
fun Arb.Companion.regex(regex: Regex): Arb<String!>

set

Returns an Arb whose of values are a set of values generated by the given element generator. The size of each set is determined randomly by the specified range.

fun <A> Arb.Companion.set(gen: Gen<A>, range: IntRange = 0..100): Arb<Set<A>>

short

The edge cases are [Short.MIN_VALUE, Short.MAX_VALUE, 0]

fun Arb.Companion.short(): Arb<Short>

shuffle

Generates random permutations of a list.

fun <A> Arb.Companion.shuffle(list: List<A>): Arb<List<A>>

string

Returns an Arb where each random value is a String of length between minSize and maxSize.

fun Arb.Companion.string(minSize: Int = 0, maxSize: Int = 100): Arb<String>fun Arb.Companion.string(range: IntRange): Arb<String>

subsequence

Generates a random subsequence, including the empty list.

fun <A> Arb.Companion.subsequence(list: List<A>): Arb<List<A>>

triple

Returns a Arb where each value is a Triple generated by a value from each of three supplied generators.

fun <A, B, C> Arb.Companion.triple(arbA: Arb<A>, arbB: Arb<B>, arbC: Arb<C>): Arb<Triple<A, B, C>>

ushort

The edge cases are [Short.MIN_VALUE, Short.MAX_VALUE, 0]

fun Arb.Companion.ushort(): Arb<UShort>

uuid

fun Arb.Companion.uuid(uuidVersion: UUIDVersion = UUIDVersion.V4, allowNilValue: Boolean = true): Arb<UUID>