How to use array class of io.kotest.property.arbitrary package

Best Kotest code snippet using io.kotest.property.arbitrary.array

ArrayStoreTests.kt

Source:ArrayStoreTests.kt Github

copy

Full Screen

1package edu.rice.fset2import io.kotest.core.spec.style.FreeSpec3import io.kotest.matchers.shouldBe4import io.kotest.property.Arb5import io.kotest.property.arbitrary.arbitrary6import io.kotest.property.arbitrary.int7import io.kotest.property.arbitrary.list8import io.kotest.property.arbitrary.map9import io.kotest.property.arbitrary.next10import io.kotest.property.checkAll11internal val listIntWithIndex = arbitrary { rs ->12 val length = Arb.int(1, 10).next(rs)13 val list = Arb.list(Arb.int(0, 10000), length..length).next(rs)14 val query = Arb.int(0, length - 1).next(rs)15 Pair(list, query)16}17internal val listKVWithIndex = arbitrary { rs ->18 val length = Arb.int(1, 10).next(rs)19 val list = Arb.list(20 Arb.int(0, 10000)21 .map { kv(it.toString(), it.toString().length) },22 length..length23 )24 .next(rs)25 val query = Arb.int(0, length - 1).next(rs)26 Pair(list, query)27}28class ArrayStoreTests : FreeSpec({29 "basic equality" {30 checkAll(listIntWithIndex) { (list, _) ->31 val as1 = list.toArrayStore()32 val as2 = list.toArrayStore()33 list shouldBe as1.toList()34 as1.deepEquals(as2) shouldBe true35 as1.hashCode() shouldBe as2.hashCode()36 }37 }38 "getting" {39 checkAll(listIntWithIndex) { (list, query) ->40 val as1 = list.toArrayStore()41 as1[query] shouldBe list.get(query)42 }43 }44 "withoutIndex" {45 checkAll(listIntWithIndex) { (list, query) ->46 val as1 = list.toArrayStore()47 as1.withoutIndex(query)48 .toList() shouldBe list.filterIndexed { index, _ -> query != index }49 }50 }51 "withoutElement" {52 checkAll(listIntWithIndex) { (list, query) ->53 val as1 = list.toArrayStore()54 // might be multiple copies; we're checking that withoutElement removes the first of them55 val firstOffsetOf = list.indexOf(list[query])56 as1.withoutElement(as1[firstOffsetOf])57 .toList() shouldBe list.filterIndexed { index, _ -> firstOffsetOf != index }58 }59 }60 "updateElement" {61 checkAll(listKVWithIndex) { (list, query) ->62 val as1 = list.toArrayStore()63 val firstOffsetOf = list.indexOf(list[query])64 val updateVal = kv(65 list[query].key,66 -list[query].value67 ) // keys are still equal, values are different68 val as2 = as1.updateElement(updateVal)69 as2.deepEquals(as2) shouldBe true70 as2[firstOffsetOf].key shouldBe as1[firstOffsetOf].key71 as2[firstOffsetOf].value shouldBe -as1[firstOffsetOf].value72 // now, we'll try something that's not there73 as1.updateElement(kv("-5", 5)).deepEquals(as1) shouldBe true74 }75 }76 "updateOffset" {77 checkAll(listIntWithIndex) { (list, query) ->78 val as1 = list.toArrayStore()79 val as2 = as1.updateOffset(query, -5)80 val expected = list.subList(0, query) + (-5) + (list.subList(query + 1, list.size))81 as2.toList() shouldBe expected82 }83 }84 "contains and find" {85 checkAll(listIntWithIndex) { (list, query) ->86 val as1 = list.toArrayStore()87 as1.contains(list[query]) shouldBe true88 as1.contains(-5) shouldBe false89 as1.find(list[query]) shouldBe list[query]90 as1.find(-5) shouldBe null91 }92 }93 "insert" {94 checkAll(listIntWithIndex) { (list, query) ->95 val as1 = list.toArrayStore()96 val as2 = as1.insert(-5, query)97 as2.size() shouldBe list.size + 198 as2.toList() shouldBe list.subList(0, query) + (-5) + list.subList(query, list.size)99 }100 }101 "mapIndexed" {102 checkAll(listIntWithIndex) { (list, _) ->103 val as1 = list.toArrayStore()104 val as2 = as1.mapIndexed { index, value -> index + value }105 as2.toList() shouldBe list.mapIndexed { index, value -> index + value }106 }107 }108 "append" {109 checkAll(listIntWithIndex) { (list, _) ->110 val as1 = list.toArrayStore()111 val as2 = as1.append(-5)112 as2.toList() shouldBe list + (-5)113 }114 }115 "flatMap" {116 checkAll(listIntWithIndex) { (list, _) ->117 val as1 = list.toArrayStore()118 as1.flatMap {119 sequenceOf("<", it.toString(), ">")120 }.toList() shouldBe list.flatMap {121 sequenceOf("<", it.toString(), ">")122 }.toList()123 }124 }125 "joinToString" {126 checkAll(listIntWithIndex) { (list, _) ->127 val as1 = list.toArrayStore()128 as1.joinToString(", ") shouldBe list.joinToString(separator = ", ")129 }130 }131 "toSet" {132 checkAll(listIntWithIndex) { (list, _) ->133 val as1 = list.toArrayStore()134 as1.toSet() shouldBe list.toSet()135 }136 }137})...

Full Screen

Full Screen

NotePitchTest.kt

Source:NotePitchTest.kt Github

copy

Full Screen

1package io.loskunos.midi2import io.kotest.data.forAll3import io.kotest.data.row4import io.kotest.matchers.collections.shouldContainExactly5import io.kotest.matchers.shouldBe6import io.kotest.property.Arb7import io.kotest.property.Exhaustive8import io.kotest.property.arbitrary.element9import io.kotest.property.arbitrary.list10import io.kotest.property.checkAll11import io.kotest.property.exhaustive.collection12import io.kotest.property.exhaustive.enum13import io.loskunos.midi.Octave.Companion.o014import io.loskunos.midi.Octave.Companion.o115import io.loskunos.midi.Octave.Companion.o216import io.loskunos.midi.Octave.Companion.o317import io.loskunos.midi.Octave.Companion.o418import io.loskunos.midi.Octave.Companion.o519import io.loskunos.midi.Octave.Companion.o620import io.loskunos.midi.Octave.Companion.o721import io.loskunos.midi.Octave.Companion.o822import io.loskunos.midi.PitchClass.C23import kotlinx.coroutines.runBlocking24import org.junit.jupiter.api.Nested25import org.junit.jupiter.api.Test26class NotePitchTest {27 private val allPitchClassInstances = PitchClass::class.sealedSubclasses.map { it.objectInstance!! }28 @Nested29 inner class PitchClassToNotePitch {30 @Test31 fun `should be the same note`() {32 runBlocking {33 checkAll(Exhaustive.collection(allPitchClassInstances)) { pitchClass ->34 pitchClass.octave(o1).pitchClass shouldBe pitchClass35 }36 }37 }38 @Test39 fun `should have given octave`() {40 runBlocking {41 checkAll(Exhaustive.enum<Octave>()) { givenOctave ->42 C.octave(givenOctave) shouldBe NotePitch(C, givenOctave)43 }44 }45 }46 }47 @Test48 fun `adding octave to a list of PitchClasses returns a list of NotePitches with correct octave`() {49 runBlocking {50 checkAll(iterations = 10, Arb.list(Arb.element(allPitchClassInstances), range = 0..10)) { pitchClasses ->51 checkAll(Exhaustive.enum<Octave>()) { givenOctave ->52 forAll(53 row { octave(givenOctave, *pitchClasses.toTypedArray()) },54 row { octave(givenOctave) { pitchClasses } },55 row { pitchClasses.octave(givenOctave) }56 ) { octaveFun ->57 val result = octaveFun()58 result.map { it.octave }.forEach { it shouldBe givenOctave }59 result.map { it.pitchClass } shouldContainExactly pitchClasses60 }61 }62 }63 }64 }65 @Test66 fun `o0-o8 functions should return NotePitch with correct octave`() {67 C.o0.octave shouldBe o068 C.o1.octave shouldBe o169 C.o2.octave shouldBe o270 C.o3.octave shouldBe o371 C.o4.octave shouldBe o472 C.o5.octave shouldBe o573 C.o6.octave shouldBe o674 C.o7.octave shouldBe o775 C.o8.octave shouldBe o876 }77}...

Full Screen

Full Screen

Exhaustive.kt

Source:Exhaustive.kt Github

copy

Full Screen

...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.kt

Source:Arb.kt Github

copy

Full Screen

...24}25fun Arb.Companion.ulong() = arbitrary(listOf(ULong.MIN_VALUE, ULong.MAX_VALUE)) {26 it.random.nextULong()27}28inline fun <reified T> Arb.Companion.arrayOf(value: Arb<T>, length: IntRange): Arb<Array<T>> = arbitrary { rs ->29 Array(rs.random.nextInt(length.first, length.last)) {30 value.sample(rs).value31 }32}...

Full Screen

Full Screen

MumbleLinkImplTest.kt

Source:MumbleLinkImplTest.kt Github

copy

Full Screen

1package com.skaggsm.jmumblelink2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.shouldBe4import io.kotest.property.Arb5import io.kotest.property.arbitrary.filter6import io.kotest.property.arbitrary.map7import io.kotest.property.arbitrary.string8import io.kotest.property.checkAll9/**10 * Created by Mitchell Skaggs on 5/17/2019.11 */12class MumbleLinkImplTest : StringSpec({13 "Given a link to Mumble, when data is written, then the basic data is persisted correctly"{14 MumbleLinkImpl().use {15 it.uiVersion = 216 it.uiTick++17 it.name = "Testname"18 it.avatarPosition = floatArrayOf(0f, 0f, 0f)19 it.uiVersion shouldBe 220 it.uiTick shouldBe 121 it.name shouldBe "Testname"22 it.avatarPosition shouldBe floatArrayOf(0f, 0f, 0f)23 }24 }25 "Given a link to Mumble, when a name is written, it should be readable"{26 checkAll(Arb.string().map { it + it + it }.filter { it.length <= 255 }) { name: String ->27 MumbleLinkImpl().use {28 it.name = name29 it.name shouldBe name30 }31 }32 }33})...

Full Screen

Full Screen

InsertionSortTest.kt

Source:InsertionSortTest.kt Github

copy

Full Screen

...5import io.kotest.property.arbitrary.int6import io.kotest.property.arbitrary.intArray7import io.kotest.property.checkAll8class InsertionSortTest : StringSpec({9 "should sort array in ascending order" {10 checkAll(Arb.intArray(Arb.int(5, 15), Arb.int())) { array ->11 InsertionSort.sort(array.toTypedArray()).shouldBeSorted()12 }13 }14})...

Full Screen

Full Screen

SelectionSortTest.kt

Source:SelectionSortTest.kt Github

copy

Full Screen

...5import io.kotest.property.arbitrary.int6import io.kotest.property.arbitrary.intArray7import io.kotest.property.checkAll8class SelectionSortTest : StringSpec({9 "should sort int array ascending" {10 checkAll(Arb.intArray(Arb.int(5, 15), Arb.int())) { array ->11 SelectionSort.sort(array.toTypedArray()).shouldBeSorted()12 }13 }14})...

Full Screen

Full Screen

BubbleSortTest.kt

Source:BubbleSortTest.kt Github

copy

Full Screen

...5import io.kotest.property.arbitrary.int6import io.kotest.property.arbitrary.intArray7import io.kotest.property.checkAll8class BubbleSortTest : StringSpec({9 "should sort int array ascending" {10 checkAll(Arb.intArray(Arb.int(5, 15), Arb.int())) { array ->11 BubbleSort.sort(array.toTypedArray()).shouldBeSorted()12 }13 }14})...

Full Screen

Full Screen

array

Using AI Code Generation

copy

Full Screen

1val arrayArb = Arb.array(Arb.int())2arrayArb.take(10).forEach { println(it.toList()) }3val mapArb = Arb.map(Arb.int(), Arb.int())4mapArb.take(10).forEach { println(it.entries.toList()) }5val setArb = Arb.set(Arb.int())6setArb.take(10).forEach { println(it.toList()) }7val stringArb = Arb.string()8stringArb.take(10).forEach { println(it) }9val uuidArb = Arb.uuid()10uuidArb.take(10).forEach { println(it) }11enum class TestEnum { A, B, C }12val enumArb = Arb.enum<TestEnum>()13enumArb.take(10).forEach { println(it) }14enum class TestEnum2 { A, B, C }15val enumArb2 = Arb.enum<TestEnum2>()16enumArb2.take(10).forEach { println(it) }17enum class TestEnum3 { A, B, C }18val enumArb3 = Arb.enum<TestEnum3>()19enumArb3.take(10).forEach { println(it) }20enum class TestEnum4 { A, B, C }21val enumArb4 = Arb.enum<TestEnum4>()22enumArb4.take(10).forEach { println(it) }23enum class TestEnum5 { A, B, C }24val enumArb5 = Arb.enum<TestEnum5>()25enumArb5.take(10).forEach { println(it) }26enum class TestEnum6 { A, B, C }27val enumArb6 = Arb.enum<TestEnum6>()28enumArb6.take(10

Full Screen

Full Screen

array

Using AI Code Generation

copy

Full Screen

1val arrayArb = Arb.int().array()2arrayArb.take(10).forEach { println(it.toList()) }3val listArb = Arb.int().list()4listArb.take(10).forEach { println(it) }5val setArb = Arb.int().set()6setArb.take(10).forEach { println(it) }7val mapArb = Arb.int().map(Arb.string())8mapArb.take(10).forEach { println(it) }9val sequenceArb = Arb.int().sequence()10sequenceArb.take(10).forEach { println(it.toList()) }11val streamArb = Arb.int().stream()12streamArb.take(10).forEach { println(it.toList()) }13val stringArb = Arb.string()14stringArb.take(10).forEach { println(it) }15val rangeArb = Arb.int().range(1..10)16rangeArb.take(10).forEach { println(it) }17val charArb = Arb.char()18charArb.take(10).forEach { println(it) }19val booleanArb = Arb.boolean()20booleanArb.take(10).forEach { println(it) }21val byteArb = Arb.byte()22byteArb.take(10).forEach { println(it) }23val shortArb = Arb.short()24shortArb.take(10).forEach { println(it) }25val longArb = Arb.long()26longArb.take(10).forEach { println(it) }

Full Screen

Full Screen

array

Using AI Code Generation

copy

Full Screen

1val arrayArb = Arb.array(Arb.int())2val arrayArb = Arb.array(Arb.int(), 10, 100)3val arrayArb = Arb.array(Arb.int(), 10..100)4val arrayArb = Arb.array(Arb.int(), 10, 100) { it.toList() }5val arrayArb = Arb.array(Arb.int(), 10..100) { it.toList() }6val arrayArb = Arb.array(Arb.int(), 10, 100) { it.toList() }7val arrayArb = Arb.array(Arb.int(), 10..100) { it.toList() }8val collectionArb = Arb.collection(Arb.int())9val collectionArb = Arb.collection(Arb.int(), 10, 100)10val collectionArb = Arb.collection(Arb.int(), 10..100)11val collectionArb = Arb.collection(Arb.int(), 10, 100) { it.toList() }12val collectionArb = Arb.collection(Arb.int(), 10..100) { it.toList() }13val collectionArb = Arb.collection(Arb.int(), 10, 100) { it.toList() }14val collectionArb = Arb.collection(Arb.int(), 10..100) { it.toList() }15val setArb = Arb.set(Arb.int())16val setArb = Arb.set(Arb.int(), 10, 100)17val setArb = Arb.set(Arb.int(), 10..100)18val setArb = Arb.set(Arb.int(), 10, 100) { it.toList() }19val setArb = Arb.set(Arb.int(), 10..100) { it.toList() }20val setArb = Arb.set(Arb.int(), 10, 100) { it.toList() }21val setArb = Arb.set(Arb.int(), 10..100) { it.toList() }22val mapArb = Arb.map(Arb.int(), Arb.int())23val mapArb = Arb.map(Arb.int(), Arb.int(), 10, 100)24val mapArb = Arb.map(Arb.int(), Arb.int(), 10..100)

Full Screen

Full Screen

array

Using AI Code Generation

copy

Full Screen

1val intList = Gen.list(Gen.int()).random().take(5).toList()2println(intList)3val intList = Gen.list(Gen.int()).random().take(5).toList()4println(intList)5val intList = Gen.list(Gen.int()).random().take(5).toList()6println(intList)7val intList = Gen.list(Gen.int()).random().take(5).toList()8println(intList)9val intList = Gen.list(Gen.int()).random().take(5).toList()10println(intList)11val intList = Gen.list(Gen.int()).random().take(5).toList()12println(intList)13val intList = Gen.list(Gen.int()).random().take(5).toList()14println(intList)15val intList = Gen.list(Gen.int()).random().take(5).toList()16println(intList)17val intList = Gen.list(Gen.int()).random().take(5).toList()18println(intList)19val intList = Gen.list(Gen.int()).random().take(5).toList()20println(intList)21val intList = Gen.list(Gen.int()).random().take(5).toList()22println(intList)23val intList = Gen.list(Gen.int()).random().take(5).toList()24println(intList)25val intList = Gen.list(Gen.int()).random().take(5).toList()26println(intList)27val intList = Gen.list(Gen.int()).random().take(5).toList()28println(intList)29val intList = Gen.list(Gen.int()).random().take(5).toList()30println(intList)

Full Screen

Full Screen

array

Using AI Code Generation

copy

Full Screen

1val arrayArb = ArrayArbitrary(1..10, Arb.int())2val array = arrayArb.next(RandomSource.Default)3println(array.joinToString())4val stringArb = StringArbitrary(1..10, Arb.int())5val string = stringArb.next(RandomSource.Default)6println(string)7val setArb = SetArbitrary(1..10, Arb.int())8val set = setArb.next(RandomSource.Default)9println(set)10val listArb = ListArbitrary(1..10, Arb.int())11val list = listArb.next(RandomSource.Default)12println(list)13val mapArb = MapArbitrary(1..10, Arb.int(), Arb.string())14val map = mapArb.next(RandomSource.Default)15println(map)16val enumArb = EnumArbitrary(TestEnum::class)17val enum = enumArb.next(RandomSource.Default)18println(enum)19val uuidArb = UUIDArbitrary()20val uuid = uuidArb.next(RandomSource.Default)21println(uuid)22val instantArb = InstantArbitrary()23val instant = instantArb.next(RandomSource.Default)24println(instant)25val localDateArb = LocalDateArbitrary()26val localDate = localDateArb.next(RandomSource.Default)27println(localDate)28val localTimeArb = LocalTimeArbitrary()29val localTime = localTimeArb.next(RandomSource.Default)30println(localTime)31val localDateTimeArb = LocalDateTimeArbitrary()32val localDateTime = localDateTimeArb.next(RandomSource.Default)33println(localDateTime)34val zonedDateTimeArb = ZonedDateTimeArbitrary()

Full Screen

Full Screen

array

Using AI Code Generation

copy

Full Screen

1val array = arrayOf(1, 2, 3, 4, 5)2val arrayArb = array(arbInt())3val result = arrayArb.random().value4println(result)5val list = listOf(1, 2, 3, 4, 5)6val listArb = list(arbInt())7val result = listArb.random().value8println(result)9val set = setOf(1, 2, 3, 4, 5)10val setArb = set(arbInt())11val result = setArb.random().value12println(result)13val map = mapOf(1 to "one", 2 to "two", 3 to "three", 4 to "four", 5 to "five")14val mapArb = map(arbInt(), arbString())15val result = mapArb.random().value16println(result)17val sequence = sequenceOf(1, 2, 3, 4, 5)18val sequenceArb = sequence(arbInt())19val result = sequenceArb.random().value20println(result)21val stringArb = string()22val result = stringArb.random().value23println(result)24val charArb = char()25val result = charArb.random().value26println(result)27val bigInt = BigInteger("1234567890")28val bigIntArb = bigInt()29val result = bigIntArb.random().value30println(result)31val bigDecimal = BigDecimal("1234567890.1234567890")32val bigDecimalArb = bigDecimal()33val result = bigDecimalArb.random().value34println(result)

Full Screen

Full Screen

array

Using AI Code Generation

copy

Full Screen

1val array = Arb.array(Arb.int(0..10), 5)2val array = Arb.array(Arb.int(0..100), 10)3val array = Arb.array(Arb.char('a'..'z'), 5)4val array = Arb.array(Arb.char('a'..'z'), 10)5val array = Arb.array(Arb.string(1..1, Arb.char('a'..'z')), 5)6val array = Arb.array(Arb.string(1..1, Arb.char('a'..'z')), 10)7val array = Arb.array(Arb.string(1..1, Arb.char('a'..'z')), 5)

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 methods 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