How to use Arb.Companion.toPrimitiveArray method of io.kotest.property.arbitrary.array class

Best Kotest code snippet using io.kotest.property.arbitrary.array.Arb.Companion.toPrimitiveArray

ints.kt

Source:ints.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import io.kotest.property.Gen4import io.kotest.property.Shrinker5import io.kotest.property.arbitrary.numbers.IntClassifier6import kotlin.math.abs7import kotlin.random.nextInt8import kotlin.random.nextUInt9class IntShrinker(val range: IntRange) : Shrinker<Int> {10 override fun shrink(value: Int): List<Int> = when (value) {11 0 -> emptyList()12 1, -1 -> listOf(0).filter { it in range }13 else -> {14 val a = intArrayOf(0, 1, -1, abs(value), value / 3, value / 2, value * 2 / 3)15 val b = (1..5).map { value - it }.reversed().filter { it > 0 }16 (a + b).distinct().filterNot { it == value }.filter { it in range }17 }18 }19}20/**21 * Returns an [Arb] that produces [Int]s from [min] to [max] (inclusive).22 *23 * The edge cases are [min], -1, 0, 1 and [max] where -1, 0, and 1 are only included if they24 * are inside the given range.25 *26 * Min defaults to [Int.MIN_VALUE] and max defaults to [Int.MAX_VALUE].27 */28fun Arb.Companion.int(min: Int = Int.MIN_VALUE, max: Int = Int.MAX_VALUE) = int(min..max)29/**30 * Returns an [Arb] that produces [Int]s in [range].31 *32 * The edge cases are [IntRange.first], -1, 0, 1 and [IntRange.last] where -1, 0, and 1 are only33 * included if they are inside the given range.34 *35 * The range defaults to [Int.MIN_VALUE] to [Int.MAX_VALUE].36 */37fun Arb.Companion.int(range: IntRange = Int.MIN_VALUE..Int.MAX_VALUE): Arb<Int> {38 val edgeCases = intArrayOf(range.first, -1, 0, 1, range.last).filter { it in range }.distinct()39 return ArbitraryBuilder.create { it.random.nextInt(range) }40 .withEdgecases(edgeCases)41 .withShrinker(IntShrinker(range))42 .withClassifier(IntClassifier(range))43 .build()44}45/**46 * Returns an [Arb] that produces positive [Int]s from 1 to [max] (inclusive).47 * The edge cases are 1 and [max].48 *49 * Max defaults to [Int.MAX_VALUE]50 */51fun Arb.Companion.positiveInt(max: Int = Int.MAX_VALUE) = int(1, max)52@Deprecated("use positiveInt. Deprecated in 5.0.", ReplaceWith("positiveInt(max)"))53fun Arb.Companion.positiveInts(max: Int = Int.MAX_VALUE) = positiveInt(max)54@Deprecated("use positiveInt. Deprecated in 5.0.", ReplaceWith("positiveInt(max)"))55fun Arb.Companion.nats(max: Int = Int.MAX_VALUE) = positiveInt(max)56/**57 * Returns an [Arb] that produces non-negative [Int]s from 0 to [max] (inclusive).58 * The edge cases are 0, 1 and [max].59 *60 * Max defaults to [Int.MAX_VALUE]61 */62fun Arb.Companion.nonNegativeInt(max: Int = Int.MAX_VALUE) = int(0, max)63/**64 * Returns an [Arb] that produces negative [Int]s from [min] to -1 (inclusive).65 * The edge cases are [min] and -1.66 */67fun Arb.Companion.negativeInt(min: Int = Int.MIN_VALUE) = int(min, -1)68@Deprecated("use negativeInt. Deprecated in 5.0.", ReplaceWith("negativeInt(min)"))69fun Arb.Companion.negativeInts(min: Int = Int.MIN_VALUE) = negativeInt(min)70/**71 * Returns an [Arb] that produces non-positive [Int]s from [min] to 0 (inclusive).72 * The edge cases are [min], -1 and 0.73 */74fun Arb.Companion.nonPositiveInt(min: Int = Int.MIN_VALUE) = int(min, 0)75/**76 * Returns an [Arb] that produces [IntArray]s where [length] produces the length of the arrays and77 * [content] produces the content of the arrays.78 */79fun Arb.Companion.intArray(length: Gen<Int>, content: Arb<Int>): Arb<IntArray> =80 toPrimitiveArray(length, content, Collection<Int>::toIntArray)81class UIntShrinker(val range: UIntRange) : Shrinker<UInt> {82 override fun shrink(value: UInt): List<UInt> = when (value) {83 0u -> emptyList()84 1u -> listOf(0u).filter { it in range }85 else -> {86 val a = listOf(0u, 1u, value / 3u, value / 2u, value * 2u / 3u)87 val b = (1u..5u).map { value - it }.reversed().filter { it > 0u }88 (a + b).distinct().filterNot { it == value }.filter { it in range }89 }90 }91}92/**93 * Returns an [Arb] that produces [UInt]s from [min] to [max] (inclusive).94 * The edge cases are [min], 1 and [max] where 1 is included only if it is in the provided range.95 */96fun Arb.Companion.uInt(min: UInt = UInt.MIN_VALUE, max: UInt = UInt.MAX_VALUE) = uInt(min..max)97/**98 * Returns an [Arb] that produces [UInt]s in range.99 * The edge cases are [UIntRange.first], 1 and [UIntRange.last] where 1 is included only100 * if it is in the provided range.101 */102fun Arb.Companion.uInt(range: UIntRange = UInt.MIN_VALUE..UInt.MAX_VALUE): Arb<UInt> {103 val edges = listOf(range.first, 1u, range.last).filter { it in range }.distinct()104 return arbitrary(edges, UIntShrinker(range)) { it.random.nextUInt(range) }105}106/**107 * Returns an [Arb] that produces [UIntArray]s where [length] produces the length of the arrays and108 * [content] produces the content of the arrays.109 */110@ExperimentalUnsignedTypes111fun Arb.Companion.uIntArray(length: Gen<Int>, content: Arb<UInt>): Arb<UIntArray> =112 toPrimitiveArray(length, content, Collection<UInt>::toUIntArray)...

