How to use List.exhaustive method of io.kotest.property.exhaustive.Exhaustive class

Best Kotest code snippet using io.kotest.property.exhaustive.Exhaustive.List.exhaustive

PitchProperties.kt

Source:PitchProperties.kt Github

copy

Full Screen

1package org.harris.notes2import io.kotest.matchers.shouldBe3import io.kotest.property.Exhaustive4import io.kotest.property.checkAll5import io.kotest.property.exhaustive.enum6import io.kotest.property.exhaustive.exhaustive7import io.kotest.property.exhaustive.ints8import io.kotest.runner.junit4.StringSpec9val pitches = listOf(10 Pitch.C,11 Pitch.G,12 Pitch.D,13 Pitch.A,14 Pitch.E,15 Pitch.B,16 Pitch.F,17 Pitch.BFlat,18 Pitch.EFlat,19 Pitch.AFlat,20 Pitch.DFlat,21 Pitch.GFlat,22 Pitch.FSharp,23 Pitch.CSharp,24 Pitch.GSharp,25 Pitch.DSharp,26 Pitch.ASharp27)28class PitchProperties : StringSpec({29 "Sharping and flating a pitch results in the original pitch" {30 checkAll(pitches.exhaustive()) { pitch ->31 pitch.sharp().flat().value() shouldBe pitch.value()32 }33 }34 "Flating and sharping a pitch results in the original pitch" {35 checkAll(pitches.exhaustive()) { pitch ->36 pitch.flat().sharp().value() shouldBe pitch.value()37 }38 }39 "A sharped pitch has a higher pitch except B" {40 checkAll(pitches.exhaustive()) { pitch ->41 if (pitch == Pitch.B) {42 pitch.sharp() == Pitch.C43 } else {44 pitch.sharp().value() > pitch.value()45 }46 }47 }48 "A ftated pitch has a lower pitch except C" {49 checkAll(pitches.exhaustive()) { pitch ->50 if (pitch == Pitch.C) {51 pitch.flat() == Pitch.B52 } else {53 pitch.flat().value() < pitch.value()54 }55 }56 }57 "semitones between a pitch and itself sharp n times is n semitones" {58 checkAll(pitches.exhaustive(), Exhaustive.ints(0..12)) { pitch, distance ->59 var transposed = pitch60 for (d in 0 until distance) {61 transposed = transposed.sharp()62 }63 if (distance == 12) {64 pitch.absoluteDistance(transposed) shouldBe 065 } else {66 pitch.absoluteDistance(transposed) shouldBe distance67 }68 }69 }70 "semitones between a pitch and itself flat n times is n semitones" {71 checkAll(pitches.exhaustive(), Exhaustive.ints(0..12)) { pitch, distance ->72 var transposed = pitch73 for (d in 0 until distance) {74 transposed = transposed.flat()75 }76 if (distance == 12 || distance == 0) {77 pitch.absoluteDistance(transposed) shouldBe 078 } else {79 pitch.absoluteDistance(transposed) shouldBe 12 - distance80 }81 }82 }83 "interval between a pitch and itself transposed by an interval is the interval with some exceptions" {84 checkAll(pitches.exhaustive(), Exhaustive.enum<Interval>()) { pitch, interval ->85 val to = pitch.transpose(interval)86 val resultingInterval = pitch.intervalTo(to)87 when (pitch) {88 Pitch.CSharp, Pitch.DSharp, Pitch.FSharp, Pitch.GSharp, Pitch.ASharp ->89 if (interval == Interval.MinorSecond) {90 resultingInterval shouldBe Interval.AugmentedUnison91 }92 Pitch.E, Pitch.B, Pitch.BFlat, Pitch.AFlat, Pitch.DFlat, Pitch.GFlat ->93 if (interval == Interval.AugmentedSecond) {94 resultingInterval shouldBe Interval.MinorThird95 }96 Pitch.EFlat ->97 if (interval == Interval.DiminishedFifth) {98 resultingInterval shouldBe Interval.AugmentedFourth99 }100 else -> when (interval) {101 Interval.Tritone -> resultingInterval shouldBe Interval.DiminishedFifth102 Interval.DiminishedSeventh -> resultingInterval shouldBe Interval.MajorSixth103 Interval.PerfectOctave -> resultingInterval shouldBe Interval.Unison104 Interval.MinorNinth -> resultingInterval shouldBe Interval.MinorSecond105 Interval.MajorNinth -> resultingInterval shouldBe Interval.MajorSecond106 Interval.AugmentedNinth -> resultingInterval shouldBe Interval.AugmentedSecond107 Interval.PerfectEleventh -> resultingInterval shouldBe Interval.PerfectFourth108 Interval.AugmentedEleventh -> resultingInterval shouldBe Interval.AugmentedFourth109 Interval.MinorThirteenth -> resultingInterval shouldBe Interval.MinorSixth110 Interval.MajorThirteenth -> resultingInterval shouldBe Interval.MajorSixth111 else -> resultingInterval shouldBe interval112 }113 }114 }115 }116})...

Full Screen

Full Screen

BatchMigrationGenerator.kt

Source:BatchMigrationGenerator.kt Github

copy

Full Screen

1package liquibase.ext.generators2import io.kotest.property.Arb3import io.kotest.property.Exhaustive4import io.kotest.property.RandomSource5import io.kotest.property.arbitrary.arbitrary6import io.kotest.property.arbitrary.filter7import io.kotest.property.arbitrary.filterNot8import io.kotest.property.arbitrary.int9import io.kotest.property.arbitrary.list10import io.kotest.property.arbitrary.long11import io.kotest.property.arbitrary.map12import io.kotest.property.arbitrary.next13import io.kotest.property.arbitrary.orNull14import io.kotest.property.exhaustive.azstring15import io.kotest.property.exhaustive.exhaustive16import io.kotest.property.exhaustive.merge17import liquibase.ext.changes.BatchMigrationChange18import java.sql.RowIdLifetime19object BatchMigrationGenerator {20 val identifierGen = { min: Int -> Exhaustive.azstring(min..16).toArb() }21 val rowIdLifeTimeInvalidGenerator = listOf(22 RowIdLifetime.ROWID_UNSUPPORTED,23 RowIdLifetime.ROWID_VALID_OTHER,24 RowIdLifetime.ROWID_VALID_SESSION,25 RowIdLifetime.ROWID_VALID_TRANSACTION26 ).exhaustive()27 val rowIdLifeTimeGenerator = listOf(28 RowIdLifetime.ROWID_VALID_FOREVER,29 ).exhaustive().merge(rowIdLifeTimeInvalidGenerator)30 val validMigrationGenerator = arbitrary { rs: RandomSource ->31 val change = BatchMigrationChange()32 val colCount = Arb.int(1, 5).next(rs)33 val colGen = fixedColumnListNoDupsGenerator(colCount, colCount)34 change.tableName = identifierGen(1).next(rs)35 change.chunkSize = Arb.long(1L, 10000L).next(rs)36 val from = colGen.next(rs)37 val fromSet = from.toSet()38 change.fromColumns = from.toColumnList()39 // Make sure we do not have overlapping or crossing columns between from and to40 val to = colGen.filterNot { l -> fromSet.any { it in l.toSet() } }.next(rs)41 change.toColumns = to.toColumnList()42 change43 }44 val validMigrationWithSleepsGenerator = arbitrary { rs: RandomSource ->45 val mig = validMigrationGenerator.next(rs)46 mig.sleepTime = Arb.long(0L, 10000L).orNull().next(rs)47 mig48 }49 val sampleMigrationGenerator = arbitrary { rs: RandomSource ->50 val change = BatchMigrationChange()51 change.tableName = identifierGen(1).orNull().next(rs)52 change.chunkSize = Arb.long(-100L, 10000L).orNull().next(rs)53 val upperBound = Arb.int(0, 5).next(rs)54 val minBound = Arb.int(0, 5).filter { it <= upperBound }.next(rs)55 change.fromColumns = fixedColumnStringSequenceGenerator(minBound, upperBound).orNull().next(rs)56 change.toColumns = fixedColumnStringSequenceGenerator(minBound, upperBound).orNull().next(rs)57 change.sleepTime = Arb.long(-100L, 10000L).orNull().next(rs)58 change59 }60 val invalidMigrationGenerator = sampleMigrationGenerator.filter { c: BatchMigrationChange ->61 val simplePredicate = c.fromColumns.isNullOrEmpty() ||62 c.toColumns.isNullOrEmpty() || (c.chunkSize ?: -1L) <= 0L || c.sleepTime?.let { it < 0L } ?: false63 if (simplePredicate) return@filter true64 else {65 val from = c.fromColumns!!.split(",")66 val to = c.toColumns!!.split(",").toSet()67 // check whether from and to columns are equal somewhere or crossing68 // check whether any to column is in primary keys69 from.size != to.size || from.any { it in to }70 }71 }72 private fun List<String>.toColumnList(): String = joinToString(separator = ",") { it }73 private val fixedColumnListGenerator = { lowerBound: Int, inclusiveUpperBound: Int ->74 Arb.list(identifierGen(1), IntRange(lowerBound, inclusiveUpperBound))75 }76 private val fixedColumnListNoDupsGenerator = { lowerBound: Int, inclusiveUpperBound: Int ->77 fixedColumnListGenerator(lowerBound, inclusiveUpperBound).filterNot { l ->78 l.toSet().size != l.size79 }80 }81 private val fixedColumnStringSequenceGenerator = { lowerBound: Int, inclusiveUpperBound: Int ->82 fixedColumnListGenerator(lowerBound, inclusiveUpperBound).map { l -> l.joinToString(",") { it } }83 }84}...

Full Screen

Full Screen

TestCodeGenerators.kt

Source:TestCodeGenerators.kt Github

copy

Full Screen

1import io.kotest.property.Arb2import io.kotest.property.Exhaustive3import io.kotest.property.arbitrary.bind4import io.kotest.property.arbitrary.list5import io.kotest.property.arbitrary.take6import io.kotest.property.exhaustive.azstring7import io.kotest.property.exhaustive.collection8import konnekt.HeadersDeclaration9import konnekt.MimeEncodingsDeclaration10import konnekt.SourcesDeclaration11import konnekt.names12import konnekt.prelude.FormUrlEncoded13import konnekt.prelude.Multipart14fun functions(source: SourcesDeclaration): List<String> {15 val annotations = annotationVariants(source)16 return when (source) {17 SourcesDeclaration.PATH -> annotations.mapIndexed { i, annotation ->18 """|@GET("/test/{p}")19 |suspend fun test${source.name}$i($annotation r: Int): String""".trimMargin()20 }21 SourcesDeclaration.BODY, SourcesDeclaration.QUERY, SourcesDeclaration.PART, SourcesDeclaration.FIELD, SourcesDeclaration.HEADER -> annotations.mapIndexed { i, annotation ->22 """|${source.optInAnnotation()}23 |@GET("/test")24 |suspend fun test${source.name}$i($annotation r: Int): String""".trimMargin()25 }26 }27}28fun headerFunctions(): Iterable<String> {29 val annotations = headerAnnotationVariants.take(50)30 return annotations.mapIndexed { i, annotation ->31 """|@GET("/test")32 |$annotation33 |suspend fun testHEADERS_$i(): String""".trimMargin()34 }.asIterable()35}36fun mimeEncodingFunctions(encoding: MimeEncodingsDeclaration): Iterable<String> {37 val annotations = encoding.names.map { "@$it" }38 return annotations.mapIndexed { i, annotation ->39 """|$annotation40 |@GET("/test")41 |suspend fun testMIME_ENCODING_$i(): String""".trimMargin()42 }43}44private fun annotationVariants(it: SourcesDeclaration): List<String> {45 return when (it) {46 SourcesDeclaration.BODY -> it.names.map { "@$it" }47 SourcesDeclaration.PATH -> (it.names product listOf("\"p\"").named("value"))48 .let { oneArg ->49 val stringOnly = oneArg.map { (name, str) -> "@$name($str)" }50 val complete = (oneArg product booleanLiterals.named("encoded")).map { (name, str, bool) -> "@$name($str, $bool)" }51 stringOnly + complete52 }53 SourcesDeclaration.QUERY, SourcesDeclaration.FIELD -> (it.names product stringLiterals.named("value"))54 .let { oneArg ->55 val stringOnly = oneArg.map { (name, str) -> "@$name($str)" }56 val complete = (oneArg product booleanLiterals.named("encoded")).map { (name, str, bool) -> "@$name($str, $bool)" }57 stringOnly + complete58 }59 SourcesDeclaration.PART, SourcesDeclaration.HEADER -> (it.names product stringLiterals.named("value"))60 .map { (name, str) -> "@$name($str)" }61 }62}63private fun SourcesDeclaration.optInAnnotation(): String {64 val name = when (this) {65 SourcesDeclaration.PART -> Multipart::class.java.simpleName66 SourcesDeclaration.FIELD -> FormUrlEncoded::class.java.simpleName67 else -> null68 }69 return name?.let { "@$it" } ?: ""70}71private val headerAnnotationVariants = Arb.bind(72 Exhaustive.collection(HeadersDeclaration.names),73 Arb.list(Exhaustive.azstring(1..10).toArb())74) { name, args ->75 val varargs = args.joinToString(", "){ "\"$it\"" }76 "@$name($varargs)"77}78private val stringLiterals = listOf(""""p"""", "\"\"")79private val booleanLiterals = listOf("true", "false")80infix fun <T, E> List<T>.product(other: List<E>): List<Pair<T, E>> {81 return flatMap { l -> other.map { r -> l to r } }82}83@JvmName("productTriple")84infix fun <T, E, L> List<Pair<T, E>>.product(other: List<L>): List<Triple<T, E, L>> {85 return flatMap { (l1, l2) -> other.map { r -> Triple(l1, l2, r) } }86}87private fun List<String>.named(name: String): List<Argument> = flatMap {88 listOf(Argument(it, null), Argument(it, name))89}90data class Argument(val value: String, val name: String? = null) {91 override fun toString(): String =92 if (name != null) {93 "$name = $value"94 } else {95 value96 }97}...

Full Screen

Full Screen

AxisBindingTest.kt

Source:AxisBindingTest.kt Github

copy

Full Screen

1package com.eaglerobotics.lib.shuffleboard2import com.eaglerobotics.lib.shuffleboard.internal.OISubsystem3import edu.wpi.first.wpilibj.GenericHID4import edu.wpi.first.wpilibj.PS4Controller5import edu.wpi.first.wpilibj.XboxController6import edu.wpi.first.wpilibj.simulation.XboxControllerSim7import io.kotest.matchers.doubles.shouldBeExactly8import io.kotest.matchers.shouldBe9import io.kotest.property.Arb10import io.kotest.property.Exhaustive11import io.kotest.property.arbitrary.int12import io.kotest.property.checkAll13import io.kotest.property.exhaustive.enum14import io.kotest.property.exhaustive.exhaustive15class AxisBindingTest : ShuffleboardWordSpec({16 // These are lazy so that they don't get created until after HAL.initialize has been called17 val xboxController by lazy { XboxController(0) }18 val xboxControllerSim by lazy { XboxControllerSim(0) }19 val ps4Controller by lazy { PS4Controller(1) }20 val oi by lazy { OISubsystem(xboxController, ps4Controller) }21 beforeTest {22 XboxController.Axis.values().forEach {23 xboxControllerSim.setRawAxis(it.value, 0.0)24 }25 xboxControllerSim.notifyNewData()26 }27 "AxisBinding.get" should {28 "return the value of the bound axis" {29 val binding = AxisBinding(AxisActions.LEFT_DRIVE, oi, container)30 xboxControllerSim.setRawAxis(AxisActions.LEFT_DRIVE.defaultChannel, 0.5)31 xboxControllerSim.notifyNewData()32 binding.get() shouldBeExactly 0.533 }34 }35 "AxisBinding.getBoundChannelName" should {36 "return the name of XboxController axes" {37 val binding = AxisBinding(AxisActions.LEFT_DRIVE, oi, container)38 checkAll<XboxController.Axis>(Exhaustive.enum()) { axis ->39 binding.bindTo(xboxController, axis.value)40 binding.boundChannelName shouldBe "$axis"41 }42 }43 "return the name of PS4Controller axes" {44 val binding = AxisBinding(AxisActions.LEFT_DRIVE, oi, container)45 checkAll<PS4Controller.Axis>(Exhaustive.enum()) { axis ->46 binding.bindTo(ps4Controller, axis.value)47 binding.boundChannelName shouldBe "$axis"48 }49 }50 "return the channel number if not a known channel" {51 val binding = AxisBinding(AxisActions.LEFT_DRIVE, oi, container)52 checkAll(53 30,54 Arb.int(20),55 listOf(xboxController, ps4Controller, GenericHID((2))).exhaustive()56 ) { channel, controller ->57 binding.bindTo(controller, channel)58 binding.boundChannelName shouldBe "$channel"59 }60 }61 }62 "AxisBinding.getSelectedChannel" should {63 "return the id of the highest value axis" {64 val binding = AxisBinding(AxisActions.LEFT_DRIVE, oi, container)65 with(xboxControllerSim) {66 setRawAxis(1, 0.5)67 setRawAxis(2, -1.0)68 setRawAxis(3, 0.2)69 notifyNewData()70 }71 binding.getSelectedChannel(xboxController) shouldBe 272 }73 "return null if no axis is above the deadband" {74 val binding = AxisBinding(AxisActions.LEFT_DRIVE, oi, container)75 with(xboxControllerSim) {76 setRawAxis(1, -0.2)77 setRawAxis(2, 0.0)78 setRawAxis(3, 0.2)79 notifyNewData()80 }81 binding.getSelectedChannel(xboxController) shouldBe null82 }83 }84})...

Full Screen

Full Screen

ButtonBindingTest.kt

Source:ButtonBindingTest.kt Github

copy

Full Screen

1package com.eaglerobotics.lib.shuffleboard2import com.eaglerobotics.lib.shuffleboard.internal.OISubsystem3import edu.wpi.first.wpilibj.GenericHID4import edu.wpi.first.wpilibj.PS4Controller5import edu.wpi.first.wpilibj.XboxController6import edu.wpi.first.wpilibj.simulation.XboxControllerSim7import io.kotest.matchers.shouldBe8import io.kotest.property.Arb9import io.kotest.property.Exhaustive10import io.kotest.property.arbitrary.int11import io.kotest.property.checkAll12import io.kotest.property.exhaustive.enum13import io.kotest.property.exhaustive.exhaustive14class ButtonBindingTest : ShuffleboardWordSpec({15 // These are lazy so that they don't get created until after HAL.initialize has been called16 val xboxController by lazy { XboxController(0) }17 val xboxControllerSim by lazy { XboxControllerSim(0) }18 val ps4Controller by lazy { PS4Controller(1) }19 val oi by lazy { OISubsystem(xboxController, ps4Controller) }20 beforeTest {21 XboxController.Button.values().forEach {22 xboxControllerSim.setRawButton(it.value, false)23 }24 xboxControllerSim.notifyNewData()25 }26 "ButtonBinding.get" should {27 "return the value of the bound axis" {28 val binding = ButtonBinding(ButtonActions.SHOOT, oi, container)29 xboxControllerSim.setRawButton(ButtonActions.SHOOT.defaultChannel, true)30 xboxControllerSim.notifyNewData()31 binding.get() shouldBe true32 }33 }34 "ButtonBinding.getBoundChannelName" should {35 "return the name of XboxController axes" {36 val binding = ButtonBinding(ButtonActions.SHOOT, oi, container)37 checkAll<XboxController.Button>(Exhaustive.enum()) { axis ->38 binding.bindTo(xboxController, axis.value)39 binding.boundChannelName shouldBe "$axis"40 }41 }42 "return the name of PS4Controller axes" {43 val binding = ButtonBinding(ButtonActions.SHOOT, oi, container)44 checkAll<PS4Controller.Button>(Exhaustive.enum()) { axis ->45 binding.bindTo(ps4Controller, axis.value)46 binding.boundChannelName shouldBe "$axis"47 }48 }49 "return the channel number if not a known channel" {50 val binding = ButtonBinding(ButtonActions.SHOOT, oi, container)51 checkAll(52 30,53 Arb.int(20),54 listOf(xboxController, ps4Controller, GenericHID((2))).exhaustive()55 ) { channel, controller ->56 binding.bindTo(controller, channel)57 binding.boundChannelName shouldBe "$channel"58 }59 }60 }61 "ButtonBinding.getSelectedChannel" should {62 "return the highest id pressed button" {63 val binding = ButtonBinding(ButtonActions.SHOOT, oi, container)64 with(xboxControllerSim) {65 setRawButton(1, true)66 setRawButton(2, false)67 setRawButton(4, true)68 notifyNewData()69 }70 binding.getSelectedChannel(xboxController) shouldBe 471 }72 "return null if no buttons are pressed" {73 val binding = ButtonBinding(ButtonActions.SHOOT, oi, container)74 with(xboxControllerSim) {75 setRawButton(1, false)76 setRawButton(2, false)77 setRawButton(4, false)78 notifyNewData()79 }80 binding.getSelectedChannel(xboxController) shouldBe null81 }82 }83})...

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

GeneratorTests.kt

Source:GeneratorTests.kt Github

copy

Full Screen

1package test.kotest.propertyTest2import io.kotest.core.spec.style.StringSpec3import io.kotest.property.Arb4import io.kotest.property.Exhaustive5import io.kotest.property.RandomSource6import io.kotest.property.arbitrary.*7import io.kotest.property.exhaustive.enum8import io.kotest.property.exhaustive.exhaustive9import io.kotest.property.exhaustive.ints10import io.kotest.property.forAll11import java.time.LocalDateTime12enum class Season { Winter, Fall, Spring, Summer }13data class Person(val name: String, val age: Int)14class GeneratorTests : StringSpec({15 //根据类型自动选择合适的generator16 "use forAll" {17 forAll<Int, Double, Boolean, String, LocalDateTime, Season>(10) { a, b, c, d, e, f ->18 println("$a $b $c $d $e $f")19 true20 }21 }22 //使用底层生成器Arbitrary 无限随机生成器23 "use generator" {24 Arb.int(1, 200).take(10).toList().run(::println)25 Arb.intArray(Arb.int(2, 8), Arb.int(200..400)).take(10).map { it.toList() }.toList().run(::println)26 Arb.char('a'..'z').take(10).toList().run(::println)27 Arb.stringPattern("\\w+[0-9]").take(10).toList().run(::println)28 Arb.list(Arb.int(), 1..5).take(10).toList().run(::println)29 }30 //使用有限生成器 Exhaustive31 "use exhaustive" {32 Exhaustive.enum<Season>().values.run(::println)33 Exhaustive.ints(1..10).values.run(::println)34 }35 //使用组合生成器36 "use complex operation" {37 Arb.choice(Arb.int(1..10), Arb.double(20.0..50.0)).take(10).toList().run(::println)38 Arb.bind(Arb.string(), Arb.int()) { name, age ->39 Person(name, age).run(::println)40 }41 Arb.choose(1 to Arb.int(1, 10), 2 to Arb.double(1.0, 5.0)).take(10).toList().run(::println)42 Arb.shuffle(listOf(1, 2, 3, 4, 5, 6)).take(10).toList().run(::println)43 Arb.subsequence(listOf(1, 2, 3, 4, 5, 6)).take(10).toList().run(::println)44 }45 //自定义生成器46 "custom generator" {47 val arb = arbitrary { rs: RandomSource ->48 rs.random.nextInt(1, 20)49 }50 arb.take(10).toList().run(::println)51 val personArb = arbitrary {52 val name = Arb.string(10..12).bind()53 val age = Arb.int(21..150).bind()54 Person(name, age)55 }56 personArb.take(10).toList().run(::println)57 val singleDigitPrimes = listOf(2, 3, 5, 7).exhaustive()58 singleDigitPrimes.values.run(::println)59 }60})...

Full Screen

Full Screen

option.kt

Source:option.kt Github

copy

Full Screen

1package io.kotest.property.arrow2import arrow.core.None3import arrow.core.Option4import arrow.core.Some5import arrow.core.some6import io.kotest.property.Arb7import io.kotest.property.Exhaustive8import io.kotest.property.arbitrary.constant9import io.kotest.property.arbitrary.map10import io.kotest.property.arbitrary.merge11import io.kotest.property.exhaustive.exhaustive12/**13 * Returns an Exhaustive that contains a None and a Some with the given value14 */15fun <A> Exhaustive.Companion.option(a: A) = exhaustive(listOf(None, Some(a)))16fun <A> Exhaustive.Companion.none() = exhaustive(listOf(None))17/**18 * Wraps each element generated by the given Arb in a Some.19 */20fun <A> Arb.Companion.some(arb: Arb<A>): Arb<Option<A>> = arb.map { it.some() }21fun <A> Arb.Companion.none(): Arb<Option<A>> = Arb.constant(None)22fun <A> Arb.Companion.option(arb: Arb<A>): Arb<Option<A>> = some(arb).merge(none())...

Full Screen

Full Screen

List.exhaustive

Using AI Code Generation

copy

Full Screen

1val list = List.exhaustive(1, 2, 3, 4, 5)2list.forEach { println(it) }3val list = List.exhaustive(1, 2, 3, 4, 5)4list.forEach { println(it) }5val list = List.exhaustive(1, 2, 3, 4, 5)6list.forEach { println(it) }7val list = List.exhaustive(1, 2, 3, 4, 5)8list.forEach { println(it) }9val list = List.exhaustive(1, 2, 3, 4, 5)10list.forEach { println(it) }11val list = List.exhaustive(1, 2, 3, 4, 5)12list.forEach { println(it) }13val list = List.exhaustive(1, 2, 3, 4, 5)14list.forEach { println(it) }15val list = List.exhaustive(1, 2, 3, 4, 5)16list.forEach { println(it) }17val list = List.exhaustive(1, 2, 3, 4, 5)18list.forEach { println(it) }19val list = List.exhaustive(1, 2, 3, 4, 5)20list.forEach { println(it) }

Full Screen

Full Screen

List.exhaustive

Using AI Code Generation

copy

Full Screen

1val list = List . exhaustive ( 1 , 2 , 3 )2val list = List . exhaustive ( 1 , 2 , 3 )3val list = List . exhaustive ( 1 , 2 , 3 )4val list = List . exhaustive ( 1 , 2 , 3 )5val list = List . exhaustive ( 1 , 2 , 3 )6val list = List . exhaustive ( 1 , 2 , 3 )7val list = List . exhaustive ( 1 , 2 , 3 )8val list = List . exhaustive ( 1 , 2 , 3 )9val list = List . exhaustive ( 1 , 2 , 3 )10val list = List . exhaustive ( 1 , 2 , 3 )11val list = List . exhaustive ( 1

Full Screen

Full Screen

List.exhaustive

Using AI Code Generation

copy

Full Screen

1val stringList = listOf("a", "b", "c")2val listExhaustive = stringList.exhaustive()3val someList = listOf("a", "b", "c")4val someOtherList = listOf("a", "b", "c")5val someMoreList = listOf("a", "b", "c")6val listOfLists = listOf(someList, someOtherList, someMoreList)7val listOfListsExhaustive = listOfLists.exhaustive()8val map = mapOf("a" to 1, "b" to 2, "c" to 3)9val mapExhaustive = map.exhaustive()10val someMap = mapOf("a" to 1, "b" to 2, "c" to 3)11val someOtherMap = mapOf("a" to 1, "b" to 2, "c" to 3)12val someMoreMap = mapOf("a" to 1, "b" to 2, "c" to 3)13val listOfMaps = listOf(someMap, someOtherMap, someMoreMap)14val listOfMapsExhaustive = listOfMaps.exhaustive()15val set = setOf("a", "b", "c")16val setExhaustive = set.exhaustive()17val someSet = setOf("a", "b", "c")18val someOtherSet = setOf("a", "b", "c")19val someMoreSet = setOf("a", "b", "c")20val listOfSets = listOf(someSet, someOtherSet, someMoreSet)21val listOfSetsExhaustive = listOfSets.exhaustive()22val someArray = arrayOf("a", "b", "c")23val someOtherArray = arrayOf("a", "b", "c")24val someMoreArray = arrayOf("a", "b", "c")25val arrayOfArrays = arrayOf(someArray, someOtherArray, someMoreArray)26val arrayOfArraysExhaustive = arrayOfArrays.exhaustive()27val someSequence = sequenceOf("a", "b", "c")28val someOtherSequence = sequenceOf("a", "b", "c")29val someMoreSequence = sequenceOf("a", "b", "c")30val sequenceOfSequences = sequenceOf(someSequence, someOtherSequence, someMoreSequence)

Full Screen

Full Screen

List.exhaustive

Using AI Code Generation

copy

Full Screen

1val result = propertyTest(100, List.exhaustive(1..100)) {2}3val result = propertyTest(100, List.exhaustive(1..100)) {4}5val result = propertyTest(100, List.exhaustive(1..100)) {6}7val result = propertyTest(100, List.exhaustive(1..100)) {8}9val result = propertyTest(100, List.exhaustive(1..100)) {10}11val result = propertyTest(100, List.exhaustive(1..100)) {12}13val result = propertyTest(100, List.exhaustive(1..100)) {14}15val result = propertyTest(100, List.exhaustive(1..100)) {16}17val result = propertyTest(100, List.exhaustive(1..100)) {18}19val result = propertyTest(100, List.exhaustive(1..100)) {20}21val result = propertyTest(100, List.exhaustive(1..100)) {22}

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