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

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

GenHelper.kt

Source:GenHelper.kt Github

copy

Full Screen

...33import io.kotest.property.arbitrary.localDate34import io.kotest.property.arbitrary.localDateTime35import io.kotest.property.arbitrary.localTime36import io.kotest.property.arbitrary.long37import io.kotest.property.arbitrary.map38import io.kotest.property.arbitrary.next39import io.kotest.property.arbitrary.period40import io.kotest.property.arbitrary.short41import io.kotest.property.arbitrary.string42import io.kotest.property.arbitrary.uuid43import io.kotest.property.exhaustive.exhaustive44import java.net.URI45fun Arb.Companion.suspendFunThatReturnsEitherAnyOrAnyOrThrows(): Arb<suspend () -> Either<Any, Any>> =46 choice(47 suspendFunThatReturnsAnyRight(),48 suspendFunThatReturnsAnyLeft(),49 suspendFunThatThrows()50 )51fun Arb.Companion.suspendFunThatReturnsEitherAnyOrUnitOrThrows(): Arb<suspend () -> Either<Any, Unit>> =52 choice(53 suspendFunThatReturnsUnitRight() as Arb<suspend () -> Either<Any, Unit>>,54 suspendFunThatReturnsAnyLeft() as Arb<suspend () -> Either<Any, Unit>>,55 suspendFunThatThrows() as Arb<suspend () -> Either<Any, Unit>>56 )57fun Arb.Companion.suspendFunThatReturnsUnitRight(): Arb<suspend () -> Either<Any, Unit>> =58 unit().map { suspend { it.right() } }59fun Arb.Companion.suspendFunThatReturnsAnyRight(): Arb<suspend () -> Either<Any, Any>> =60 any().map { suspend { it.right() } }61fun Arb.Companion.suspendFunThatReturnsAnyLeft(): Arb<suspend () -> Either<Any, Any>> =62 any().map { suspend { it.left() } }63fun Arb.Companion.suspendFunThatThrows(): Arb<suspend () -> Either<Any, Any>> =64 throwable().map { suspend { throw it } } as Arb<suspend () -> Either<Any, Any>>65fun Arb.Companion.suspendFunThatThrowsFatalThrowable(): Arb<suspend () -> Either<Any, Any>> =66 fatalThrowable().map { suspend { throw it } } as Arb<suspend () -> Either<Any, Any>>67fun Arb.Companion.throwable(): Arb<Throwable> =68 element(69 Exception(),70 RuntimeException(),71 IllegalArgumentException(),72 IllegalStateException(),73 IndexOutOfBoundsException(),74 UnsupportedOperationException(),75 ArithmeticException(),76 NumberFormatException(),77 NullPointerException(),78 ClassCastException(),79 AssertionError(),80 NoSuchElementException(),81 ConcurrentModificationException()82 )83fun Arb.Companion.fatalThrowable(): Arb<Throwable> =84 element(85 MyVirtualMachineError(),86 ThreadDeath(),87 InterruptedException(),88 LinkageError()89 )90class MyVirtualMachineError : VirtualMachineError()91fun Arb.Companion.any(): Arb<Any> =92 choice(93 string() as Arb<Any>,94 int() as Arb<Any>,95 short() as Arb<Any>,96 long() as Arb<Any>,97 float() as Arb<Any>,98 double() as Arb<Any>,99 bool() as Arb<Any>,100 byte() as Arb<Any>,101 uuid() as Arb<Any>,102 file() as Arb<Any>,103 localDate() as Arb<Any>,104 localTime() as Arb<Any>,105 localDateTime() as Arb<Any>,106 period() as Arb<Any>,107 throwable() as Arb<Any>,108 fatalThrowable() as Arb<Any>,109 mapOfStringAndStringGenerator() as Arb<Any>,110 uri() as Arb<Any>,111 httpMethod() as Arb<Any>,112 unit() as Arb<Any>113 )114fun Arb.Companion.unit(): Arb<Unit> =115 create { Unit }116fun Arb.Companion.mapOfStringAndStringGenerator(): Arb<Map<String, String>> =117 element(118 listOf(119 emptyMap(),120 mapOf(121 string().next() to string().next()122 ),123 mapOf(124 string().next() to string().next(),125 string().next() to string().next()126 ),127 mapOf(128 string().next() to string().next(),129 string().next() to string().next(),130 string().next() to string().next()131 ),132 mapOf(133 string().next() to string().next(),134 string().next() to string().next(),135 string().next() to string().next(),136 string().next() to string().next(),137 string().next() to string().next(),138 string().next() to string().next()139 ),140 mapOf(141 string().next() to string().next(),142 string().next() to string().next(),143 string().next() to string().next(),144 string().next() to string().next(),145 string().next() to string().next(),146 string().next() to string().next(),147 string().next() to string().next(),148 string().next() to string().next(),149 string().next() to string().next(),150 string().next() to string().next(),151 string().next() to string().next(),152 string().next() to string().next()153 ),154 mapOf(155 string().next() to string().next(),156 string().next() to string().next(),157 string().next() to string().next(),158 string().next() to string().next(),159 string().next() to string().next(),160 string().next() to string().next(),161 string().next() to string().next(),162 string().next() to string().next(),163 string().next() to string().next(),164 string().next() to string().next(),165 string().next() to string().next(),166 string().next() to string().next(),167 string().next() to string().next(),168 string().next() to string().next(),...

Full Screen

Full Screen

Generators.kt

Source:Generators.kt Github

copy

Full Screen

...25import io.kotest.property.arbitrary.filter26import io.kotest.property.arbitrary.flatMap27import io.kotest.property.arbitrary.int28import io.kotest.property.arbitrary.long29import io.kotest.property.arbitrary.map30import io.kotest.property.arbitrary.numericDoubles31import io.kotest.property.arbitrary.numericFloats32import io.kotest.property.arbitrary.of33import io.kotest.property.arbitrary.orNull34import io.kotest.property.arbitrary.short35import io.kotest.property.arbitrary.string36import kotlin.Result.Companion.failure37import kotlin.Result.Companion.success38import kotlin.math.abs39public fun <A, B> Arb.Companion.functionAToB(arb: Arb<B>): Arb<(A) -> B> =40 arb.map { b: B -> { _: A -> b } }41public fun <A> Arb.Companion.functionAAToA(arb: Arb<A>): Arb<(A, A) -> A> =42 arb.map { a: A -> { _: A, _: A -> a } }43public fun <A, B> Arb.Companion.functionBAToB(arb: Arb<B>): Arb<(B, A) -> B> =44 arb.map { b: B -> { _: B, _: A -> b } }45public fun <A, B> Arb.Companion.functionABToB(arb: Arb<B>): Arb<(A, B) -> B> =46 arb.map { b: B -> { _: A, _: B -> b } }47public fun <A> Arb.Companion.functionToA(arb: Arb<A>): Arb<() -> A> =48 arb.map { a: A -> { a } }49public fun Arb.Companion.throwable(): Arb<Throwable> =50 Arb.of(listOf(RuntimeException(), NoSuchElementException(), IllegalArgumentException()))51public fun <A> Arb.Companion.result(arbA: Arb<A>): Arb<Result<A>> =52 Arb.choice(arbA.map(::success), throwable().map(::failure))53public fun Arb.Companion.doubleSmall(): Arb<Double> =54 Arb.numericDoubles(from = 0.0, to = 100.0)55public fun Arb.Companion.floatSmall(): Arb<Float> =56 Arb.numericFloats(from = 0F, to = 100F)57public fun Arb.Companion.intSmall(factor: Int = 10000): Arb<Int> =58 Arb.int((Int.MIN_VALUE / factor)..(Int.MAX_VALUE / factor))59public fun Arb.Companion.byteSmall(): Arb<Byte> =60 Arb.byte(min = (Byte.MIN_VALUE / 10).toByte(), max = (Byte.MAX_VALUE / 10).toByte())61public fun Arb.Companion.shortSmall(): Arb<Short> {62 val range = (Short.MIN_VALUE / 1000)..(Short.MAX_VALUE / 1000)63 return Arb.short().filter { it in range }64}65public fun Arb.Companion.longSmall(): Arb<Long> =66 Arb.long((Long.MIN_VALUE / 100000L)..(Long.MAX_VALUE / 100000L))67public fun <A, B, C, D> Arb.Companion.tuple4(arbA: Arb<A>, arbB: Arb<B>, arbC: Arb<C>, arbD: Arb<D>): Arb<Tuple4<A, B, C, D>> =68 Arb.bind(arbA, arbB, arbC, arbD, ::Tuple4)69public fun <A, B, C, D, E> Arb.Companion.tuple5(70 arbA: Arb<A>,71 arbB: Arb<B>,72 arbC: Arb<C>,73 arbD: Arb<D>,74 arbE: Arb<E>75): Arb<Tuple5<A, B, C, D, E>> =76 Arb.bind(arbA, arbB, arbC, arbD, arbE, ::Tuple5)77public fun <A, B, C, D, E, F> Arb.Companion.tuple6(78 arbA: Arb<A>,79 arbB: Arb<B>,80 arbC: Arb<C>,81 arbD: Arb<D>,82 arbE: Arb<E>,83 arbF: Arb<F>84): Arb<Tuple6<A, B, C, D, E, F>> =85 Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, ::Tuple6)86public fun <A, B, C, D, E, F, G> Arb.Companion.tuple7(87 arbA: Arb<A>,88 arbB: Arb<B>,89 arbC: Arb<C>,90 arbD: Arb<D>,91 arbE: Arb<E>,92 arbF: Arb<F>,93 arbG: Arb<G>94): Arb<Tuple7<A, B, C, D, E, F, G>> =95 Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG, ::Tuple7)96public fun <A, B, C, D, E, F, G, H> Arb.Companion.tuple8(97 arbA: Arb<A>,98 arbB: Arb<B>,99 arbC: Arb<C>,100 arbD: Arb<D>,101 arbE: Arb<E>,102 arbF: Arb<F>,103 arbG: Arb<G>,104 arbH: Arb<H>105): Arb<Tuple8<A, B, C, D, E, F, G, H>> =106 Arb.bind(107 Arb.tuple7(arbA, arbB, arbC, arbD, arbE, arbF, arbG),108 arbH109 ) { (a, b, c, d, e, f, g), h ->110 Tuple8(a, b, c, d, e, f, g, h)111 }112public fun <A, B, C, D, E, F, G, H, I> Arb.Companion.tuple9(113 arbA: Arb<A>,114 arbB: Arb<B>,115 arbC: Arb<C>,116 arbD: Arb<D>,117 arbE: Arb<E>,118 arbF: Arb<F>,119 arbG: Arb<G>,120 arbH: Arb<H>,121 arbI: Arb<I>122): Arb<Tuple9<A, B, C, D, E, F, G, H, I>> =123 Arb.bind(124 Arb.tuple8(arbA, arbB, arbC, arbD, arbE, arbF, arbG, arbH),125 arbI126 ) { (a, b, c, d, e, f, g, h), i ->127 Tuple9(a, b, c, d, e, f, g, h, i)128 }129public fun <A, B, C, D, E, F, G, H, I, J> Arb.Companion.tuple10(130 arbA: Arb<A>,131 arbB: Arb<B>,132 arbC: Arb<C>,133 arbD: Arb<D>,134 arbE: Arb<E>,135 arbF: Arb<F>,136 arbG: Arb<G>,137 arbH: Arb<H>,138 arbI: Arb<I>,139 arbJ: Arb<J>140): Arb<Tuple10<A, B, C, D, E, F, G, H, I, J>> =141 Arb.bind(142 Arb.tuple9(arbA, arbB, arbC, arbD, arbE, arbF, arbG, arbH, arbI),143 arbJ144 ) { (a, b, c, d, e, f, g, h, i), j ->145 Tuple10(a, b, c, d, e, f, g, h, i, j)146 }147public fun Arb.Companion.nonZeroInt(): Arb<Int> = Arb.int().filter { it != 0 }148public fun Arb.Companion.intPredicate(): Arb<(Int) -> Boolean> =149 Arb.nonZeroInt().flatMap { num ->150 val absNum = abs(num)151 Arb.of(152 listOf<(Int) -> Boolean>(153 { it > num },154 { it <= num },155 { it % absNum == 0 },156 { it % absNum == absNum - 1 }157 )158 )159 }160public fun <A> Arb.Companion.endo(arb: Arb<A>): Arb<Endo<A>> = arb.map { a: A -> Endo<A> { a } }161public fun <B> Arb.Companion.option(arb: Arb<B>): Arb<Option<B>> =162 arb.orNull().map { it.toOption() }163public fun <E, A> Arb.Companion.either(arbE: Arb<E>, arbA: Arb<A>): Arb<Either<E, A>> {164 val arbLeft = arbE.map { Either.Left(it) }165 val arbRight = arbA.map { Either.Right(it) }166 return Arb.choice(arbLeft, arbRight)167}168public fun <E, A> Arb<E>.or(arbA: Arb<A>): Arb<Either<E, A>> = Arb.either(this, arbA)169public fun <E, A> Arb.Companion.validated(arbE: Arb<E>, arbA: Arb<A>): Arb<Validated<E, A>> =170 Arb.either(arbE, arbA).map { Validated.fromEither(it) }171public fun Arb.Companion.unit(): Arb<Unit> =172 Arb.constant(Unit)173public fun <A, B> Arb.Companion.ior(arbA: Arb<A>, arbB: Arb<B>): Arb<Ior<A, B>> =174 arbA.alignWith(arbB) { it }175public fun <A, B> Arb.Companion.arbConst(arb: Arb<A>): Arb<Const<A, B>> =176 arb.map { Const<A, B>(it) }177public fun <A> Arb<A>.eval(): Arb<Eval<A>> =178 map { Eval.now(it) }179private fun <A, B, R> Arb<A>.alignWith(arbB: Arb<B>, transform: (Ior<A, B>) -> R): Arb<R> =180 Arb.bind(this, arbB) { a, b -> transform(Ior.Both(a, b)) }181public fun Arb.Companion.suspendFunThatReturnsEitherAnyOrAnyOrThrows(): Arb<suspend () -> Either<Any, Any>> =182 choice(183 suspendFunThatReturnsAnyRight(),184 suspendFunThatReturnsAnyLeft(),185 suspendFunThatThrows()186 )187public fun Arb.Companion.suspendFunThatReturnsAnyRight(): Arb<suspend () -> Either<Any, Any>> =188 any().map { suspend { it.right() } }189public fun Arb.Companion.suspendFunThatReturnsAnyLeft(): Arb<suspend () -> Either<Any, Any>> =190 any().map { suspend { it.left() } }191public fun Arb.Companion.suspendFunThatThrows(): Arb<suspend () -> Either<Any, Any>> =192 throwable().map { suspend { throw it } } as Arb<suspend () -> Either<Any, Any>>193public fun Arb.Companion.any(): Arb<Any> =194 choice(195 Arb.string() as Arb<Any>,196 Arb.int() as Arb<Any>,197 Arb.long() as Arb<Any>,198 Arb.boolean() as Arb<Any>,199 Arb.throwable() as Arb<Any>,200 Arb.unit() as Arb<Any>201 )...

Full Screen

Full Screen

RoomsKtTest.kt

Source:RoomsKtTest.kt Github

copy

Full Screen

...13import io.kotest.property.arbitrary.enum14import io.kotest.property.arbitrary.set15import io.kotest.property.checkAll16import io.kotest.property.exhaustive.ints17import io.kotest.property.exhaustive.map18import io.kotest.property.forAll19import org.jetbrains.exposed.sql.insert20import org.jetbrains.exposed.sql.select21import org.jetbrains.exposed.sql.selectAll22import org.jetbrains.exposed.sql.transactions.transaction23import kotlin.random.nextInt24val directionSets = Arb.set(Arb.enum<Direction>(), 0..Direction.values().size)25val rotations = Exhaustive.ints(0..3).map { it.toShort() }26val invalidRotationValues = (Short.MIN_VALUE..Short.MAX_VALUE) - (0..3)27val invalidRotations = arbitrary(listOf(Short.MIN_VALUE, -1, 4, Short.MAX_VALUE), ShortShrinker) {28 it.random.nextInt(invalidRotationValues.indices).let { i -> invalidRotationValues[i] }.toShort()29}30class RoomsKtTest : DescribeSpec({31 useDatabase()32 describe("returnRoomToStack") {33 it("returns to empty stack") {34 transaction {35 val gameId = "ABCDEF"36 val stackId =37 RoomStacks.insert {38 it[this.gameId] = gameId39 it[curIndex] = null40 it[flipped] = false41 } get RoomStacks.id42 val roomId =43 Rooms.insert {44 it[this.gameId] = gameId45 it[roomDefId] = 1446 it[gridX] = 047 it[gridY] = 048 it[rotation] = 049 } get Rooms.id50 returnRoomToStack(gameId, roomId)51 Rooms.selectAll().shouldBeEmpty()52 val stackRows = RoomStacks.select { RoomStacks.id eq stackId }53 stackRows.count().shouldBe(1)54 stackRows.first().should {55 it[RoomStacks.curIndex].shouldBe(0)56 }57 RoomStackContents.select { RoomStackContents.stackId eq stackId }58 .first().should {59 it[RoomStackContents.index].shouldBe(0)60 it[RoomStackContents.roomDefId].shouldBe(14)61 }62 }63 }64 it("returns to non-empty stack") {65 transaction {66 val gameId = "ABCDEF"67 val stackId = RoomStacks.insert {68 it[this.gameId] = gameId69 it[curIndex] = 1770 it[flipped] = false71 } get RoomStacks.id72 RoomStackContents.insert {73 it[this.stackId] = stackId74 it[index] = 2575 it[roomDefId] = 976 }77 RoomStackContents.insert {78 it[this.stackId] = stackId79 it[index] = 1780 it[roomDefId] = 1381 }82 RoomStackContents.insert {83 it[this.stackId] = stackId84 it[index] = 385 it[roomDefId] = 2386 }87 val roomId = Rooms.insert {88 it[this.gameId] = gameId89 it[roomDefId] = 1490 it[gridX] = 091 it[gridY] = 092 it[rotation] = 093 } get Rooms.id94 returnRoomToStack(gameId, roomId)95 Rooms.selectAll().shouldBeEmpty()96 RoomStackContents.selectAll()97 .map { it[RoomStackContents.index] }98 .shouldContainExactlyInAnyOrder(0, 1, 2, 3)99 }100 }101 }102 describe("rotateDoors") {103 it("maintains number of directions") {104 forAll(directionSets, rotations) { dirs, rotation ->105 rotateDoors(dirs, rotation).size == dirs.size106 }107 }108 it("throws for invalid rotations") {109 checkAll(directionSets, invalidRotations) { dirs, rotation ->110 shouldThrow<IllegalArgumentException> { rotateDoors(dirs, rotation) }111 }...

Full Screen

Full Screen

TestCodeGenerators.kt

Source:TestCodeGenerators.kt Github

copy

Full Screen

...13import 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

TestUtil.kt

Source:TestUtil.kt Github

copy

Full Screen

...10import io.kotest.property.arbitrary.choice11import io.kotest.property.arbitrary.constant12import io.kotest.property.arbitrary.double13import io.kotest.property.arbitrary.int14import io.kotest.property.arbitrary.map15import io.kotest.property.arbitrary.string16fun convertToString(expected: String) = object : Matcher<RObject> {17 override fun test(value: RObject) =18 MatcherResult(19 value.toString() == expected,20 "Object $value should convert to string $expected",21 "Object $value should not convert to string $expected"22 )23}24infix fun RObject.shouldConvertToString(expected: String) = this should convertToString(expected)25fun <T> succeedWith(expected: T) = object : Matcher<Result<T>> {26 override fun test(value: Result<T>) =27 MatcherResult(28 value is Result.Success && value.obj == expected,29 "Result $value should be successful with value $expected",30 "Result $value should not be successful with value $expected"31 )32}33infix fun <T> Result<T>.shouldSucceedWith(expected: T) = this should succeedWith(expected)34fun <T> Result<T>.shouldError() = this should beOfType<Result.Error>()35fun <T> errorWith(expected: String) = object : Matcher<Result<T>> {36 override fun test(value: Result<T>) =37 MatcherResult(38 value is Result.Error && value.reason == expected,39 "Result $value should be error with reason $expected",40 "Result $value should not be error with reason $expected"41 )42}43infix fun <T> Result<T>.shouldErrorWith(reason: String) = this should errorWith(reason)44val rapiraEmptyArb = Arb.constant(Empty)45val rapiraFunctionArb = arbitrary { Function() }46val rapiraIntegerArb = Arb.int().map { num -> num.toRInteger() }47val rapiraLogicalArb = Arb.bool().map { bool -> Logical(bool) }48val rapiraProcedureArb = arbitrary { Procedure() }49val rapiraRealArb = Arb.double().map { double -> Real(double) }50val rapiraTextArb = Arb.string().map { str -> str.toText() }51val rapiraObjectArb = Arb.choice(52 rapiraEmptyArb,53 rapiraFunctionArb,54 rapiraIntegerArb,55 rapiraLogicalArb,56 rapiraProcedureArb,57 rapiraRealArb,58 rapiraTextArb59)...

Full Screen

Full Screen

identifierGenerator.kt

Source:identifierGenerator.kt Github

copy

Full Screen

...18import io.kotest.property.RandomSource19import io.kotest.property.Sample20import io.kotest.property.arbitrary.Codepoint21import io.kotest.property.arbitrary.element22import io.kotest.property.arbitrary.map23import io.kotest.property.arbitrary.string24import kotlinx.collections.immutable.PersistentList25import kotlinx.collections.immutable.toPersistentList26internal fun Arb.Companion.semVerIdentifier(minParts: Int = 1, maxParts: Int): Arb<Pair<PersistentList<Identifier>, String>> =27 object : Arb<Pair<PersistentList<Identifier>, String>>() {28 override fun edgecase(rs: RandomSource): Pair<PersistentList<Identifier>, String>? = null29 override fun sample(rs: RandomSource): Sample<Pair<PersistentList<Identifier>, String>> {30 // I don't really know what a sensible maxSize would be, even 100 feels a bit large for a semver identifier31 // the system should be able to handle identifiers of any size (as long as the final string isn't larger32 // than what is supported by the JVM)33 val stringArb = Arb.string(minSize = 1, maxSize = 100, codepoints = Codepoint.semVerIdentifier())34 val sequenceSize = rs.random.nextInt(minParts, maxParts + 1)35 val identifiers = stringArb.samples(rs)36 .take(sequenceSize)37 .map { it.value }38 .map { Identifier.of(it) }39 .toPersistentList()40 val identifierTextSequence = identifiers.joinToString(separator = ".")41 return Sample(identifiers to identifierTextSequence)42 }43 }44internal fun Codepoint.Companion.semVerIdentifier(): Arb<Codepoint> =45 Arb.element((('a'..'z') + ('A'..'Z') + ('0'..'9') + '-').toList()).map { Codepoint(it.code) }...

Full Screen

Full Screen

ApplicativeTest.kt

Source:ApplicativeTest.kt Github

copy

Full Screen

...32})33val nelArb = Arb.list(Arb.int(), 1..1000)34fun <F, A> leftIdLaw(ap: Applicative<F>, fa: Kind<F, A>): Boolean =35 ap.run {36 map2(unit { }, fa) { _, a -> a } == fa37 }38fun <F, A> rightIdLaw(ap: Applicative<F>, fa: Kind<F, A>): Boolean =39 ap.run {40 map2(fa, unit { }) { a, _ -> a } == fa41 }42fun <A, B, C> assoc(p: Pair<A, Pair<B, C>>): Pair<Pair<A, B>, C> = (p.first to p.second.first) to p.second.second43fun <F, A, B, C> assocLaw(ap: Applicative<F>, fa: Kind<F, A>, fb: Kind<F, B>, fc: Kind<F, C>): Boolean =44 ap.run {45 product(product(fa, fb), fc) == product(fa, product(fb, fc)).map { assoc(it) }46 }47fun <I, O, I2, O2> productF(f: (I) -> O, g: (I2) -> O2): (I, I2) -> Pair<O, O2> = { i, i2 -> f(i) to g(i2) }48fun <F, A, B, C, D> naturalityLaw(ap: Applicative<F>, fa: Kind<F, A>, fb: Kind<F, B>, f: (A) -> C, g: (B) -> D): Boolean =49 ap.run {50 map2(fa, fb) { a, b -> productF(f, g)(a, b) } == product(fa.map(f), fb.map(g))51 }

Full Screen

Full Screen

ResponseError.kt

Source:ResponseError.kt Github

copy

Full Screen

1package uk.co.appsplus.bootstrap.testing.arbs.ext2import com.squareup.moshi.Moshi3import io.kotest.property.Arb4import io.kotest.property.arbitrary.list5import io.kotest.property.arbitrary.map6import io.kotest.property.arbitrary.string7import uk.co.appsplus.bootstrap.network.models.ResponseError8fun Arb.Companion.domainError(): Arb<ResponseError> {9 return Arb10 .map(Arb.string(), Arb.list(Arb.string(), range = 1..3), minSize = 0, maxSize = 2)11 .map { ResponseError(it) }12}13fun ResponseError.toJson(): String {14 return Moshi.Builder().build().adapter(ResponseError::class.java).toJson(this)15}16fun Arb.Companion.domainErrorJson(): Arb<String> {17 return domainError()18 .map {19 it.toJson()20 }21}...

Full Screen

Full Screen

map

Using AI Code Generation

copy

Full Screen

1val mapArb = Arb.map(Arb.int(), Arb.string())2val setArb = Arb.set(Arb.int())3val sortedMapArb = Arb.sortedMap(Arb.int(), Arb.string())4val sortedSetArb = Arb.sortedSet(Arb.int())5val stringArb = Arb.string()6val stringPrintableArb = Arb.stringPrintable()7val stringPrintableASCIIArb = Arb.stringPrintableASCII()8val stringPrintableASCIIWithSpacesArb = Arb.stringPrintableASCIIWithSpaces()9val stringPrintableWithSpacesArb = Arb.stringPrintableWithSpaces()10val stringPrintableWithSpacesAndNewLinesArb = Arb.stringPrintableWithSpacesAndNewLines()11val stringPrintableWithSpacesAndNewLinesArb = Arb.stringPrintableWithSpacesAndNewLines()12val stringPrintableWithSpacesAndNewLinesArb = Arb.stringPrintableWithSpacesAndNewLines()13val stringPrintableWithSpacesAndNewLinesArb = Arb.stringPrintableWithSpacesAndNewLines()14val stringPrintableWithSpacesAndNewLinesArb = Arb.stringPrintableWithSpacesAndNewLines()

Full Screen

Full Screen

map

Using AI Code Generation

copy

Full Screen

1val mapArb = Arb.map(Arb.int(), Arb.string())2mapArb.take(10).forEach { println(it) }3val setArb = Arb.set(Arb.int())4setArb.take(10).forEach { println(it) }5val stringArb = Arb.string()6stringArb.take(10).forEach { println(it) }7val uuidArb = Arb.uuid()8uuidArb.take(10).forEach { println(it) }9val longArb = Arb.long()10longArb.take(10).forEach { println(it) }11val doubleArb = Arb.double()12doubleArb.take(10).forEach { println(it) }13val floatArb = Arb.float()14floatArb.take(10).forEach { println(it) }15val bigDecimalArb = Arb.bigDecimal()16bigDecimalArb.take(10).forEach { println(it) }17val bigIntegerArb = Arb.bigInteger()18bigIntegerArb.take(10).forEach { println(it) }19val charArb = Arb.char()20charArb.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) }25enum class TestEnum { A, B, C }26val enumArb = Arb.enum<TestEnum>()27enumArb.take(10).forEach { println(it) }

Full Screen

Full Screen

map

Using AI Code Generation

copy

Full Screen

1import io.kotest.core.spec.style.StringSpec2import io.kotest.matchers.shouldBe3import io.kotest.property.arbitrary.*4import io.kotest.property.*5class MapTest : StringSpec({6"MapTest" {7val map = Arb.map(Arb.int(), Arb.int())8map.sample().size shouldBe 29}10})11import io.kotest.core.spec.style.StringSpec12import io.kotest.matchers.shouldBe13import io.kotest.property.*14import io.kotest.property.arbitrary.*15class MapTest : StringSpec({16"MapTest" {17val map = Arb.map(Arb.int(), Arb.int())18map.sample().size shouldBe 219}20})21import io.kotest.core.spec.style.StringSpec22import io.kotest.matchers.shouldBe23import io.kotest.property.*24import io.kotest.property.arbitrary.*25class MapTest : StringSpec({26"MapTest" {27val map = Arb.map(Arb.int(), Arb.int())28map.sample().size shouldBe 229}30})31import io.kotest.core.spec.style.StringSpec32import io.kotest.matchers.shouldBe33import io.kotest.property.*34import io.kotest.property.arbitrary.*35class MapTest : StringSpec({36"MapTest" {37val map = Arb.map(Arb.int(), Arb.int())38map.sample().size shouldBe 239}40})41import io.kotest.core.spec.style.StringSpec42import io.kotest.matchers.shouldBe43import io.kotest.property.*44import io.kotest.property.arbitrary.*45class MapTest : StringSpec({46"MapTest" {47val map = Arb.map(Arb.int(), Arb.int())48map.sample().size shouldBe 249}50})51import io.kotest.core.spec.style.StringSpec52import io.kotest.matchers.shouldBe53import io.kotest.property.*54import io.kotest.property.arbitrary.*55class MapTest : StringSpec({56"MapTest" {57val map = Arb.map(Arb.int(), Arb.int())58map.sample().size shouldBe 259}60})

Full Screen

Full Screen

map

Using AI Code Generation

copy

Full Screen

1val map = Arb.map(Arb.int(), Arb.string())2map.sample()3val set = Arb.set(Arb.int())4set.sample()5val list = Arb.list(Arb.int())6list.sample()7val sequence = Arb.sequence(Arb.int())8sequence.sample()9val array = Arb.array(Arb.int())10array.sample()11val collection = Arb.collection(Arb.int())12collection.sample()13val list = Arb.list(Arb.int())14list.sample()15val sequence = Arb.sequence(Arb.int())16sequence.sample()17val array = Arb.array(Arb.int())18array.sample()19val collection = Arb.collection(Arb.int())20collection.sample()21val list = Arb.list(Arb.int())22list.sample()23val sequence = Arb.sequence(Arb.int())24sequence.sample()25val array = Arb.array(Arb.int())26array.sample()27val collection = Arb.collection(Arb.int())28collection.sample()29val list = Arb.list(Arb.int())30list.sample()31val sequence = Arb.sequence(Arb.int())32sequence.sample()33val array = Arb.array(Arb.int())34array.sample()35val collection = Arb.collection(Arb.int())36collection.sample()

Full Screen

Full Screen

map

Using AI Code Generation

copy

Full Screen

1val mapArb = Arb.map(Arb.int(), Arb.int())2val map = mapArb .sample()3println(map)4val setArb = Arb.set(Arb.int())5val set = setArb .sample()6println(set)7val stringArb = Arb.string()8val string = stringArb .sample()9println(string)10val charArb = Arb.char()11val char = charArb .sample()12println(char)13val doubleArb = Arb.double()14val double = doubleArb .sample()15println(double)16val floatArb = Arb.float()17val float = floatArb .sample()18println(float)19val longArb = Arb.long()20val long = longArb .sample()21println(long)22val shortArb = Arb.short()23val short = shortArb .sample()24println(short)25val byteArb = Arb.byte()26val byte = byteArb .sample()27println(byte)28val bigDecimalArb = Arb.bigDecimal()29val bigDecimal = bigDecimalArb .sample()30println(bigDecimal)31val bigIntegerArb = Arb.bigInteger()32val bigInteger = bigIntegerArb .sample()33println(bigInteger)34val booleanArb = Arb.boolean()35val boolean = booleanArb .sample()36println(boolean)37val charRangeArb = Arb.charRange()38val charRange = charRangeArb .sample()39println(charRange)

Full Screen

Full Screen

map

Using AI Code Generation

copy

Full Screen

1val map = map(arbitrary< String >(), arbitrary< Int >())2val set = set(arbitrary< String >())3val tuple = tuple(arbitrary< String >(), arbitrary< Int >())4val uuid = uuid()5val uuid = uuid()6val zip = zip(arbitrary< String >(), arbitrary< Int >())7val zipWithNext = zipWithNext(arbitrary< String >(), arbitrary< Int >())8val zipWithPrevious = zipWithPrevious(arbitrary< String >(), arbitrary< Int >())9val zipWithPreviousAndNext = zipWithPreviousAndNext(arbitrary< String >(), arbitrary< Int >())10val zipWithPreviousAndNext = zipWithPreviousAndNext(arbitrary< String >(), arbitrary< Int >())11val zipWithPreviousAndNext = zipWithPreviousAndNext(arbitrary< String >(), arbitrary< Int >())12val zipWithPreviousAndNext = zipWithPreviousAndNext(arbitrary< String >(), arbitrary< Int >())13val zipWithPreviousAndNext = zipWithPreviousAndNext(arbitrary< String >(), arbitrary< Int >())14val zipWithPreviousAndNext = zipWithPreviousAndNext(arbitrary< String >(), arbitrary< Int >())

Full Screen

Full Screen

map

Using AI Code Generation

copy

Full Screen

1 fun `test map class of io.kotest.property.arbitrary package`() {2 val mapArb = Arb.map(Arb.int(), Arb.string())3 val map = mapArb.sample()4 println(map)5 }6 fun `test map class of io.kotest.property package`() {7 val mapArb = io.kotest.property.arbitrary.map(Arb.int(), Arb.string())8 val map = mapArb.sample()9 println(map)10 }11 fun `test map class of io.kotest.property package`() {12 val mapArb = io.kotest.property.arbitrary.map(Arb.int(), Arb.string())13 val map = mapArb.sample()14 println(map)15 }16 fun `test map class of io.kotest.property package`() {17 val mapArb = io.kotest.property.arbitrary.map(Arb.int(), Arb.string())18 val map = mapArb.sample()19 println(map)20 }21 fun `test map class of io.kotest.property package`() {22 val mapArb = io.kotest.property.arbitrary.map(Arb.int(), Arb.string())23 val map = mapArb.sample()24 println(map)25 }26 fun `test map class of io.kotest.property package`() {27 val mapArb = io.kotest.property.arbitrary.map(Arb.int(), Arb.string())28 val map = mapArb.sample()29 println(map)30 }31 fun `test map class of io.kotest.property package`() {32 val mapArb = io.kotest.property.arbitrary.map(Arb.int(), Arb.string())33 val map = mapArb.sample()34 println(map)35 }

Full Screen

Full Screen

map

Using AI Code Generation

copy

Full Screen

1 val map = Arb.map(Arb.int(), Arb.int())2 property("map should be non-empty") {3 forAll(map) {4 it.isNotEmpty()5 }6 }7}

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