Full Screen

Full Screen

longs.kt

Source:longs.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import io.kotest.property.Gen4import io.kotest.property.Shrinker5import io.kotest.property.arbitrary.numbers.LongClassifier6import kotlin.math.abs7import kotlin.random.nextLong8import kotlin.random.nextULong9class LongShrinker(private val range: LongRange) : Shrinker<Long> {10 override fun shrink(value: Long): List<Long> = when (value) {11 0L -> emptyList()12 1L, -1L -> listOf(0L).filter { it in range }13 else -> {14 val a = listOf(0, 1, -1, abs(value), value / 3, value / 2, value * 2 / 3)15 val b = (1..5).map { value - it }.reversed().filter { it > 0 }16 (a + b).distinct().filterNot { it == value }.filter { it in range }17 }18 }19}20/**21 * Returns an [Arb] that produces [Long]s from [min] to [max] (inclusive).22 * The edge cases are [min], -1, 0, 1 and [max] which are only included if they are in the provided range.23 */24fun Arb.Companion.long(min: Long = Long.MIN_VALUE, max: Long = Long.MAX_VALUE) = long(min..max)25/**26 * Returns an [Arb] that produces [Long]s in [range].27 *28 * The edge cases are [LongRange.first], -1, 0, 1 and [LongRange.last].29 *30 * -1, 0, and 1 are only included if they are present in the given range.31 */32fun Arb.Companion.long(range: LongRange = Long.MIN_VALUE..Long.MAX_VALUE): Arb<Long> {33 val edgeCases = longArrayOf(range.first, -1, 0, 1, range.last).filter { it in range }.distinct()34 return ArbitraryBuilder.create { it.random.nextLong(range) }35 .withEdgecases(edgeCases)36 .withShrinker(LongShrinker(range))37 .withClassifier(LongClassifier(range))38 .build()39}40/**41 * Returns an [Arb] that produces positive [Long]s from 1 to [max] (inclusive).42 * The edge cases are 1 and [max].43 */44fun Arb.Companion.positiveLong(max: Long = Long.MAX_VALUE): Arb<Long> = long(1L, max)45/**46 * Returns an [Arb] that produces negative [Long]s from [min] to -1 (inclusive).47 * The edge cases are [min] and -1.48 */49fun Arb.Companion.negativeLong(min: Long = Long.MIN_VALUE): Arb<Long> = long(min, -1L)50/**51 * Returns an [Arb] that produces [LongArray]s where [generateArrayLength] produces the length of the arrays and52 * [generateContents] produces the content of the arrays.53 */54fun Arb.Companion.longArray(generateArrayLength: Gen<Int>, generateContents: Arb<Long>): Arb<LongArray> =55 toPrimitiveArray(generateArrayLength, generateContents, Collection<Long>::toLongArray)56class ULongShrinker(val range: ULongRange) : Shrinker<ULong> {57 override fun shrink(value: ULong): List<ULong> = when (value) {58 0uL -> emptyList()59 1uL -> listOf(0uL).filter { it in range }60 else -> {61 val a = listOf(0uL, 1uL, value / 3u, value / 2u, value * 2u / 3u)62 val b = (1u..5u).map { value - it }.reversed().filter { it > 0u }63 (a + b).distinct().filterNot { it == value }.filter { it in range }64 }65 }66}67/**68 * Returns an [Arb] that produces [ULong]s from [min] to [max] (inclusive).69 * The edge cases are [min], 1 and [max] which are only included if they are in the provided range.70 */71fun Arb.Companion.uLong(min: ULong = ULong.MIN_VALUE, max: ULong = ULong.MAX_VALUE) = uLong(min..max)72/**73 * Returns an [Arb] that produces [ULong]s in range.74 * The edge cases are [ULongRange.first], 1 and [ULongRange.last] which are only included if they are in the provided75 * range.76 */77fun Arb.Companion.uLong(range: ULongRange = ULong.MIN_VALUE..ULong.MAX_VALUE): Arb<ULong> {78 val edgeCases = listOf(range.first, 1uL, range.last).filter { it in range }.distinct()79 return arbitrary(edgeCases, ULongShrinker(range)) {80 var value = it.random.nextULong(range)81 while(value !in range) value = it.random.nextULong(range) // temporary workaround for KT-4730482 value83 }84}85/**86 * Returns an [Arb] that produces [ULongArray]s where [generateArrayLength] produces the length of the arrays and87 * [generateContents] produces the content of the arrays.88 */89@ExperimentalUnsignedTypes90fun Arb.Companion.uLongArray(generateArrayLength: Gen<Int>, generateContents: Arb<ULong>): Arb<ULongArray> =91 toPrimitiveArray(generateArrayLength, generateContents, Collection<ULong>::toULongArray)...

Full Screen

Full Screen

floats.kt

Source:floats.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import io.kotest.property.Gen4import io.kotest.property.Shrinker5import kotlin.math.absoluteValue6private val numericEdgeCases = listOf(-1.0F, -Float.MIN_VALUE, -0.0F, 0.0F, Float.MIN_VALUE, 1.0F)7private val nonFiniteEdgeCases = listOf(Float.NEGATIVE_INFINITY, Float.NaN, Float.POSITIVE_INFINITY)8object FloatShrinker : Shrinker<Float> {9 override fun shrink(value: Float): List<Float> =10 if (value == 0f || !value.isFinite() || value.absoluteValue < 10 * Float.MIN_VALUE)11 emptyList()12 else13 listOfNotNull(DoubleShrinker.shrink(value.toString())?.toFloat())14}15/**16 * Returns an [Arb] that produces [Float]s from [min] to [max] (inclusive).17 * The edge cases are [Float.NEGATIVE_INFINITY], [min], -1.0, -[Float.MIN_VALUE], -0.0, 0.0, [Float.MIN_VALUE], 1.0,18 * [max], [Float.POSITIVE_INFINITY] and [Float.NaN] which are only included if they are in the provided range.19 *20 * @see numericFloat to only produce numeric [Float]s21 */22fun Arb.Companion.float(min: Float = -Float.MAX_VALUE, max: Float = Float.MAX_VALUE): Arb<Float> = float(min..max)23/**24 * Returns an [Arb] that produces [Float]s in [range].25 * The edge cases are [Float.NEGATIVE_INFINITY], [ClosedFloatingPointRange.start], -1.0, -[Float.MIN_VALUE], -0.0,26 * 0.0, [Float.MIN_VALUE], 1.0, [ClosedFloatingPointRange.endInclusive], [Float.POSITIVE_INFINITY] and [Float.NaN] which27 * are only included if they are in the provided range.28 */29fun Arb.Companion.float(range: ClosedFloatingPointRange<Float> = -Float.MAX_VALUE..Float.MAX_VALUE): Arb<Float> =30 arbitrary(31 (numericEdgeCases.filter { it in range } +32 listOf(-1.0F, -0.0F, 0.0F, 1.0F).filter { it in range }.map { it / 0.0F } +33 listOf(range.start, range.endInclusive)34 ).distinct(),35 FloatShrinker36 ) {37 it.random.nextDouble(range.start.toDouble(), range.endInclusive.toDouble()).toFloat()38 }39/**40 * Returns an [Arb] that produces positive [Float]s from [Float.MIN_VALUE] to [max] (inclusive).41 * The edge cases are [Float.MIN_VALUE], 1.0, [max] and [Float.POSITIVE_INFINITY] which are only included if they are42 * in the provided range.43 */44fun Arb.Companion.positiveFloat(): Arb<Float> = float(Float.MIN_VALUE, Float.MAX_VALUE)45/**46 * Returns an [Arb] that produces negative [Float]s from [min] to -[Float.MIN_VALUE] (inclusive).47 * The edge cases are [Float.NEGATIVE_INFINITY], [min], -1.0 and -[Float.MIN_VALUE] which are only included if they48 * are in the provided range.49 */50fun Arb.Companion.negativeFloat(): Arb<Float> = float(-Float.MAX_VALUE, -Float.MIN_VALUE)51/**52 * Returns an [Arb] that produces numeric [Float]s from [min] to [max] (inclusive).53 * The edge cases are [min], -1.0, -[Float.MIN_VALUE], -0.0, 0.0, [Float.MIN_VALUE], 1.0 and [max] which are only54 * included if they are in the provided range.55 *56 * @see float to also have non numeric [Float]s as edge cases.57 */58fun Arb.Companion.numericFloat(59 min: Float = -Float.MAX_VALUE,60 max: Float = Float.MAX_VALUE61): Arb<Float> = arbitrary((numericEdgeCases.filter { it in min..max } + listOf(min, max)).distinct(), FloatShrinker) {62 it.random.nextDouble(min.toDouble(), max.toDouble()).toFloat()63}64@Deprecated("use numericFloat", ReplaceWith("numericFloat(from, to)"))65fun Arb.Companion.numericFloats(from: Float = -Float.MAX_VALUE, to: Float = Float.MAX_VALUE): Arb<Float> =66 numericFloat(from, to)67/**68 * Returns an [Arb] that produces [FloatArray]s where [length] produces the length of the arrays and69 * [content] produces the content of the arrays.70 */71fun Arb.Companion.floatArray(length: Gen<Int>, content: Arb<Float>): Arb<FloatArray> =72 toPrimitiveArray(length, content, Collection<Float>::toFloatArray)...

Full Screen

Full Screen

bytes.kt

Source:bytes.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import io.kotest.property.Gen4import io.kotest.property.bimap5import kotlin.random.nextUInt6/**7 * Returns an [Arb] that produces [Byte]s from [min] to [max] (inclusive).8 * The edge cases are [min], -1, 0, 1 and [max] which are only included if they are in the provided range.9 */10fun Arb.Companion.byte(min: Byte = Byte.MIN_VALUE, max: Byte = Byte.MAX_VALUE): Arb<Byte> =11 arbitrary(byteArrayOf(min, -1, 0, 1, max).filter { it in min..max }.distinct(), ByteShrinker) {12 generateSequence { it.random.nextBytes(1).first() }.filter { it in min..max }.first()13 }14val ByteShrinker = IntShrinker(Byte.MIN_VALUE..Byte.MAX_VALUE).bimap({ it.toInt() }, { it.toByte() })15/**16 * Returns an [Arb] that produces positive [Byte]s from 1 to [max] (inclusive).17 * The edge cases are 1 and [max] which are only included if they are in the provided range.18 */19fun Arb.Companion.positiveByte(max: Byte = Byte.MAX_VALUE): Arb<Byte> = byte(1, max)20/**21 * Returns an [Arb] that produces negative [Byte]s from [min] to -1 (inclusive).22 * The edge cases are [min] and -1 which are only included if they are in the provided range.23 */24fun Arb.Companion.negativeByte(min: Byte = Byte.MIN_VALUE): Arb<Byte> = byte(min, -1)25/**26 * Returns an [Arb] that produces [ByteArray]s where [length] produces the length of the arrays and27 * [content] produces the content of the arrays.28 */29fun Arb.Companion.byteArray(length: Gen<Int>, content: Arb<Byte>): Arb<ByteArray> =30 toPrimitiveArray(length, content, Collection<Byte>::toByteArray)31@Deprecated("use byteArray", ReplaceWith("byteArray(generateArrayLength, generateContents)"))32fun Arb.Companion.byteArrays(generateArrayLength: Gen<Int>, generateContents: Arb<Byte>): Arb<ByteArray> =33 byteArray(generateArrayLength, generateContents)34/**35 * Returns an [Arb] that produces [UByte]s from [min] to [max] (inclusive).36 * The edge cases are [min], 1 and [max] which are only included if they are in the provided range.37 */38fun Arb.Companion.uByte(min: UByte = UByte.MIN_VALUE, max: UByte = UByte.MAX_VALUE): Arb<UByte> =39 arbitrary(listOf(min, 1u, max).filter { it in min..max }.distinct(), UByteShrinker) {40 it.random.nextUInt(min..max).toUByte()41 }42val UByteShrinker = UIntShrinker(UByte.MIN_VALUE..UByte.MAX_VALUE).bimap({ it.toUInt() }, { it.toUByte() })43/**44 * Returns an [Arb] that produces [UByteArray]s where [length] produces the length of the arrays and45 * [content] produces the content of the arrays.46 */47@ExperimentalUnsignedTypes48fun Arb.Companion.uByteArray(length: Gen<Int>, content: Arb<UByte>): Arb<UByteArray> =49 toPrimitiveArray(length, content, Collection<UByte>::toUByteArray)...

Full Screen

Full Screen

shorts.kt

Source:shorts.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import io.kotest.property.Gen4import io.kotest.property.bimap5import kotlin.random.nextInt6import kotlin.random.nextUInt7/**8 * Returns an [Arb] that produces [Short]s from [min] to [max] (inclusive).9 * The edge cases are [min], -1, 0, 1 and [max] which are only included if they are in the provided range.10 */11fun Arb.Companion.short(min: Short = Short.MIN_VALUE, max: Short = Short.MAX_VALUE): Arb<Short> {12 val edges = shortArrayOf(min, -1, 0, 1, max).filter { it in min..max }.distinct()13 return arbitrary(edges, ShortShrinker) { it.random.nextInt(min..max).toShort() }14}15val ShortShrinker = IntShrinker(Short.MIN_VALUE..Short.MAX_VALUE).bimap({ it.toInt() }, { it.toShort() })16/**17 * Returns an [Arb] that positive produces [Short]s from 1 to [max] (inclusive).18 * The edge cases are 1 and [max] which are only included if they are in the provided range.19 */20fun Arb.Companion.positiveShort(max: Short = Short.MAX_VALUE) = short(1, max)21/**22 * Returns an [Arb] that produces negative [Short]s from [min] to -1 (inclusive).23 * The edge cases are [min] and -1 which are only included if they are in the provided range.24 */25fun Arb.Companion.negativeShort(min: Short = Short.MIN_VALUE) = short(min, -1)26/**27 * Returns an [Arb] that produces [ShortArray]s where [length] produces the length of the arrays and28 * [content] produces the content of the arrays.29 */30fun Arb.Companion.shortArray(length: Gen<Int>, content: Arb<Short>): Arb<ShortArray> =31 toPrimitiveArray(length, content, Collection<Short>::toShortArray)32/**33 * Returns an [Arb] that produces [UShort]s from [min] to [max] (inclusive).34 * The edge cases are [min], 1 and [max] which are only included if they are in the provided range.35 */36fun Arb.Companion.uShort(min: UShort = UShort.MIN_VALUE, max: UShort = UShort.MAX_VALUE): Arb<UShort> {37 val edges = listOf(min, 1u, max).filter { it in min..max }.distinct()38 return arbitrary(edges, UShortShrinker) { it.random.nextUInt(min..max).toUShort() }39}40@Deprecated("use uShort", ReplaceWith("uShort(min, max)"))41fun Arb.Companion.ushort(min: UShort = UShort.MIN_VALUE, max: UShort = UShort.MAX_VALUE): Arb<UShort> = uShort(min, max)42val UShortShrinker = UIntShrinker(UShort.MIN_VALUE..UShort.MAX_VALUE).bimap({ it.toUInt() }, { it.toUShort() })43/**44 * Returns an [Arb] that produces [UShortArray]s where [length] produces the length of the arrays and45 * [content] produces the content of the arrays.46 */47@ExperimentalUnsignedTypes48fun Arb.Companion.uShortArray(length: Gen<Int>, content: Arb<UShort>): Arb<UShortArray> =49 toPrimitiveArray(length, content, Collection<UShort>::toUShortArray)...

Full Screen

Full Screen

char.kt

Source:char.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import io.kotest.property.Gen4/**5 * Returns a [Arb] that generates randomly-chosen Chars. Custom characters can be generated by6 * providing CharRanges. Distribution will be even across the ranges of Chars.7 * For example:8 * Gen.char('A'..'C', 'D'..'E')9 * Ths will choose A, B, C, D, and E each 20% of the time.10 */11fun Arb.Companion.char(range: CharRange, vararg ranges: CharRange): Arb<Char> {12 return Arb.char(listOf(range) + ranges)13}14/**15 * Returns a [Arb] that generates randomly-chosen Chars. Custom characters can be generated by16 * providing a list of CharRanges. Distribution will be even across the ranges of Chars.17 * For example:18 * Gen.char(listOf('A'..'C', 'D'..'E')19 * Ths will choose A, B, C, D, and E each 20% of the time.20 *21 * If no parameter is given, ASCII characters will be generated.22 */23fun Arb.Companion.char(ranges: List<CharRange> = CharSets.BASIC_LATIN): Arb<Char> {24 require(ranges.all { !it.isEmpty() }) { "Ranges cannot be empty" }25 require(ranges.isNotEmpty()) { "List of ranges must have at least one range" }26 fun makeRangeWeightedGen(): Arb<CharRange> {27 val weightPairs = ranges.map { range ->28 val weight = range.last.code - range.first.code + 129 Pair(weight, range)30 }31 return Arb.choose(weightPairs[0], weightPairs[1], *weightPairs.drop(2).toTypedArray())32 }33 // Convert the list of CharRanges into a weighted Gen in which34 // the ranges are chosen from the list using the length of the35 // range as the weight.36 val arbRange: Arb<CharRange> =37 if (ranges.size == 1) Arb.constant(ranges.first())38 else makeRangeWeightedGen()39 return arbRange.flatMap { charRange ->40 arbitrary { charRange.random(it.random) }41 }42}43/**44 * Returns an [Arb] that produces [CharArray]s where [length] produces the length of the arrays and45 * [content] produces the content of the arrays.46 */47fun Arb.Companion.charArray(length: Gen<Int>, content: Arb<Char>): Arb<CharArray> =48 toPrimitiveArray(length, content, Collection<Char>::toCharArray)49private object CharSets {50 val CONTROL = listOf('\u0000'..'\u001F', '\u007F'..'\u007F')51 val WHITESPACE = listOf('\u0020'..'\u0020', '\u0009'..'\u0009', '\u000A'..'\u000A')52 val BASIC_LATIN = listOf('\u0021'..'\u007E')53}...

Full Screen

Full Screen

bools.kt

Source:bools.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import io.kotest.property.Gen4/**5 * Returns an [Arb] that produces [Boolean]s.6 */7fun Arb.Companion.boolean(): Arb<Boolean> = arbitrary(listOf(true, false)) { it.random.nextBoolean() }8@Deprecated("use boolean", ReplaceWith("boolean()"))9fun Arb.Companion.bool(): Arb<Boolean> = boolean()10/**11 * Returns an [Arb] that produces [BooleanArray]s where [length] produces the length of the arrays and12 * [content] produces the content of the arrays.13 */14fun Arb.Companion.booleanArray(length: Gen<Int>, content: Arb<Boolean>): Arb<BooleanArray> =15 toPrimitiveArray(length, content, Collection<Boolean>::toBooleanArray)...

Full Screen

Full Screen

array.kt

Source:array.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import io.kotest.property.Exhaustive4import io.kotest.property.Gen5internal inline fun <P, A> Arb.Companion.toPrimitiveArray(6 generateArrayLength: Gen<Int>,7 generateContents: Arb<P>,8 crossinline toArray: Collection<P>.() -> A9): Arb<A> = when (generateArrayLength) {10 is Arb -> generateArrayLength11 is Exhaustive -> generateArrayLength.toArb()12}.flatMap { length -> Arb.list(generateContents, length..length) }.map { it.toArray() }...

Full Screen

Full Screen

Arb.Companion.toPrimitiveArray

Using AI Code Generation

copy

Full Screen

1import io.kotest.property.arbitrary.array2import io.kotest.property.arbitrary.toPrimitiveArray3import io.kotest.property.checkAll4checkAll<Array<Int>> { array ->5 val primitiveArray = array.toPrimitiveArray()6}7import io.kotest.property.arbitrary.array8import io.kotest.property.arbitrary.toPrimitiveArray9import io.kotest.property.checkAll10checkAll<Array<Short>> { array ->11 val primitiveArray = array.toPrimitiveArray()12}13import io.kotest.property.arbitrary.array14import io.kotest.property.arbitrary.toPrimitiveArray15import io.kotest.property.checkAll16checkAll<Array<Long>> { array ->17 val primitiveArray = array.toPrimitiveArray()18}19import io.kotest.property.arbitrary.array20import io.kotest.property.arbitrary.toPrimitiveArray21import io.kotest.property.checkAll22checkAll<Array<Byte>> { array ->23 val primitiveArray = array.toPrimitiveArray()24}25import io.kotest.property.arbitrary.array26import io.kotest.property.arbitrary.toPrimitiveArray27import io.kotest.property.checkAll28checkAll<Array<Char>> { array ->29 val primitiveArray = array.toPrimitiveArray()30}31import io.kotest.property.arbitrary.array32import io.kotest.property.arbitrary.toPrimitiveArray33import io.kotest.property.checkAll34checkAll<Array<Float>> { array ->35 val primitiveArray = array.toPrimitiveArray()36}37import io.kotest.property.arbitrary.array38import io.kotest.property.arbitrary.toPrimitiveArray39import io.kotest.property

Full Screen

Full Screen

Arb.Companion.toPrimitiveArray

Using AI Code Generation

copy

Full Screen

1val arrayArb = Arb.array(Arb.int(), 5..10)2arrayArb.sample()3val arrayArb = Arb.array(Arb.int(), 5..10)4arrayArb.sample()5val arrayArb = Arb.array(Arb.int(), 5..10)6arrayArb.sample()7val arrayArb = Arb.array(Arb.int(), 5..10)8arrayArb.sample()9val arrayArb = Arb.array(Arb.int(), 5..10)10arrayArb.sample()11val arrayArb = Arb.array(Arb.int(), 5..10)12arrayArb.sample()13val arrayArb = Arb.array(Arb.int(), 5..10)14arrayArb.sample()15val arrayArb = Arb.array(Arb.int(), 5..10)16arrayArb.sample()17val arrayArb = Arb.array(Arb.int(), 5..10)18arrayArb.sample()19val arrayArb = Arb.array(Arb.int(), 5..10)20arrayArb.sample()21val arrayArb = Arb.array(Arb.int(), 5..10)22arrayArb.sample()23val arrayArb = Arb.array(Arb.int(), 5..10)24arrayArb.sample()

Full Screen

Full Screen

Arb.Companion.toPrimitiveArray

Using AI Code Generation

copy

Full Screen

1val arb: Arb < Array < Int > > = Arb . array ( Arb . int ( 0 , 100 ) , 0 , 10 ) arb . toPrimitiveArray ( 0 ) . checkAll { array -> array . size in 0 .. 10 array . all { it in 0 .. 100 } }2val arb : Arb < Array < Int > > = Arb . array ( Arb . int ( 0 , 100 ) , 0 , 10 ) arb . toPrimitiveArray ( 0 ) . checkAll { array - > array . size in 0 .. 10 array . all { it in 0 .. 100 } }3val arb : Arb < Array < Int > > = Arb . array ( Arb . int ( 0 , 100 ) , 0 , 10 ) arb . toPrimitiveArray ( 0 ) . checkAll { array -> array . size in 0 .. 10 array . all { it in 0 .. 100 } }4val arb : Arb < Array < Int > > = Arb . array ( Arb . int ( 0 , 100 ) , 0 , 10 ) arb . toPrimitiveArray ( 0 ) . checkAll { array - > array . size in 0 .. 10 array . all { it in 0 .. 100 } }5val arb : Arb < Array < Int > > = Arb . array ( Arb . int ( 0 , 100 ) , 0 , 10 ) arb . toPrimitiveArray ( 0 ) . checkAll { array -> array . size in 0 .. 10 array . all { it in 0 .. 100 } }6val arb : Arb < Array < Int > > = Arb . array ( Arb . int ( 0 , 100 ) , 0 , 10 ) arb . toPrimitiveArray ( 0 ) . checkAll { array

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in array

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful