How to use Arb.Companion.short method of io.kotest.property.arbitrary.shorts class

Best Kotest code snippet using io.kotest.property.arbitrary.shorts.Arb.Companion.short

Arb.kt

Source:Arb.kt Github

copy

Full Screen

1package arrow.fx.coroutines.stream2import io.kotest.property.Arb3import io.kotest.property.RandomSource4import io.kotest.property.Sample5import io.kotest.property.Shrinker6import io.kotest.property.arbitrary.arb7import io.kotest.property.arbitrary.bool8import io.kotest.property.arbitrary.byte9import io.kotest.property.arbitrary.choice10import io.kotest.property.arbitrary.choose11import io.kotest.property.arbitrary.double12import io.kotest.property.arbitrary.float13import io.kotest.property.arbitrary.int14import io.kotest.property.arbitrary.list15import io.kotest.property.arbitrary.long16import io.kotest.property.arbitrary.map17import io.kotest.property.arbitrary.set18import io.kotest.property.arbitrary.short19import kotlin.random.nextInt20@JvmOverloads21inline fun <reified A> Arb.Companion.array(22 gen: Arb<A>,23 range: IntRange = 0..10024): Arb<Array<A>> {25 check(!range.isEmpty())26 check(range.first >= 0)27 return arb(edgecases = listOf(emptyArray<A>()) + gen.edgecases().map { arrayOf(it) }) {28 sequence {29 val genIter = gen.generate(it).iterator()30 while (true) {31 val targetSize = it.random.nextInt(range)32 val list = ArrayList<A>(targetSize)33 while (list.size < targetSize && genIter.hasNext()) {34 list.add(genIter.next().value)35 }36 check(list.size == targetSize)37 yield(list.toArray() as Array<A>)38 }39 }40 }41}42@PublishedApi43internal fun <A, B> arrayChunkGenerator(44 arb: Arb<A>,45 shrinker: Shrinker<B>,46 range: IntRange = 0..10,47 build: (values: List<A>, offset: Int, length: Int) -> B48): Arb<B> {49 check(!range.isEmpty())50 check(range.first >= 0)51 val edgecases =52 arb.edgecases().map { a -> build(listOf(a), 0, 1) } + build(emptyList(), 0, 0)53 return arb(edgecases, shrinker) {54 val genIter = arb.generate(it).iterator()55 sequence {56 while (true) {57 val targetSize = it.random.nextInt(range)58 val list = ArrayList<A>(targetSize)59 while (list.size < targetSize && genIter.hasNext()) {60 list.add(genIter.next().value)61 }62 val offset = (0..list.size).random(it.random)63 val length = (0..(list.size - offset)).random(it.random)64 yield(build(list, offset, length))65 }66 }67 }68}69class ChunkShrinker<A> : Shrinker<Chunk<A>> {70 override fun shrink(value: Chunk<A>): List<Chunk<A>> =71 if (value.isEmpty()) emptyList()72 else listOf(73 Chunk.empty(),74 value.takeLast(1),75 value.take(value.size() / 3),76 value.take(value.size() / 2),77 value.take(value.size() * 2 / 3),78 value.dropLast(1)79 )80}81inline fun <reified A> Arb.Companion.chunk(arb: Arb<A>): Arb<Chunk<A>> =82 object : Arb<Chunk<A>>() {83 override fun edgecases(): List<Chunk<A>> =84 listOf(Chunk.empty<A>()) + arb.edgecases().map { Chunk(it) }85 override fun values(rs: RandomSource): Sequence<Sample<Chunk<A>>> =86 Arb.choose(87 5 to arb.map { Chunk.just(it) },88 10 to Arb.list(arb, 0..20).map { Chunk.iterable(it) },89 10 to Arb.set(arb, 0..20).map { Chunk.iterable(it) },90 10 to Arb.array(arb, 0..20).map { Chunk.array(it) },91 10 to Arb.boxedChunk(arb)92 ).values(rs)93 }94inline fun <reified A> Arb.Companion.boxedChunk(arb: Arb<A>): Arb<Chunk<A>> =95 object : Arb<Chunk<A>>() {96 override fun edgecases(): List<Chunk<A>> =97 listOf(Chunk.empty<A>()) + arb.edgecases().map { Chunk(it) }98 override fun values(rs: RandomSource): Sequence<Sample<Chunk<A>>> =99 arrayChunkGenerator(arb, ChunkShrinker()) { values, offset, length ->100 Chunk.boxed(values.toTypedArray(), offset, length)101 }.values(rs)102 }103fun Arb.Companion.booleanChunk(): Arb<Chunk<Boolean>> =104 object : Arb<Chunk<Boolean>>() {105 override fun edgecases(): List<Chunk<Boolean>> =106 listOf(Chunk.empty<Boolean>()) + Arb.bool().edgecases().map { Chunk(it) }107 override fun values(rs: RandomSource): Sequence<Sample<Chunk<Boolean>>> =108 Arb.choice(109 arrayChunkGenerator(Arb.bool(), ChunkShrinker()) { values, offset, length ->110 Chunk.booleans(values.toBooleanArray(), offset, length)111 },112 arrayChunkGenerator(Arb.bool(), ChunkShrinker()) { values, _, _ ->113 Chunk.array(values.toTypedArray())114 }115 ).values(rs)116 }117fun Arb.Companion.byteChunk(): Arb<Chunk<Byte>> =118 object : Arb<Chunk<Byte>>() {119 override fun edgecases(): List<Chunk<Byte>> =120 listOf(Chunk.empty<Byte>()) + Arb.byte().edgecases().map { Chunk(it) }121 override fun values(rs: RandomSource): Sequence<Sample<Chunk<Byte>>> =122 Arb.choice(123 arrayChunkGenerator(Arb.byte(), ChunkShrinker()) { values, offset, length ->124 Chunk.bytes(values.toByteArray(), offset, length)125 },126 arrayChunkGenerator(Arb.byte(), ChunkShrinker()) { values, _, _ ->127 Chunk.array(values.toTypedArray())128 }129 ).values(rs)130 }131fun Arb.Companion.intChunk(): Arb<Chunk<Int>> =132 object : Arb<Chunk<Int>>() {133 override fun edgecases(): List<Chunk<Int>> =134 listOf(Chunk.empty<Int>()) + Arb.int().edgecases().map { Chunk(it) }135 override fun values(rs: RandomSource): Sequence<Sample<Chunk<Int>>> =136 Arb.choice(137 arrayChunkGenerator(Arb.int(), ChunkShrinker()) { values, offset, length ->138 Chunk.ints(values.toIntArray(), offset, length)139 },140 arrayChunkGenerator(Arb.int(), ChunkShrinker()) { values, _, _ ->141 Chunk.array(values.toTypedArray())142 }143 ).values(rs)144 }145fun Arb.Companion.longChunk(): Arb<Chunk<Long>> =146 object : Arb<Chunk<Long>>() {147 override fun edgecases(): List<Chunk<Long>> =148 listOf(Chunk.empty<Long>()) + Arb.long().edgecases().map { Chunk(it) }149 override fun values(rs: RandomSource): Sequence<Sample<Chunk<Long>>> =150 Arb.choice(151 arrayChunkGenerator(Arb.long(), ChunkShrinker()) { values, offset, length ->152 Chunk.longs(values.toLongArray(), offset, length)153 },154 arrayChunkGenerator(Arb.long(), ChunkShrinker()) { values, _, _ ->155 Chunk.array(values.toTypedArray())156 }157 ).values(rs)158 }159fun Arb.Companion.doubleChunk(): Arb<Chunk<Double>> =160 object : Arb<Chunk<Double>>() {161 override fun edgecases(): List<Chunk<Double>> =162 listOf(Chunk.empty<Double>()) + Arb.double().edgecases().map { Chunk(it) }163 override fun values(rs: RandomSource): Sequence<Sample<Chunk<Double>>> =164 Arb.choice(165 arrayChunkGenerator(Arb.double(), ChunkShrinker()) { values, offset, length ->166 Chunk.doubles(values.toDoubleArray(), offset, length)167 },168 arrayChunkGenerator(Arb.double(), ChunkShrinker()) { values, _, _ ->169 Chunk.array(values.toTypedArray())170 }171 ).values(rs)172 }173fun Arb.Companion.floatChunk(): Arb<Chunk<Float>> =174 object : Arb<Chunk<Float>>() {175 override fun edgecases(): List<Chunk<Float>> =176 listOf(Chunk.empty<Float>()) + Arb.float().edgecases().map { Chunk(it) }177 override fun values(rs: RandomSource): Sequence<Sample<Chunk<Float>>> =178 Arb.choice(179 arrayChunkGenerator(Arb.float(), ChunkShrinker()) { values, offset, length ->180 Chunk.floats(values.toFloatArray(), offset, length)181 },182 arrayChunkGenerator(Arb.float(), ChunkShrinker()) { values, _, _ ->183 Chunk.array(values.toTypedArray())184 }185 ).values(rs)186 }187fun Arb.Companion.shortChunk(): Arb<Chunk<Short>> =188 object : Arb<Chunk<Short>>() {189 override fun edgecases(): List<Chunk<Short>> =190 listOf(Chunk.empty<Short>()) + Arb.short().edgecases().map { Chunk(it) }191 override fun values(rs: RandomSource): Sequence<Sample<Chunk<Short>>> =192 Arb.choice(193 arrayChunkGenerator(Arb.short(), ChunkShrinker()) { values, offset, length ->194 Chunk.shorts(values.toShortArray(), offset, length)195 },196 arrayChunkGenerator(Arb.short(), ChunkShrinker()) { values, _, _ ->197 Chunk.array(values.toTypedArray())198 }199 ).values(rs)200 }...

