Best Kotest code snippet using io.kotest.property.arbitrary.shorts
YamlReadingTest.kt
Source:YamlReadingTest.kt
...473 it("deserializes it to the expected value") {474 result shouldBe listOf(123L, 45, 6)475 }476 }477 context("parsing that input as a list of shorts") {478 val result = Yaml.default.decodeFromString(ListSerializer(Short.serializer()), input)479 it("deserializes it to the expected value") {480 result shouldBe listOf(123.toShort(), 45, 6)481 }482 }483 context("parsing that input as a list of bytes") {484 val result = Yaml.default.decodeFromString(ListSerializer(Byte.serializer()), input)485 it("deserializes it to the expected value") {486 result shouldBe listOf(123.toByte(), 45, 6)487 }488 }489 context("parsing that input as a list of doubles") {490 val result = Yaml.default.decodeFromString(ListSerializer(Double.serializer()), input)491 it("deserializes it to the expected value") {...
ChunkTest.kt
Source:ChunkTest.kt
1package arrow.fx.coroutines.stream2import arrow.fx.coroutines.ArrowFxSpec3import io.kotest.assertions.assertSoftly4import io.kotest.matchers.shouldBe5import io.kotest.matchers.shouldNotBe6import io.kotest.property.Arb7import io.kotest.property.arbitrary.int8import io.kotest.property.arbitrary.list9import io.kotest.property.arbitrary.orNull10import io.kotest.property.arbitrary.positiveInts11import io.kotest.property.arbitrary.string12import kotlin.math.max13class ChunkTest : ArrowFxSpec() {14 init {15 testChunk("BooleanArray", Arb.booleanChunk())16 testChunk("IntArray", Arb.intChunk())17 testChunk("DoubleArray", Arb.doubleChunk())18 testChunk("LongArray", Arb.longChunk())19 testChunk("BytesArray", Arb.byteChunk())20 testChunk("Boxed", Arb.boxedChunk(Arb.int().orNull()))21 testChunk("Float", Arb.floatChunk())22 testChunk("Short", Arb.shortChunk())23 "Chunk - toList" {24 checkAll(Arb.list(Arb.int(), 0..10)) { l ->25 Chunk.iterable(l).toList() shouldBe l26 }27 }28 "Chunk - tail" {29 checkAll(Arb.chunk(Arb.int())) { ch ->30 val expected = ch.toList().drop(1)31 ch.tail().toList() shouldBe expected32 }33 }34 "Chunk - filter" {35 checkAll(Arb.chunk(Arb.int())) { ch ->36 val f = { i: Int -> i % 2 == 0 }37 ch.filter(f).toList() shouldBe ch.toList().filter(f)38 }39 }40 "Chunk - first" {41 checkAll(Arb.chunk(Arb.int())) { ch ->42 ch.firstOrNull() shouldBe ch.toList().firstOrNull()43 }44 }45 "Chunk - firstOrNull()" {46 checkAll(Arb.chunk(Arb.int())) { ch ->47 ch.firstOrNull() shouldBe ch.toList().firstOrNull()48 }49 }50 "Chunk - firstOrNull(f)" {51 checkAll(Arb.chunk(Arb.int()), Arb.int()) { ch, n ->52 val f = { i: Int -> i < n }53 ch.firstOrNull(f) shouldBe ch.toList().firstOrNull(f)54 }55 }56 "Chunk - lastOrNull" {57 checkAll(Arb.chunk(Arb.int())) { ch ->58 ch.lastOrNull() shouldBe ch.toList().lastOrNull()59 }60 }61 "Chunk - lastOrNull(f)" {62 checkAll(Arb.chunk(Arb.int()), Arb.int()) { ch, n ->63 val f = { i: Int -> i < n }64 ch.lastOrNull(f) shouldBe ch.toList().lastOrNull(f)65 }66 }67 "Chunk - drop(n)" {68 checkAll(Arb.chunk(Arb.int().orNull()), Arb.int()) { ch, n ->69 ch.drop(n)70 .toList() shouldBe ch.toList().drop(max(n, 0))71 }72 }73 "Chunk - take(n)" {74 checkAll(Arb.chunk(Arb.int().orNull()), Arb.int()) { ch, n ->75 ch.take(n)76 .toList() shouldBe ch.toList().take(max(n, 0))77 }78 }79 "Chunk - takeLast(n)" {80 checkAll(Arb.chunk(Arb.int().orNull()), Arb.int()) { ch, n ->81 ch.takeLast(n)82 .toList() shouldBe ch.toList().takeLast(max(n, 0))83 }84 }85 "Chunk - indexOfFirst" {86 checkAll(Arb.chunk(Arb.int()), Arb.int()) { ch, n ->87 val f = { i: Int -> i < n }88 ch.indexOfFirst(f) shouldBe ch.toList().indexOfFirst(f).let {89 if (it == -1) null else it90 }91 }92 }93 "Chunk - map" {94 checkAll(Arb.chunk(Arb.int()), Arb.int()) { a, b ->95 a.map { b }.toList() shouldBe a.toList().map { b }96 }97 }98 "Chunk - flatMap" {99 checkAll(Arb.chunk(Arb.int()), Arb.chunk(Arb.int())) { a, b ->100 a.flatMap { b }.toList() shouldBe a.toList().flatMap { b.toList() }101 }102 }103 "Chunk - fold" {104 checkAll(Arb.chunk(Arb.int())) { a ->105 a.fold(0) { acc, i -> acc + i } shouldBe a.toList().fold(0) { acc, i -> acc + i }106 }107 }108 "Chunk - forEach" {109 checkAll(Arb.chunk(Arb.int())) { a ->110 var index = 0111 a.forEach { o ->112 o shouldBe a[index++]113 }114 }115 }116 "Chunk - forEachIndexed" {117 checkAll(Arb.chunk(Arb.int())) { a ->118 a.forEachIndexed { index, o ->119 o shouldBe a[index]120 }121 }122 }123 "Chunk - zip" {124 checkAll(Arb.chunk(Arb.int()), Arb.chunk(Arb.int())) { a, b ->125 a.zip(b).toList() shouldBe a.toList().zip(b.toList())126 }127 }128 "Chunk - zipWith" {129 checkAll(Arb.chunk(Arb.int()), Arb.chunk(Arb.int())) { a, b ->130 a.zipWith(b) { x, y -> x + y }.toList() shouldBe a.toList().zip(b.toList()) { x, y -> x + y }131 }132 }133 "Chunk - concat" {134 checkAll(Arb.list(Arb.chunk(Arb.int()))) { chs ->135 Chunk.concat(chs).toList() shouldBe chs.flatMap { it.toList() }136 }137 }138 "Chunk - concatBooleans" {139 checkAll(Arb.list(Arb.booleanChunk())) { chs ->140 Chunk.concat(chs).toList() shouldBe chs.flatMap { it.toList() }141 }142 }143 "Chunk - concatDouble" {144 checkAll(Arb.list(Arb.doubleChunk())) { chs ->145 Chunk.concat(chs).toList() shouldBe chs.flatMap { it.toList() }146 }147 }148 "Chunk - concatShorts" {149 checkAll(Arb.list(Arb.shortChunk())) { chs ->150 Chunk.concat(chs).toList() shouldBe chs.flatMap { it.toList() }151 }152 }153 "Chunk - byteChunk" {154 checkAll(Arb.list(Arb.byteChunk())) { chs ->155 Chunk.concat(chs).toList() shouldBe chs.flatMap { it.toList() }156 }157 }158 "Chunk - longChunk" {159 checkAll(Arb.list(Arb.longChunk())) { chs ->160 Chunk.concat(chs).toList() shouldBe chs.flatMap { it.toList() }161 }162 }163 "Chunk - intChunk" {164 checkAll(Arb.list(Arb.intChunk())) { chs ->165 Chunk.concat(chs).toList() shouldBe chs.flatMap { it.toList() }166 }167 }168 "Chunk - equals" {169 checkAll(Arb.chunk(Arb.int())) { chs ->170 assertSoftly {171 chs shouldBe chs172 chs shouldBe Chunk.iterable(chs.toList())173 if (chs.size() > 1) chs.drop(1) shouldNotBe chs174 }175 }176 }177 "Chunk - just.drop is empty" {178 Chunk.just(1).drop(1) shouldBe Chunk.empty()179 }180 "Chunk - hashCode" {181 checkAll(Arb.chunk(Arb.string())) { chs ->182 assertSoftly {183 chs.hashCode() shouldBe chs.hashCode()184 chs.hashCode() shouldBe Chunk.iterable(chs.toList()).hashCode()185 if (chs.size() >= 1) chs.drop(1).hashCode() shouldNotBe chs.hashCode()186 }187 }188 }189 "Chunk.Queue - take" {190 checkAll(Arb.list(Arb.chunk(Arb.int())), Arb.int()) { chs, n ->191 val res = Chunk.Queue(chs).take(n)192 res.toChunk().toList() shouldBe chs.flatMap { it.toList() }.take(max(n, 0))193 }194 }195 "Chunk.Queue - drop" {196 checkAll(Arb.list(Arb.chunk(Arb.int())), Arb.int()) { chs, n ->197 val result = Chunk.Queue(chs).drop(n)198 result.toChunk().toList() shouldBe chs.flatMap { it.toList() }.drop(max(n, 0))199 }200 }201 "Chunk.Queue - takeRight" {202 checkAll(Arb.list(Arb.chunk(Arb.int())), Arb.int()) { chs, n ->203 val result = Chunk.Queue(chs).takeLast(n)204 result.toChunk().toList() shouldBe chs.flatMap { it.toList() }.takeLast(max(n, 0))205 }206 }207 "Chunk.Queue - dropRight" {208 checkAll(Arb.list(Arb.chunk(Arb.int())), Arb.int()) { chs, n ->209 val result = Chunk.Queue(chs).dropLast(n)210 result.toChunk().toList() shouldBe chs.flatMap { it.toList() }.dropLast(max(n, 0))211 }212 }213 "Chunk.Queue - equals" {214 checkAll(Arb.list(Arb.chunk(Arb.int()))) { chs ->215 val cq = Chunk.Queue(chs)216 assertSoftly {217 cq shouldBe cq218 cq shouldBe Chunk.Queue(chs)219 if (cq.size > 1) cq.drop(1) shouldNotBe cq220 }221 }222 }223 "Chunk.Queue - hashCode" {224 checkAll(Arb.list(Arb.chunk(Arb.int()))) { chs ->225 val cq = Chunk.Queue(chs)226 assertSoftly {227 cq.hashCode() shouldBe cq.hashCode()228 cq.hashCode() shouldBe Chunk.Queue(chs).hashCode()229 if (cq.size > 1) cq.drop(1).hashCode() shouldNotBe cq.hashCode()230 }231 }232 }233 "BooleanArray - copyToBooleanArray" {234 checkAll(Arb.booleanChunk()) { ch ->235 val arr = BooleanArray(ch.size() * 2)236 ch.copyToArray(arr, 0)237 ch.copyToArray(arr, ch.size())238 arr.toList() shouldBe (ch.toList() + ch.toList())239 }240 }241 "IntArray - copyToIntArray" {242 checkAll(Arb.intChunk()) { ch ->243 val arr = IntArray(ch.size() * 2)244 ch.copyToArray(arr, 0)245 ch.copyToArray(arr, ch.size())246 arr.toList() shouldBe (ch.toList() + ch.toList())247 }248 }249 "DoubleArray - copyToDoubleArray" {250 checkAll(Arb.doubleChunk()) { ch ->251 val arr = DoubleArray(ch.size() * 2)252 ch.copyToArray(arr, 0)253 ch.copyToArray(arr, ch.size())254 arr.toList() shouldBe (ch.toList() + ch.toList())255 }256 }257 "LongArray - copyToLongArray" {258 checkAll(Arb.longChunk()) { ch ->259 val arr = LongArray(ch.size() * 2)260 ch.copyToArray(arr, 0)261 ch.copyToArray(arr, ch.size())262 arr.toList() shouldBe (ch.toList() + ch.toList())263 }264 }265 "ByteArray - copyToLongArray" {266 checkAll(Arb.byteChunk()) { ch ->267 val arr = ByteArray(ch.size() * 2)268 ch.copyToArray(arr, 0)269 ch.copyToArray(arr, ch.size())270 arr.toList() shouldBe (ch.toList() + ch.toList())271 }272 }273 "ShortArray - copyToShortArray" {274 checkAll(Arb.shortChunk()) { ch ->275 val arr = ShortArray(ch.size() * 2)276 ch.copyToArray(arr, 0)277 ch.copyToArray(arr, ch.size())278 arr.toList() shouldBe (ch.toList() + ch.toList())279 }280 }281 "FloatArray - copyToFloatArray" {282 checkAll(Arb.floatChunk()) { ch ->283 val arr = FloatArray(ch.size() * 2)284 ch.copyToArray(arr, 0)285 ch.copyToArray(arr, ch.size())286 arr.toList() shouldBe (ch.toList() + ch.toList())287 }288 }289 }290}291/**292 * Test suite for `open` functions of [Chunk].293 */294inline fun <reified A> ArrowFxSpec.testChunk(295 name: String,296 arb: Arb<Chunk<A>>297): Unit {298 "$name - size" {299 checkAll(arb) { ch ->300 ch.size() shouldBe ch.toList().size301 }302 }303 "$name - drop" {304 checkAll(arb, Arb.int()) { ch, n ->305 val expected = ch.toList().drop(max(n, 0))306 ch.drop(n).toList() shouldBe expected307 }308 }309 "$name - take" {310 checkAll(arb, Arb.positiveInts()) { ch, n ->311 ch.take(n).toList() shouldBe ch.toList().take(max(n, 0))312 }313 }314 "$name - isEmpty" {315 checkAll(arb) { ch ->316 ch.isEmpty() shouldBe ch.toList().isEmpty()317 }318 }319 "$name - isNotEmpty" {320 checkAll(arb) { ch ->321 ch.isNotEmpty() shouldBe ch.toList().isNotEmpty()322 }323 }324 "$name - toArray" {325 checkAll(arb) { ch ->326 ch.toArray().toList() shouldBe ch.toList()327 // Do it twice to make sure the first time didn't mutate state328 ch.toArray().toList() shouldBe ch.toList()329 }330 }331 "$name - copyToArray" {332 checkAll(arb) { ch ->333 val arr = arrayOfNulls<A>(ch.size() * 2)334 ch.copyToArray(arr, 0)335 ch.copyToArray(arr, ch.size())336 arr.toList() shouldBe (ch.toList() + ch.toList())337 }338 }339}...
Arb.kt
Source:Arb.kt
...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 }...
NumberTest.kt
Source:NumberTest.kt
...22import utils.MessageUnpackerFactory23import utils.TypedElement24import utils.minus25import utils.pack26import utils.shorts27import utils.toLong28import utils.toShort29import utils.convert30import utils.ubytes31import utils.ushorts32import utils.with33private val ALL_NEGATIVE_FIX_INT = Exhaustive.bytes(-32, -1)34private val ALL_POSITIVE_FIX_INT = Exhaustive.bytes(0, 127)35private val ALL_FIX_INT = ALL_NEGATIVE_FIX_INT + ALL_POSITIVE_FIX_INT36private val ALL_INT8 = Exhaustive.bytes()37private val ALL_INT16 = Exhaustive.shorts()38private val ALL_UINT8 = Exhaustive.ubytes()39private val ALL_UINT16 = Exhaustive.ushorts()40class NumberTest : AbstractMessagePackTest() {41 init {42 "Packer" should {43 "use fixint" {44 checkAll(ALL_FIX_INT) {45 int(it) with packer shouldBe fixint(it)46 int(it.toShort()) with packer shouldBe fixint(it)47 int(it.toInt()) with packer shouldBe fixint(it)48 int(it.toLong()) with packer shouldBe fixint(it)49 }50 }51 "use int8" {52 checkAll(ALL_INT8 - ALL_FIX_INT) {53 int(it) with packer shouldBe int8(it)...
Exhaustive.kt
Source:Exhaustive.kt
...10import 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}...
shorts
Using AI Code Generation
1import io.kotest.property.arbitrary.*2val shorts = Shorts()3val shorts = Shorts(0, 100)4val shorts = Shorts(0, 100, 5)5val shorts = Shorts(0, 100, 5, 10)6val shorts = Shorts(0, 100, 5, 10, 15)7val shorts = Shorts(0, 100, 5, 10, 15, 20)8val shorts = Shorts(0, 100, 5, 10, 15, 20, 25)9val shorts = Shorts(0, 100, 5, 10, 15, 20, 25, 30)10val shorts = Shorts(0, 100, 5, 10, 15, 20, 25, 30, 35)11val shorts = Shorts(0, 100, 5, 10, 15, 20, 25, 30, 35, 40)12val shorts = Shorts(0, 100, 5, 10, 15, 20, 25, 30, 35, 40, 45)13val shorts = Shorts(0, 100, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50)14val shorts = Shorts(0, 100, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55)15val shorts = Shorts(0, 100, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60)16val shorts = Shorts(0, 100, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65)17val shorts = Shorts(0, 100, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70)18val shorts = Shorts(0, 100, 5, 10, 15,
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!