Generators List

This page lists all current generators in Kotest. There are two types of generator: arbitrary and exhaustive.

Most generators are available on all platforms. Some are JVM or JS specific.

We also provide generators for Arrow as a separate module.

GeneratorDescriptionJVMJSNative
Nulls
arb.orNull()Generates random values from the arb instance, with null values mixed in. For example, Arb.int().orNull() could generate 1, -1, null, 8, 17, and so on. Has overloaded versions to control the frequency of nulls being generated.โœ“โœ“โœ“
arb.orNull(nullProbability)Generates random values from the arb instance, with null values mixed in using the defined probability.โœ“โœ“โœ“
Booleans
Arb.boolean()Returns an Arb that produces Booleans.โœ“โœ“โœ“
Arb.booleanArray(length, content)Returns an Arb that produces BoolArrays where length produces the length of the arrays and content produces the content of the arrays.โœ“โœ“โœ“
Exhaustive.boolean()Alternatives between true and false.โœ“โœ“โœ“
Chars
Arb.char(range1, range2,...)Returns random char's generated from one or more given ranges. By supporting multiple ranges, it is possible to specific non-consecutive ranges of characters to populate values from.โœ“โœ“โœ“
Arb.charArray(length, content)Returns an Arb that produces CharArrays where length produces the length of the arrays and content produces the content of the arrays.โœ“โœ“โœ“
Bytes
Arb.byte(min, max)Returns an Arb that produces Bytes from min to max (inclusive). The edge cases are min, -1, 0, 1 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.positiveByte(min, max)Returns an Arb that produces positive Bytes from min to max (inclusive). The edge cases are 1 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.negativeByte(min, max)Returns an Arb that produces negative Bytes from min to max (inclusive). The edge cases are min and -1 which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.byteArray(length, content)Returns an Arb that produces ByteArrays where length produces the length of the arrays and content produces the content of the arrays.โœ“โœ“โœ“
Arb.uByte(min, max)Returns an Arb that produces UBytes from min to max (inclusive). The edge cases are min, 1 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.uByteArray(length, content)Returns an Arb that produces UByteArrays where length produces the length of the arrays and content produces the content of the arrays.โœ“โœ“โœ“
Shorts
Arb.short(min, max)Returns an Arb that produces Shorts from min to max (inclusive). The edge cases are min, -1, 0, 1 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.positiveShort(min, max)Returns an Arb that produces positive Shorts from min to max (inclusive). The edge cases are 1 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.negativeShort(min, max)Returns an Arb that produces negative Shorts from min to max (inclusive). The edge cases are min and -1 which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.shortArray(length, content)Returns an Arb that produces ShortArrays where length produces the length of the arrays and content produces the content of the arrays.โœ“โœ“โœ“
Arb.uShort(min, max)Returns an Arb that produces UShorts from min to max (inclusive). The edge cases are min, 1 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.uShortArray(length, content)Returns an Arb that produces UShortArrays where length produces the length of the arrays and content produces the content of the arrays.โœ“โœ“โœ“
Ints
Arb.int(min, max)Returns an Arb that produces Ints from min to max (inclusive). The edge cases are min, -1, 0, 1 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.positiveInt(min, max)Returns an Arb that produces positive Ints from min to max (inclusive). The edge cases are 1 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.nonNegativeInts(min, max)Returns an Arb that produces non negative Ints from min to max (inclusive). The edge cases are 0, 1 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.negativeInt(min, max)Returns an Arb that produces negative Ints from min to max (inclusive). The edge cases are min and -1 which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.nonPositiveInts(min, max)Returns an Arb that produces non positive Ints from min to max (inclusive). The edge cases are min, -1 and 0 which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.intArray(length, content)Returns an Arb that produces IntArrays where length produces the length of the arrays and content produces the content of the arrays.โœ“โœ“โœ“
Arb.uInt(min, max)Returns an Arb that produces UInts from min to max (inclusive). The edge cases are min, 1 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.uIntArray(length, content)Returns an Arb that produces UIntArrays where length produces the length of the arrays and content produces the content of the arrays.โœ“โœ“โœ“
Exhaustive.ints(range)Returns all ints in the given range.โœ“โœ“โœ“
Arb.multiple(k, max)Generates multiples of k up a max value. The edge cases are 0.โœ“โœ“โœ“
Arb.factor(k)Generates factors of k.โœ“โœ“โœ“
Longs
Arb.long(min, max)Returns an Arb that produces Longs from min to max (inclusive). The edge cases are min, -1, 0, 1 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.positiveLong(min, max)Returns an Arb that produces positive Longs from min to max (inclusive). The edge cases are 1 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.negativeLong(min, max)Returns an Arb that produces negative Longs from min to max (inclusive). The edge cases are min and -1 which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.longArray(length, content)Returns an Arb that produces LongArrays where length produces the length of the arrays and content produces the content of the arrays.โœ“โœ“โœ“
Arb.uLong(min, max)Returns an Arb that produces ULongs from min to max (inclusive). The edge cases are min, 1 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.uLongArray(length, content)Returns an Arb that produces ULongArrays where length produces the length of the arrays and content produces the content of the arrays.โœ“โœ“โœ“
Exhaustive.longs(range)Returns all longs in the given range.โœ“โœ“โœ“
Floats
Arb.float(min, max)Returns an Arb that produces Floats from min to max (inclusive). The edge cases are Float.NEGATIVE_INFINITY, min, -1.0, -Float.MIN_VALUE, -0.0, 0.0, Float.MIN_VALUE, 1.0, max, Float.POSITIVE_INFINITY and Float.NaN which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.positiveFloat(min, max)Returns an Arb that produces positive Floats from min to max (inclusive). Float.MIN_VALUE, 1.0, max, Float.POSITIVE_INFINITY which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.negativeFloat(min, max)Returns an Arb that produces negative Floats from min to max (inclusive). The edge cases are Float.NEGATIVE_INFINITY, min, -1.0 and -Float.MIN_VALUE which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.numericFloat(min, max)Returns an Arb that produces numeric Floats from min to max (inclusive). The edge cases are min, -1.0, -Float.MIN_VALUE, -0.0, 0.0, Float.MIN_VALUE, 1.0 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.floatArray(length, content)Returns an Arb that produces FloatArrays where length produces the length of the arrays and content produces the content of the arrays.โœ“โœ“โœ“
Doubles
Arb.double(min, max)Returns an Arb that produces Doubles from min to max (inclusive). The edge cases are Double.NEGATIVE_INFINITY, min, -1.0, -Double.MIN_VALUE, -0.0, 0.0, Double.MIN_VALUE, 1.0, max, Double.POSITIVE_INFINITY and Double.NaN which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.positiveDouble(min, max)Returns an Arb that produces positive Doubles from min to max (inclusive). Double.MIN_VALUE, 1.0, max, Double.POSITIVE_INFINITY which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.negativeDouble(min, max)Returns an Arb that produces negative Doubles from min to max (inclusive). The edge cases are Double.NEGATIVE_INFINITY, min, -1.0 and -Double.MIN_VALUE which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.numericDouble(min, max)Returns an Arb that produces numeric Doubles from min to max (inclusive). The edge cases are min, -1.0, -Double.MIN_VALUE, -0.0, 0.0, Double.MIN_VALUE, 1.0 and max which are only included if they are in the provided range.โœ“โœ“โœ“
Arb.doubleArray(length, content)Returns an Arb that produces DoubleArrays where length produces the length of the arrays and content produces the content of the arrays.โœ“โœ“โœ“
Enums
Arb.enum<T>()Randomly selects constants from the given enum.โœ“โœ“โœ“
Exhaustive.enum<T>()Iterates all the constants defined in the given enum.โœ“โœ“โœ“
Geo
Arb.latlong()Generates random pairs of doubles, where each double is in the range -180 to 180.โœ“โœ“โœ“
Strings
Arb.string(range)Generates random printable strings with a randomly chosen size from the given range. If range is not specified then (0..100) is used. The edge cases include empty string, a blank string and a unicode string.โœ“โœ“โœ“
Arb.stringPattern(pattern)Generates strings that match given pattern using Generexโœ“
Exhaustive.azstring(range)Returns all A-Z strings in the given range. For example if range was 1..2 then a, b, c, ...., yz, zz would be included.โœ“โœ“โœ“
Arb.email(localPartGen, domainGen)Generates random emails where the local part and domain part are random strings generated by the given generators. A default value is provided for both.โœ“โœ“โœ“
Arb.emailLocalPart()Generates random local email partsโœ“โœ“โœ“
Arb.uuid(type)Generates random UUIDs of the given typeโœ“
Arb.domain(tlds, labelArb)Generates random domains with a random tld (defaults to any of the top 120 TLDs) and a label generator, which generates domain parts.โœ“โœ“โœ“
Builders
Arb.create(fn)Generates values using the supplied function.โœ“โœ“โœ“
Arb.bind(arbA, arbB, fn)Generates values by pulling a value from each of the two given arbs and then passing those values to the supplied function.โœ“โœ“โœ“
Arb.bind(arbA, arbB, arbC, fn)Generates values by pulling a value from each of the three given arbs and then passing those values to the supplied function.โœ“โœ“โœ“
Arb.bind(arbA, ...., fn)Generates values by pulling a value from each of the given arbs and then passing those values to the supplied function.โœ“โœ“โœ“
Combinatorics
Arb.choose(pairs)Generates values based on weights. For example, Arb.choose(1 to 'A', 2 to 'B') will generate 'A' 33% of the time and 'B' 66% of the time.โœ“โœ“โœ“
Arb.frequency(list)Alias to chooseโœ“โœ“โœ“
Arb.shuffle(list)Generates random permutations of a list. For example, Arb.shuffle(listOf(1,2,3)) could generate listOf(3,1,2), listOf(1,3,2) and so on.โœ“โœ“โœ“
Arb.choice(arbs)Randomly selects one of the given arbs and then uses that to generate the next element.โœ“โœ“โœ“
Arb.subsequence(list)Generates a random subsequence of the given list starting at index 0 and including the empty list. For example, Arb.subsequence(listOf(1,2,3)) could generate listOf(1), listOf(1,2), and so on.โœ“โœ“โœ“
Collections
Arb.list(gen, range)Generates lists where values are generated by the given element generator. The size of each list is determined randomly by the specified range.โœ“โœ“โœ“
Arb.set(gen, range)Generates sets where values are generated by the given element generator. The size of each set is determined randomly by the specified range. The slippage argument specifies how many attempts will be made to generate each element before erroring, in the case that the underlying arb does not have enough unique values to satisfy the set size.โœ“โœ“โœ“
Arb.set(gen, range, slippage)Generates sets where values are generated by the given element generator. The size of each set is determined randomly by the specified range.โœ“โœ“โœ“
Arb.element(collection)Randomly selects one of the elements of the given collection.โœ“โœ“โœ“
Arb<T>.chunked(range)Generates lists where each list is populated from elements of this receiver. The size of each size is randomly chosen within the given range.โœ“โœ“โœ“
Exhaustive.collection(list)Enumerates each element of the list one by one.โœ“โœ“โœ“
Tuples
Arb.pair(arb1, arb2)Generates Pair instances where each value of the pair is drawn from the two provided arbsโœ“โœ“โœ“
Arb.triple(arb1, arb2, arb3)Generates Triple instances where each value of the triple is drawn from the three provided arbsโœ“โœ“โœ“
Dates
Arb.date(ranges)Generates random dates with the year between the given rangeโœ“
Arb.datetime(ranges)Generates random date times with the year between the given rangeโœ“
Arb.localDateTime(ranges)Generates random LocalDateTime's with the year between the given rangeโœ“
Arb.localDate(ranges)Generates random LocalDate's with the year between the given rangeโœ“
Kotlinx DateTimeRequires kotest-property-datetime module
Arb.date(yearRange)Generates LocalDates with the year between the given range and other fields randomly.โœ“โœ“โœ“
Arb.date(yearRange, hourRange, minuteRange, secondRage)Generates LocalDates with all fields in the given rangesโœ“โœ“โœ“
Arb.instance(range)Generates Instants with the epoch randomly generated in the given rangeโœ“โœ“โœ“