Full Screen

Full Screen

Exhaustive.kt

Source:Exhaustive.kt Github

copy

Full Screen

1package utils2import io.kotest.property.Arb3import io.kotest.property.Exhaustive4import io.kotest.property.Gen5import io.kotest.property.RandomSource6import io.kotest.property.arbitrary.byte7import io.kotest.property.arbitrary.next8import io.kotest.property.exhaustive.exhaustive9import io.kotest.property.exhaustive.filter10import io.kotest.property.exhaustive.ints11import io.kotest.property.exhaustive.map12fun <N : Number> Exhaustive<N>.toInt() = map { it.toInt() }13fun <N : Number> Exhaustive<N>.toShort() = map { it.toShort() }14fun Exhaustive.Companion.shorts(min: Short = Short.MIN_VALUE, max: Short = Short.MAX_VALUE) =15 Exhaustive.ints(min..max).map { it.toShort() }16fun Exhaustive.Companion.ubytes(min: UByte = UByte.MIN_VALUE, max: UByte = UByte.MAX_VALUE): Exhaustive<UByte> =17 Exhaustive.ints(min.toInt()..max.toInt()).map { it.toUByte() }18fun Exhaustive.Companion.ushorts(min: UShort = UShort.MIN_VALUE, max: UShort = UShort.MAX_VALUE): Exhaustive<UShort> =19 Exhaustive.ints(min.toInt()..max.toInt()).map { it.toUShort() }20fun Exhaustive.Companion.byteArrays(length: IntRange, byte: Gen<Byte> = Arb.byte()): Exhaustive<ByteArray> {21 val generator = byte.generate(RandomSource.Default).iterator()22 return length.map { ByteArray(it) { generator.next().value } }.exhaustive()23}24operator fun <A> Exhaustive<A>.minus(other: Exhaustive<A>) =25 filter { it !in other.values }26inline fun <reified T> Exhaustive.Companion.arrayOf(value: Arb<T>, length: IntRange): Exhaustive<Array<T>> {27 return length.map { Array(it) { value.next() } }.exhaustive()28}...

Full Screen

Full Screen

Arb.Companion.short

Using AI Code Generation

copy

Full Screen

1 companion object {2 fun short(min: Short = Short.MIN_VALUE, max: Short = Short.MAX_VALUE): Arb<Short> =3 Arb.int(min.toInt(), max.toInt()).map { it.toShort() }4 }5}6 companion object {7 fun int(min: Int = Int.MIN_VALUE, max: Int = Int.MAX_VALUE): Arb<Int> =8 Arb.long(min.toLong(), max.toLong()).map { it.toInt() }9 }10}11 companion object {12 fun long(min: Long = Long.MIN_VALUE, max: Long = Long.MAX_VALUE): Arb<Long> =13 Arb.choose(min, max)14 }15}16 companion object {17 fun float(min: Float = Float.MIN_VALUE, max: Float = Float.MAX_VALUE): Arb<Float> =18 Arb.double(min.toDouble(), max.toDouble()).map { it.toFloat() }19 }20}21 companion object {22 fun double(min: Double = Double.MIN_VALUE, max: Double = Double.MAX_VALUE): Arb<Double> =23 Arb.choose(min, max)24 }25}26 companion object {27 fun char(min: Char = Char.MIN_VALUE, max: Char = Char.MAX_VALUE): Arb<Char> =28 Arb.int(min.toInt(), max.toInt()).map { it.toChar() }29 }30}31 companion object {32 fun string(minSize: Int = 0, maxSize: Int = 100, charset: Charset = Charsets.UTF_8): Arb<String> =33 Arb.int(minSize, maxSize).flatMap { size ->34 Arb.list(Arb.choose(charset)).map { it.take(size).joinToString("") }35 }36 }37}38 companion object {39 fun <T> list(arb: Arb<T>, minSize: Int =

Full Screen

Full Screen

Arb.Companion.short

Using AI Code Generation

copy

Full Screen

1fun Arb.Companion.periods(): Arb<Period> = ints(0..Int.MAX_VALUE).map { Period.ofDays(it) }2fun Arb.Companion.durations(): Arb<Duration> = longs().map { Duration.ofNanos(it) }3fun Arb.Companion.durations(min: Duration, max: Duration): Arb<Duration> = longs(min.toNanos()..max.toNanos()).map { Duration.ofNanos(it) }4fun Arb.Companion.durations(range: LongRange): Arb<Duration> = longs(range).map { Duration.ofNanos(it) }5fun Arb.Companion.durations(min: Long, max: Long): Arb<Duration> = longs(min..max).map { Duration.ofNanos(it) }6fun Arb.Companion.durations(min: Duration, max: Long): Arb<Duration> = longs(min.toNanos()..max).map { Duration.ofNanos(it) }7fun Arb.Companion.durations(min: Long, max: Duration): Arb<Duration> = longs(min..max.toNanos()).map { Duration.ofNanos(it) }8fun Arb.Companion.durations(range: LongRange, unit: DurationUnit): Arb<Duration> = longs(range).map { Duration.of(it, unit) }

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful