How to use Arb.Companion.unit method of io.kotest.property.arbitrary.bind class

Best Kotest code snippet using io.kotest.property.arbitrary.bind.Arb.Companion.unit

bind.kt

Source:bind.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import io.kotest.property.Exhaustive4import io.kotest.property.Gen5import io.kotest.property.RTree6import io.kotest.property.RandomSource7import io.kotest.property.Sample8fun <A, B, T> Arb.Companion.bind(9 genA: Gen<A>,10 genB: Gen<B>,11 bindFn: (A, B) -> T12): Arb<T> =13 Arb.bindN(14 genA,15 genB,16 Arb.unit(),17 Arb.unit(),18 Arb.unit(),19 Arb.unit(),20 Arb.unit(),21 Arb.unit(),22 Arb.unit(),23 Arb.unit(),24 Arb.unit(),25 Arb.unit(),26 Arb.unit(),27 Arb.unit()28 ) { a, b, _, _, _, _, _, _, _, _, _, _, _, _ ->29 bindFn(a, b)30 }31fun <A, B, C, T> Arb.Companion.bind(32 genA: Gen<A>,33 genB: Gen<B>,34 genC: Gen<C>,35 bindFn: (A, B, C) -> T36): Arb<T> = Arb.bindN(37 genA,38 genB,39 genC,40 Arb.unit(),41 Arb.unit(),42 Arb.unit(),43 Arb.unit(),44 Arb.unit(),45 Arb.unit(),46 Arb.unit(),47 Arb.unit(),48 Arb.unit(),49 Arb.unit(),50 Arb.unit()51) { a, b, c, _, _, _, _, _, _, _, _, _, _, _ ->52 bindFn(a, b, c)53}54fun <A, B, C, D, T> Arb.Companion.bind(55 genA: Gen<A>,56 genB: Gen<B>,57 genC: Gen<C>,58 genD: Gen<D>,59 bindFn: (A, B, C, D) -> T60): Arb<T> = Arb.bindN(61 genA,62 genB,63 genC,64 genD,65 Arb.unit(),66 Arb.unit(),67 Arb.unit(),68 Arb.unit(),69 Arb.unit(),70 Arb.unit(),71 Arb.unit(),72 Arb.unit(),73 Arb.unit(),74 Arb.unit()75) { a, b, c, d, _, _, _, _, _, _, _, _, _, _ ->76 bindFn(a, b, c, d)77}78fun <A, B, C, D, E, T> Arb.Companion.bind(79 genA: Gen<A>,80 genB: Gen<B>,81 genC: Gen<C>,82 genD: Gen<D>,83 genE: Gen<E>,84 bindFn: (A, B, C, D, E) -> T85): Arb<T> = Arb.bindN(86 genA,87 genB,88 genC,89 genD,90 genE,91 Arb.unit(),92 Arb.unit(),93 Arb.unit(),94 Arb.unit(),95 Arb.unit(),96 Arb.unit(),97 Arb.unit(),98 Arb.unit(),99 Arb.unit()100) { a, b, c, d, e, _, _, _, _, _, _, _, _, _ ->101 bindFn(a, b, c, d, e)102}103fun <A, B, C, D, E, F, T> Arb.Companion.bind(104 genA: Gen<A>,105 genB: Gen<B>,106 genC: Gen<C>,107 genD: Gen<D>,108 genE: Gen<E>,109 genF: Gen<F>,110 bindFn: (A, B, C, D, E, F) -> T111): Arb<T> = Arb.bindN(112 genA,113 genB,114 genC,115 genD,116 genE,117 genF,118 Arb.unit(),119 Arb.unit(),120 Arb.unit(),121 Arb.unit(),122 Arb.unit(),123 Arb.unit(),124 Arb.unit(),125 Arb.unit()126) { a, b, c, d, e, f, _, _, _, _, _, _, _, _ ->127 bindFn(a, b, c, d, e, f)128}129fun <A, B, C, D, E, F, G, T> Arb.Companion.bind(130 genA: Gen<A>,131 genB: Gen<B>,132 genC: Gen<C>,133 genD: Gen<D>,134 genE: Gen<E>,135 genF: Gen<F>,136 genG: Gen<G>,137 bindFn: (A, B, C, D, E, F, G) -> T138): Arb<T> = Arb.bindN(139 genA,140 genB,141 genC,142 genD,143 genE,144 genF,145 genG,146 Arb.unit(),147 Arb.unit(),148 Arb.unit(),149 Arb.unit(),150 Arb.unit(),151 Arb.unit(),152 Arb.unit()153) { a, b, c, d, e, f, g, _, _, _, _, _, _, _ ->154 bindFn(a, b, c, d, e, f, g)155}156fun <A, B, C, D, E, F, G, H, T> Arb.Companion.bind(157 genA: Gen<A>,158 genB: Gen<B>,159 genC: Gen<C>,160 genD: Gen<D>,161 genE: Gen<E>,162 genF: Gen<F>,163 genG: Gen<G>,164 genH: Gen<H>,165 bindFn: (A, B, C, D, E, F, G, H) -> T166): Arb<T> = Arb.bindN(167 genA,168 genB,169 genC,170 genD,171 genE,172 genF,173 genG,174 genH,175 Arb.unit(),176 Arb.unit(),177 Arb.unit(),178 Arb.unit(),179 Arb.unit(),180 Arb.unit()181) { a, b, c, d, e, f, g, h, _, _, _, _, _, _ ->182 bindFn(a, b, c, d, e, f, g, h)183}184fun <A, B, C, D, E, F, G, H, I, T> Arb.Companion.bind(185 genA: Gen<A>,186 genB: Gen<B>,187 genC: Gen<C>,188 genD: Gen<D>,189 genE: Gen<E>,190 genF: Gen<F>,191 genG: Gen<G>,192 genH: Gen<H>,193 genI: Gen<I>,194 bindFn: (A, B, C, D, E, F, G, H, I) -> T195): Arb<T> = Arb.bindN(196 genA,197 genB,198 genC,199 genD,200 genE,201 genF,202 genG,203 genH,204 genI,205 Arb.unit(),206 Arb.unit(),207 Arb.unit(),208 Arb.unit(),209 Arb.unit()210) { a, b, c, d, e, f, g, h, i, _, _, _, _, _ ->211 bindFn(a, b, c, d, e, f, g, h, i)212}213fun <A, B, C, D, E, F, G, H, I, J, T> Arb.Companion.bind(214 genA: Gen<A>,215 genB: Gen<B>,216 genC: Gen<C>,217 genD: Gen<D>,218 genE: Gen<E>,219 genF: Gen<F>,220 genG: Gen<G>,221 genH: Gen<H>,222 genI: Gen<I>,223 genJ: Gen<J>,224 bindFn: (A, B, C, D, E, F, G, H, I, J) -> T225): Arb<T> = Arb.bindN(226 genA,227 genB,228 genC,229 genD,230 genE,231 genF,232 genG,233 genH,234 genI,235 genJ,236 Arb.unit(),237 Arb.unit(),238 Arb.unit(),239 Arb.unit()240) { a, b, c, d, e, f, g, h, i, j, _, _, _, _ ->241 bindFn(a, b, c, d, e, f, g, h, i, j)242}243fun <A, B, C, D, E, F, G, H, I, J, K, T> Arb.Companion.bind(244 genA: Gen<A>,245 genB: Gen<B>,246 genC: Gen<C>,247 genD: Gen<D>,248 genE: Gen<E>,249 genF: Gen<F>,250 genG: Gen<G>,251 genH: Gen<H>,252 genI: Gen<I>,253 genJ: Gen<J>,254 genK: Gen<K>,255 bindFn: (A, B, C, D, E, F, G, H, I, J, K) -> T256): Arb<T> = Arb.bindN(257 genA,258 genB,259 genC,260 genD,261 genE,262 genF,263 genG,264 genH,265 genI,266 genJ,267 genK,268 Arb.unit(),269 Arb.unit(),270 Arb.unit()271) { a, b, c, d, e, f, g, h, i, j, k, _, _, _ ->272 bindFn(a, b, c, d, e, f, g, h, i, j, k)273}274fun <A, B, C, D, E, F, G, H, I, J, K, L, T> Arb.Companion.bind(275 genA: Gen<A>,276 genB: Gen<B>,277 genC: Gen<C>,278 genD: Gen<D>,279 genE: Gen<E>,280 genF: Gen<F>,281 genG: Gen<G>,282 genH: Gen<H>,283 genI: Gen<I>,284 genJ: Gen<J>,285 genK: Gen<K>,286 genL: Gen<L>,287 bindFn: (A, B, C, D, E, F, G, H, I, J, K, L) -> T288): Arb<T> = Arb.bindN(289 genA,290 genB,291 genC,292 genD,293 genE,294 genF,295 genG,296 genH,297 genI,298 genJ,299 genK,300 genL,301 Arb.unit(),302 Arb.unit()303) { a, b, c, d, e, f, g, h, i, j, k, l, _, _ ->304 bindFn(a, b, c, d, e, f, g, h, i, j, k, l)305}306fun <A, B, C, D, E, F, G, H, I, J, K, L, M, T> Arb.Companion.bind(307 genA: Gen<A>,308 genB: Gen<B>,309 genC: Gen<C>,310 genD: Gen<D>,311 genE: Gen<E>,312 genF: Gen<F>,313 genG: Gen<G>,314 genH: Gen<H>,315 genI: Gen<I>,316 genJ: Gen<J>,317 genK: Gen<K>,318 genL: Gen<L>,319 genM: Gen<M>,320 bindFn: (A, B, C, D, E, F, G, H, I, J, K, L, M) -> T321): Arb<T> = Arb.bindN(322 genA,323 genB,324 genC,325 genD,326 genE,327 genF,328 genG,329 genH,330 genI,331 genJ,332 genK,333 genL,334 genM,335 Arb.unit()336) { a, b, c, d, e, f, g, h, i, j, k, l, m, _ ->337 bindFn(a, b, c, d, e, f, g, h, i, j, k, l, m)338}339fun <A, B, C, D, E, F, G, H, I, J, K, L, M, N, T> Arb.Companion.bind(340 genA: Gen<A>,341 genB: Gen<B>,342 genC: Gen<C>,343 genD: Gen<D>,344 genE: Gen<E>,345 genF: Gen<F>,346 genG: Gen<G>,347 genH: Gen<H>,348 genI: Gen<I>,349 genJ: Gen<J>,350 genK: Gen<K>,351 genL: Gen<L>,352 genM: Gen<M>,353 genN: Gen<N>,354 bindFn: (A, B, C, D, E, F, G, H, I, J, K, L, M, N) -> T355): Arb<T> = Arb.bindN(356 genA,357 genB,358 genC,359 genD,360 genE,361 genF,362 genG,363 genH,364 genI,365 genJ,366 genK,367 genL,368 genM,369 genN,370 bindFn371)372internal fun Arb.Companion.unit(): Arb<Unit> = arbitrary { }373internal fun <A, B, C, D, E, F, G, H, I, J, K, L, M, N, T> Arb.Companion.bindN(374 genA: Gen<A>,375 genB: Gen<B>,376 genC: Gen<C>,377 genD: Gen<D>,378 genE: Gen<E>,379 genF: Gen<F>,380 genG: Gen<G>,381 genH: Gen<H>,382 genI: Gen<I>,383 genJ: Gen<J>,384 genK: Gen<K>,385 genL: Gen<L>,386 genM: Gen<M>,387 genN: Gen<N>,388 bindFn: (A, B, C, D, E, F, G, H, I, J, K, L, M, N) -> T,389): Arb<T> {390 fun <S> shrink(tree: RTree<S>): List<RTree<S>> = tree.children.value391 fun combineShrinks(392 a: RTree<A>, b: RTree<B>, c: RTree<C>, d: RTree<D>, e: RTree<E>,393 f: RTree<F>, g: RTree<G>, h: RTree<H>, i: RTree<I>, j: RTree<J>,394 k: RTree<K>, l: RTree<L>, m: RTree<M>, n: RTree<N>395 ): RTree<T> =396 RTree(397 {398 bindFn(399 a.value(), b.value(), c.value(), d.value(), e.value(),400 f.value(), g.value(), h.value(), i.value(), j.value(),401 k.value(), l.value(), m.value(), n.value()402 )403 },404 kotlin.lazy {405 shrink(a).map { combineShrinks(it, b, c, d, e, f, g, h, i, j, k, l, m, n) } +406 shrink(b).map { combineShrinks(a, it, c, d, e, f, g, h, i, j, k, l, m, n) } +407 shrink(c).map { combineShrinks(a, b, it, d, e, f, g, h, i, j, k, l, m, n) } +408 shrink(d).map { combineShrinks(a, b, c, it, e, f, g, h, i, j, k, l, m, n) } +409 shrink(e).map { combineShrinks(a, b, c, d, it, f, g, h, i, j, k, l, m, n) } +410 shrink(f).map { combineShrinks(a, b, c, d, e, it, g, h, i, j, k, l, m, n) } +411 shrink(g).map { combineShrinks(a, b, c, d, e, f, it, h, i, j, k, l, m, n) } +412 shrink(h).map { combineShrinks(a, b, c, d, e, f, g, it, i, j, k, l, m, n) } +413 shrink(i).map { combineShrinks(a, b, c, d, e, f, g, h, it, j, k, l, m, n) } +414 shrink(j).map { combineShrinks(a, b, c, d, e, f, g, h, i, it, k, l, m, n) } +415 shrink(k).map { combineShrinks(a, b, c, d, e, f, g, h, i, j, it, l, m, n) } +416 shrink(l).map { combineShrinks(a, b, c, d, e, f, g, h, i, j, k, it, m, n) } +417 shrink(m).map { combineShrinks(a, b, c, d, e, f, g, h, i, j, k, l, it, n) } +418 shrink(n).map { combineShrinks(a, b, c, d, e, f, g, h, i, j, k, l, m, it) }419 }420 )421 val arbA = genA.toArb()422 val arbB = genB.toArb()423 val arbC = genC.toArb()424 val arbD = genD.toArb()425 val arbE = genE.toArb()426 val arbF = genF.toArb()427 val arbG = genG.toArb()428 val arbH = genH.toArb()429 val arbI = genI.toArb()430 val arbJ = genJ.toArb()431 val arbK = genK.toArb()432 val arbL = genL.toArb()433 val arbM = genM.toArb()434 val arbN = genN.toArb()435 return object : Arb<T>() {436 override fun edgecase(rs: RandomSource): T? {437 return bindFn(438 arbA.edgecase(rs) ?: arbA.next(rs),439 arbB.edgecase(rs) ?: arbB.next(rs),440 arbC.edgecase(rs) ?: arbC.next(rs),441 arbD.edgecase(rs) ?: arbD.next(rs),442 arbE.edgecase(rs) ?: arbE.next(rs),443 arbF.edgecase(rs) ?: arbF.next(rs),444 arbG.edgecase(rs) ?: arbG.next(rs),445 arbH.edgecase(rs) ?: arbH.next(rs),446 arbI.edgecase(rs) ?: arbI.next(rs),447 arbJ.edgecase(rs) ?: arbJ.next(rs),448 arbK.edgecase(rs) ?: arbK.next(rs),449 arbL.edgecase(rs) ?: arbL.next(rs),450 arbM.edgecase(rs) ?: arbM.next(rs),451 arbN.edgecase(rs) ?: arbN.next(rs),452 )453 }454 override fun sample(rs: RandomSource): Sample<T> {455 val (av, ar) = arbA.sample(rs)456 val (bv, br) = arbB.sample(rs)457 val (cv, cr) = arbC.sample(rs)458 val (dv, dr) = arbD.sample(rs)459 val (ev, er) = arbE.sample(rs)460 val (fv, fr) = arbF.sample(rs)461 val (gv, gr) = arbG.sample(rs)462 val (hv, hr) = arbH.sample(rs)463 val (iv, ir) = arbI.sample(rs)464 val (jv, jr) = arbJ.sample(rs)465 val (kv, kr) = arbK.sample(rs)466 val (lv, lr) = arbL.sample(rs)467 val (mv, mr) = arbM.sample(rs)468 val (nv, nr) = arbN.sample(rs)469 return Sample(470 bindFn(av, bv, cv, dv, ev, fv, gv, hv, iv, jv, kv, lv, mv, nv),471 combineShrinks(ar, br, cr, dr, er, fr, gr, hr, ir, jr, kr, lr, mr, nr)472 )473 }474 }475}476fun <A, B> Arb.Companion.bind(arbs: List<Arb<A>>, fn: (List<A>) -> B): Arb<B> = bind(arbs).map(fn)477internal fun <T> Gen<T>.toArb(): Arb<T> = when (this) {478 is Arb -> this479 is Exhaustive -> this.toArb()480}481internal fun <A> Arb.Companion.bind(arbs: List<Arb<A>>): Arb<List<A>> = when (arbs.size) {482 0 -> Arb.constant(emptyList())483 1 -> arbs[0].map { listOf(it) }484 else -> {485 val listOfArbs: List<Arb<List<A>>> = arbs.chunked(14) { el ->486 check(el.size <= 14) { "reached an impossible state" }487 when (el.size) {488 0 -> Arb.constant(emptyList())489 1 -> el[0].map { listOf(it) }490 2 -> Arb.bind(el[0], el[1]) { a, b -> listOf(a, b) }491 3 -> Arb.bind(el[0], el[1], el[2]) { a, b, c -> listOf(a, b, c) }492 4 -> Arb.bind(el[0], el[1], el[2], el[3]) { a, b, c, d -> listOf(a, b, c, d) }493 5 -> Arb.bind(el[0], el[1], el[2], el[3], el[4]) { a, b, c, d, e -> listOf(a, b, c, d, e) }494 6 -> Arb.bind(el[0], el[1], el[2], el[3], el[4], el[5]) { a, b, c, d, e, f ->495 listOf(a, b, c, d, e, f)496 }497 7 -> Arb.bind(el[0], el[1], el[2], el[3], el[4], el[5], el[6]) { a, b, c, d, e, f, g ->498 listOf(a, b, c, d, e, f, g)499 }500 8 -> Arb.bind(el[0], el[1], el[2], el[3], el[4], el[5], el[6], el[7]) { a, b, c, d, e, f, g, h ->501 listOf(a, b, c, d, e, f, g, h)502 }503 9 -> Arb.bind(el[0], el[1], el[2], el[3], el[4], el[5], el[6], el[7], el[8]) { a, b, c, d, e, f, g, h, i ->504 listOf(a, b, c, d, e, f, g, h, i)505 }506 10 -> Arb.bind(507 el[0], el[1], el[2], el[3], el[4],508 el[5], el[6], el[7], el[8], el[9]509 ) { a, b, c, d, e, f, g, h, i, j ->510 listOf(a, b, c, d, e, f, g, h, i, j)511 }512 11 -> Arb.bind(513 el[0], el[1], el[2], el[3], el[4],514 el[5], el[6], el[7], el[8], el[9],515 el[10]516 ) { a, b, c, d, e, f, g, h, i, j, k ->517 listOf(a, b, c, d, e, f, g, h, i, j, k)518 }519 12 -> Arb.bind(520 el[0], el[1], el[2], el[3], el[4],521 el[5], el[6], el[7], el[8], el[9],522 el[10], el[11]523 ) { a, b, c, d, e, f, g, h, i, j, k, l ->524 listOf(a, b, c, d, e, f, g, h, i, j, k, l)525 }526 13 -> Arb.bind(527 el[0], el[1], el[2], el[3], el[4],528 el[5], el[6], el[7], el[8], el[9],529 el[10], el[11], el[12]530 ) { a, b, c, d, e, f, g, h, i, j, k, l, m ->531 listOf(a, b, c, d, e, f, g, h, i, j, k, l, m)532 }533 14 -> Arb.bind(534 el[0], el[1], el[2], el[3], el[4],535 el[5], el[6], el[7], el[8], el[9],536 el[10], el[11], el[12], el[13]537 ) { a, b, c, d, e, f, g, h, i, j, k, l, m, n ->538 listOf(a, b, c, d, e, f, g, h, i, j, k, l, m, n)539 }540 else -> Arb.constant(emptyList())541 }542 }543 Arb.bind(listOfArbs).map { it.flatten() }544 }545}...

Full Screen

Full Screen

ParseProperty.kt

Source:ParseProperty.kt Github

copy

Full Screen

1package net.torommo.logspy2import io.kotest.core.spec.style.StringSpec3import io.kotest.property.Arb4import io.kotest.property.arbitrary.Codepoint5import io.kotest.property.arbitrary.arbitrary6import io.kotest.property.arbitrary.bind7import io.kotest.property.arbitrary.element8import io.kotest.property.arbitrary.filter9import io.kotest.property.arbitrary.int10import io.kotest.property.arbitrary.map11import io.kotest.property.arbitrary.merge12import io.kotest.property.arbitrary.single13import io.kotest.property.arbitrary.string14import io.kotest.property.checkAll15import kotlin.random.Random16import kotlin.random.nextInt17import kotlin.streams.asSequence18import kotlin.text.CharCategory.DECIMAL_DIGIT_NUMBER19import kotlin.text.CharCategory.LETTER_NUMBER20import kotlin.text.CharCategory.LOWERCASE_LETTER21import kotlin.text.CharCategory.MODIFIER_LETTER22import kotlin.text.CharCategory.OTHER_LETTER23import kotlin.text.CharCategory.TITLECASE_LETTER24import kotlin.text.CharCategory.UPPERCASE_LETTER25import net.torommo.logspy.ExceptionCreationAction.ADD_SUPPRESSED_TO_ROOT_EXCEPTION26import net.torommo.logspy.ExceptionCreationAction.RANDOM_ACTION_ON_RANDOM_SUPPRESSED_IN_ROOT_EXCEPTION27import net.torommo.logspy.ExceptionCreationAction.SET_NEW_ROOT_EXCEPTION28import org.junit.jupiter.api.Assertions.assertDoesNotThrow29import org.slf4j.Logger30import org.slf4j.LoggerFactory31class ParseProperty :32 StringSpec(33 {34 "logger name parsability" {35 checkAll(36 arbitrary(PositionIndenpendentStringShrinker(1)) { rs ->37 arbJavaIdentifier.merge(arbKotlinIdentifier).single(rs)38 }39 ) { loggerName ->40 val logger = LoggerFactory.getLogger(loggerName)41 LogstashStdoutSpyProvider().createFor(loggerName)42 .use {43 logger.error("Test")44 assertDoesNotThrow(it::events);45 }46 }47 }48 "log level parsability" {49 checkAll(arbLevel) { logAction ->50 val logger = LoggerFactory.getLogger("test")51 LogstashStdoutSpyProvider().createFor("test")52 .use {53 logAction(logger, "Test")54 assertDoesNotThrow(it::events);55 }56 }57 }58 "log message parsability" {59 checkAll(60 arbitrary(PositionIndenpendentStringShrinker()) { rs -> arbMessage.single(rs) }61 ) { message ->62 val logger = LoggerFactory.getLogger("test")63 LogstashStdoutSpyProvider().createFor("test")64 .use {65 logger.error(message)66 assertDoesNotThrow(it::events);67 }68 }69 }70 "exception message parsability" {71 val logger = LoggerFactory.getLogger("test")72 checkAll(73 arbitrary(PositionIndenpendentStringShrinker()) { rs -> arbMessage.single(rs) }74 ) { message ->75 LogstashStdoutSpyProvider().createFor("test")76 .use {77 val exception = RuntimeException(message)78 exception.stackTrace = emptyArray()79 logger.error("test", exception)80 assertDoesNotThrow(it::events);81 }82 }83 }84 "stack trace parsability" {85 val logger = LoggerFactory.getLogger("test")86 checkAll(87 arbitrary(ArrayShrinker()) { rs ->88 arbKotlinStackTraceElements.merge(arbJavaStackTraceElements).single(rs)89 }90 ) { element: Array<StackTraceElement> ->91 LogstashStdoutSpyProvider().createFor("test")92 .use {93 val exception = RuntimeException("test message")94 exception.stackTrace = element95 logger.error("test", exception)96 assertDoesNotThrow(it::events);97 }98 }99 }100 "exception tree parsability" {101 val logger = LoggerFactory.getLogger("test")102 checkAll(arbExceptionTree) { exception: Throwable ->103 LogstashStdoutSpyProvider().createFor("test")104 .use {105 logger.error("test", exception)106 assertDoesNotThrow(it::events);107 }108 }109 }110 }111 )112fun Arb.Companion.printableAscii(): Arb<Codepoint> =113 arbitrary(listOf(Codepoint('a'.code))) { rs ->114 val printableChars = (' '.code..'~'.code).asSequence()115 val codepoints = printableChars.map { Codepoint(it) }.toList()116 val ints = Arb.int(codepoints.indices)117 codepoints[ints.sample(rs).value]118 }119fun Arb.Companion.printableMultilinesIndentedAscii(): Arb<Codepoint> =120 arbitrary(listOf(Codepoint('a'.code))) { rs ->121 val indentings = sequenceOf(0xB)122 val endOfLines = sequenceOf(0xA, 0xD)123 val printableChars = (' '.code..'~'.code).asSequence()124 val codepoints = (indentings + endOfLines + printableChars).map { Codepoint(it) }.toList()125 val ints = Arb.int(codepoints.indices)126 codepoints[ints.sample(rs).value]127 }128fun Arb.Companion.unicode(): Arb<Codepoint> =129 arbitrary(listOf(Codepoint('a'.code))) { rs ->130 val ints = Arb.int(Character.MIN_CODE_POINT..Character.MAX_CODE_POINT)131 Codepoint(ints.sample(rs).value)132 }133val arbLevel =134 Arb.element(135 listOf<(Logger, String) -> Unit>(136 Logger::error,137 Logger::warn,138 Logger::info,139 Logger::debug,140 Logger::trace141 )142 )143val arbMessage =144 Arb.string(0, 1024, Arb.printableMultilinesIndentedAscii())145 .merge(Arb.string(0, 1024, Arb.unicode()))146val arbJavaIdentifier =147 Arb.string(minSize = 1, codepoints = Arb.printableAscii())148 .merge(Arb.string(minSize = 1, codepoints = Arb.unicode()))149 .filter { Character.isJavaIdentifierStart(it.codePoints().asSequence().first()) }150 .filter {151 it.codePoints()152 .asSequence()153 .all { codePoint -> Character.isJavaIdentifierPart(codePoint) }154 }155val arbJavaFileName = arbJavaIdentifier.map { "${it}.java" }156val arbJavaStackTraceElement =157 Arb.bind(arbJavaIdentifier, arbJavaIdentifier, arbJavaFileName, Arb.int(-65536, 65535))158 { className, methodName, fileName, lineNumber ->159 StackTraceElement(className, methodName, fileName, lineNumber)160 }161val arbJavaStackTraceElements = Arb.array(arbJavaStackTraceElement, 0..7)162val arbKotlinIdentifier =163 Arb.string(minSize = 1, codepoints = Arb.printableAscii())164 .merge(Arb.string(minSize = 1, codepoints = Arb.unicode()))165 .filter { isUnescapedIdentifier(it) || isEscapedIdentifier(it) }166val arbKotlinFileName = arbKotlinIdentifier.map { "${it}.kt" };167val arbKotlinStackTraceElement =168 Arb.bind(arbKotlinIdentifier, arbKotlinIdentifier, arbKotlinFileName, Arb.int(-65536, 65535))169 { className, methodName, fileName, lineNumber ->170 StackTraceElement(className, methodName, fileName, lineNumber)171 }172val arbKotlinStackTraceElements = Arb.array(arbKotlinStackTraceElement, 0..7)173val arbExceptionTree: Arb<Throwable> =174 arbitrary { rs ->175 val throwableGenerator = arbFlatException.generate(rs).iterator()176 val result = throwableGenerator.next().value177 repeat(rs.random.nextInt(1..7)) {178 val exceptionToPlace = throwableGenerator.next().value179 addExceptionToRandomPlace(rs.random, result, exceptionToPlace)180 }181 result182 }183private fun addExceptionToRandomPlace(random: Random, aggregator: Throwable, addition: Throwable) {184 when (ExceptionCreationAction.values()[random.nextInt(ExceptionCreationAction.values().size)]) {185 SET_NEW_ROOT_EXCEPTION -> {186 rootCauseOf(aggregator).initCause(addition)187 }188 ADD_SUPPRESSED_TO_ROOT_EXCEPTION -> {189 rootCauseOf(aggregator).addSuppressed(addition)190 }191 RANDOM_ACTION_ON_RANDOM_SUPPRESSED_IN_ROOT_EXCEPTION -> {192 val rootCause = rootCauseOf(aggregator)193 if (rootCause.suppressed.isNotEmpty()) {194 addExceptionToRandomPlace(195 random,196 rootCause.suppressed[random.nextInt(rootCause.suppressed.size)],197 addition198 )199 }200 }201 }202}203private tailrec fun rootCauseOf(candidate: Throwable): Throwable {204 return if (candidate.cause == null) {205 candidate206 } else {207 rootCauseOf(candidate.cause!!)208 }209}210private enum class ExceptionCreationAction {211 SET_NEW_ROOT_EXCEPTION,212 ADD_SUPPRESSED_TO_ROOT_EXCEPTION,213 RANDOM_ACTION_ON_RANDOM_SUPPRESSED_IN_ROOT_EXCEPTION214}215val arbFlatException =216 Arb.bind(217 Arb.string(0, 255, Arb.printableMultilinesIndentedAscii()),218 arbKotlinStackTraceElements.merge(arbJavaStackTraceElements)219 ) { message, stackTrace ->220 val result: Exception = RuntimeException(message)221 result.stackTrace = stackTrace222 result223 }224private fun isUnescapedIdentifier(string: String): Boolean {225 return isLetterOrUnderscore(string.first()) &&226 string.toCharArray().all { char -> isLetterOrUnderscore(char) || isUnicodeDigit(char) }227}228private fun isLetterOrUnderscore(char: Char): Boolean {229 return LOWERCASE_LETTER.contains(char) || UPPERCASE_LETTER.contains(char) ||230 TITLECASE_LETTER.contains(char) || LETTER_NUMBER.contains(char) ||231 MODIFIER_LETTER.contains(char) || OTHER_LETTER.contains(char) || char == '_'232}233private fun isUnicodeDigit(char: Char): Boolean {234 return DECIMAL_DIGIT_NUMBER.contains(char)235}236private fun isEscapedIdentifier(string: String): Boolean {237 return string.all { it != '\r' && it != '\n' && it != '`' }238}...

Full Screen

Full Screen

predef-test.kt

Source:predef-test.kt Github

copy

Full Screen

1package arrow.fx.coroutines2import arrow.core.Either3import arrow.core.Validated4import arrow.core.ValidatedNel5import arrow.core.identity6import arrow.core.invalid7import arrow.core.invalidNel8import arrow.core.left9import arrow.core.right10import arrow.core.valid11import arrow.core.validNel12import io.kotest.assertions.fail13import io.kotest.matchers.Matcher14import io.kotest.matchers.MatcherResult15import io.kotest.matchers.equalityMatcher16import io.kotest.property.Arb17import io.kotest.property.arbitrary.bind18import io.kotest.property.arbitrary.char19import io.kotest.property.arbitrary.choice20import io.kotest.property.arbitrary.choose21import io.kotest.property.arbitrary.constant22import io.kotest.property.arbitrary.int23import io.kotest.property.arbitrary.list24import io.kotest.property.arbitrary.long25import io.kotest.property.arbitrary.map26import io.kotest.property.arbitrary.string27import kotlinx.coroutines.Dispatchers28import kotlinx.coroutines.flow.Flow29import kotlinx.coroutines.flow.asFlow30import kotlin.coroutines.Continuation31import kotlin.coroutines.CoroutineContext32import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED33import kotlin.coroutines.intrinsics.intercepted34import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn35import kotlin.coroutines.resume36import kotlin.coroutines.startCoroutine37import kotlinx.coroutines.channels.Channel38import kotlinx.coroutines.flow.buffer39import kotlinx.coroutines.flow.channelFlow40import kotlinx.coroutines.flow.emptyFlow41public data class SideEffect(var counter: Int = 0) {42 public fun increment() {43 counter++44 }45}46public fun <A> Arb.Companion.flow(arbA: Arb<A>): Arb<Flow<A>> =47 Arb.choose(48 10 to Arb.list(arbA).map { it.asFlow() },49 10 to Arb.list(arbA).map { channelFlow { it.forEach { send(it) } }.buffer(Channel.RENDEZVOUS) },50 1 to Arb.constant(emptyFlow()),51 )52public fun Arb.Companion.throwable(): Arb<Throwable> =53 Arb.string().map(::RuntimeException)54public fun <L, R> Arb.Companion.either(left: Arb<L>, right: Arb<R>): Arb<Either<L, R>> {55 val failure: Arb<Either<L, R>> = left.map { l -> l.left() }56 val success: Arb<Either<L, R>> = right.map { r -> r.right() }57 return Arb.choice(failure, success)58}59public fun <L, R> Arb.Companion.validated(left: Arb<L>, right: Arb<R>): Arb<Validated<L, R>> {60 val failure: Arb<Validated<L, R>> = left.map { l -> l.invalid() }61 val success: Arb<Validated<L, R>> = right.map { r -> r.valid() }62 return Arb.choice(failure, success)63}64public fun <L, R> Arb.Companion.validatedNel(left: Arb<L>, right: Arb<R>): Arb<ValidatedNel<L, R>> {65 val failure: Arb<ValidatedNel<L, R>> = left.map { l -> l.invalidNel() }66 val success: Arb<ValidatedNel<L, R>> = right.map { r -> r.validNel() }67 return Arb.choice(failure, success)68}69public fun Arb.Companion.intRange(min: Int = Int.MIN_VALUE, max: Int = Int.MAX_VALUE): Arb<IntRange> =70 Arb.bind(Arb.int(min, max), Arb.int(min, max)) { a, b ->71 if (a < b) a..b else b..a72 }73public fun Arb.Companion.longRange(min: Long = Long.MIN_VALUE, max: Long = Long.MAX_VALUE): Arb<LongRange> =74 Arb.bind(Arb.long(min, max), Arb.long(min, max)) { a, b ->75 if (a < b) a..b else b..a76 }77public fun Arb.Companion.charRange(): Arb<CharRange> =78 Arb.bind(Arb.char(), Arb.char()) { a, b ->79 if (a < b) a..b else b..a80 }81public fun <O> Arb.Companion.function(arb: Arb<O>): Arb<() -> O> =82 arb.map { { it } }83public fun Arb.Companion.unit(): Arb<Unit> =84 Arb.constant(Unit)85public fun <A, B> Arb.Companion.functionAToB(arb: Arb<B>): Arb<(A) -> B> =86 arb.map { b: B -> { _: A -> b } }87public fun <A> Arb.Companion.nullable(arb: Arb<A>): Arb<A?> =88 Arb.Companion.choice(arb, arb.map { null })89/** Useful for testing success & error scenarios with an `Either` generator **/90public fun <A> Either<Throwable, A>.rethrow(): A =91 fold({ throw it }, ::identity)92public fun <A> Result<A>.toEither(): Either<Throwable, A> =93 fold({ a -> Either.Right(a) }, { e -> Either.Left(e) })94public suspend fun Throwable.suspend(): Nothing =95 suspendCoroutineUninterceptedOrReturn { cont ->96 suspend { throw this }.startCoroutine(97 Continuation(Dispatchers.Default) {98 cont.intercepted().resumeWith(it)99 }100 )101 COROUTINE_SUSPENDED102 }103public suspend fun <A> A.suspend(): A =104 suspendCoroutineUninterceptedOrReturn { cont ->105 suspend { this }.startCoroutine(106 Continuation(Dispatchers.Default) {107 cont.intercepted().resumeWith(it)108 }109 )110 COROUTINE_SUSPENDED111 }112public fun <A> A.suspended(): suspend () -> A =113 suspend { suspend() }114/**115 * Example usage:116 * ```kotlin117 * import arrow.fx.coroutines.assertThrowable118 *119 * fun main() {120 * val exception = assertThrowable<IllegalArgumentException> {121 * throw IllegalArgumentException("Talk to a duck")122 * }123 * require("Talk to a duck" == exception.message)124 * }125 * ```126 * <!--- KNIT example-predef-test-01.kt -->127 * @see Assertions.assertThrows128 */129public inline fun <A> assertThrowable(executable: () -> A): Throwable {130 val a = try {131 executable.invoke()132 } catch (e: Throwable) {133 e134 }135 return if (a is Throwable) a else fail("Expected an exception but found: $a")136}137public suspend fun CoroutineContext.shift(): Unit =138 suspendCoroutineUninterceptedOrReturn { cont ->139 suspend { this }.startCoroutine(140 Continuation(this) {141 cont.resume(Unit)142 }143 )144 COROUTINE_SUSPENDED145 }146public fun leftException(e: Throwable): Matcher<Either<Throwable, *>> =147 object : Matcher<Either<Throwable, *>> {148 override fun test(value: Either<Throwable, *>): MatcherResult =149 when (value) {150 is Either.Left -> when {151 value.value::class != e::class -> MatcherResult(152 false,153 "Expected exception of type ${e::class} but found ${value.value::class}",154 "Should not be exception of type ${e::class}"155 )156 value.value.message != e.message -> MatcherResult(157 false,158 "Expected exception with message ${e.message} but found ${value.value.message}",159 "Should not be exception with message ${e.message}"160 )161 else -> MatcherResult(162 true,163 "Expected exception of type ${e::class} and found ${value.value::class}",164 "Expected exception of type ${e::class} and found ${value.value::class}"165 )166 }167 is Either.Right -> MatcherResult(168 false,169 "Expected Either.Left with exception of type ${e::class} and found Right with ${value.value}",170 "Should not be Either.Left with exception"171 )172 }173 }174public fun <A> either(e: Either<Throwable, A>): Matcher<Either<Throwable, A>> =175 object : Matcher<Either<Throwable, A>> {176 override fun test(value: Either<Throwable, A>): MatcherResult =177 when (value) {178 is Either.Left -> when {179 value.value::class != (e.swap().orNull() ?: Int)::class -> MatcherResult(180 false,181 "Expected $e but found $value",182 "Should not be $e"183 )184 value.value.message != (e.swap().orNull()?.message ?: -1) -> MatcherResult(185 false,186 "Expected $e but found $value",187 "Should not be $e"188 )189 else -> MatcherResult(190 true,191 "Expected exception of type ${e::class} and found ${value.value::class}",192 "Expected exception of type ${e::class} and found ${value.value::class}"193 )194 }195 is Either.Right -> equalityMatcher(e).test(value)196 }197 }...

Full Screen

Full Screen

Generators.kt

Source:Generators.kt Github

copy

Full Screen

1package arrow.core.test.generators2import arrow.core.Const3import arrow.core.Either4import arrow.core.Endo5import arrow.core.Eval6import arrow.core.Ior7import arrow.core.Option8import arrow.core.Tuple109import arrow.core.Tuple410import arrow.core.Tuple511import arrow.core.Tuple612import arrow.core.Tuple713import arrow.core.Tuple814import arrow.core.Tuple915import arrow.core.Validated16import arrow.core.left17import arrow.core.right18import arrow.core.toOption19import io.kotest.property.Arb20import io.kotest.property.arbitrary.bind21import io.kotest.property.arbitrary.boolean22import io.kotest.property.arbitrary.byte23import io.kotest.property.arbitrary.choice24import io.kotest.property.arbitrary.constant25import 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

UnitSpec.kt

Source:UnitSpec.kt Github

copy

Full Screen

1package arrow.core.test2import arrow.core.NonEmptyList3import arrow.core.Tuple44import arrow.core.Tuple55import arrow.core.test.generators.unit6import arrow.core.test.laws.Law7import io.kotest.core.names.TestName8import io.kotest.core.spec.style.StringSpec9import io.kotest.property.Arb10import io.kotest.property.Gen11import io.kotest.property.PropertyContext12import io.kotest.property.arbitrary.bind13import io.kotest.property.arbitrary.filter14import io.kotest.property.arbitrary.map15import io.kotest.property.arbitrary.list as KList16import io.kotest.property.arbitrary.map as KMap17import io.kotest.property.checkAll18import kotlin.jvm.JvmOverloads19import kotlin.math.max20/**21 * Base class for unit tests22 */23public abstract class UnitSpec(24 public val iterations: Int = 250,25 public val maxDepth: Int = 15,26 spec: UnitSpec.() -> Unit = {}27) : StringSpec() {28 public constructor(spec: UnitSpec.() -> Unit) : this(250, 15, spec)29 public fun <A> Arb.Companion.list(gen: Gen<A>, range: IntRange = 0..maxDepth): Arb<List<A>> =30 Arb.KList(gen, range)31 public fun <A> Arb.Companion.nonEmptyList(arb: Arb<A>, depth: Int = maxDepth): Arb<NonEmptyList<A>> =32 Arb.list(arb, 1..max(1, depth)).filter(List<A>::isNotEmpty).map(NonEmptyList.Companion::fromListUnsafe)33 public fun <A> Arb.Companion.sequence(arbA: Arb<A>, range: IntRange = 0..maxDepth): Arb<Sequence<A>> =34 Arb.list(arbA, range).map { it.asSequence() }35 @JvmOverloads36 public inline fun <reified A> Arb.Companion.array(gen: Arb<A>, range: IntRange = 0..maxDepth): Arb<Array<A>> =37 Arb.list(gen, range).map { it.toTypedArray() }38 public fun <K, V> Arb.Companion.map(39 keyArb: Arb<K>,40 valueArb: Arb<V>,41 minSize: Int = 1,42 maxSize: Int = 1543 ): Arb<Map<K, V>> =44 Arb.KMap(keyArb, valueArb, minSize = minSize, maxSize = maxSize)45 init {46 spec()47 }48 public fun testLaws(vararg laws: List<Law>): Unit = laws49 .flatMap { list: List<Law> -> list.asIterable() }50 .distinctBy { law: Law -> law.name }51 .forEach { law: Law ->52 registration().addTest(TestName(law.name), xdisabled = false, law.test)53 }54 public fun testLaws(prefix: String, vararg laws: List<Law>): Unit = laws55 .flatMap { list: List<Law> -> list.asIterable() }56 .distinctBy { law: Law -> law.name }57 .forEach { law: Law ->58 registration().addTest(TestName(prefix, law.name, true), xdisabled = false, law.test)59 }60 public suspend fun checkAll(property: suspend PropertyContext.() -> Unit): PropertyContext =61 checkAll(iterations, Arb.unit()) { property() }62 public suspend fun <A> checkAll(63 genA: Arb<A>,64 property: suspend PropertyContext.(A) -> Unit65 ): PropertyContext =66 checkAll(67 iterations,68 genA,69 property70 )71 public suspend fun <A, B> checkAll(72 genA: Arb<A>,73 genB: Arb<B>,74 property: suspend PropertyContext.(A, B) -> Unit75 ): PropertyContext =76 checkAll(77 iterations,78 genA,79 genB,80 property81 )82 public suspend fun <A, B, C> checkAll(83 genA: Arb<A>,84 genB: Arb<B>,85 genC: Arb<C>,86 property: suspend PropertyContext.(A, B, C) -> Unit87 ): PropertyContext =88 checkAll(89 iterations,90 genA,91 genB,92 genC,93 property94 )95 public suspend fun <A, B, C, D> checkAll(96 genA: Arb<A>,97 genB: Arb<B>,98 genC: Arb<C>,99 genD: Arb<D>,100 property: suspend PropertyContext.(A, B, C, D) -> Unit101 ): PropertyContext =102 checkAll(103 iterations,104 genA,105 genB,106 genC,107 genD,108 property109 )110 public suspend fun <A, B, C, D, E> checkAll(111 genA: Arb<A>,112 genB: Arb<B>,113 genC: Arb<C>,114 genD: Arb<D>,115 genE: Arb<E>,116 property: suspend PropertyContext.(A, B, C, D, E) -> Unit117 ): PropertyContext =118 checkAll(119 iterations,120 genA,121 genB,122 genC,123 genD,124 genE,125 property126 )127 public suspend fun <A, B, C, D, E, F> checkAll(128 genA: Arb<A>,129 genB: Arb<B>,130 genC: Arb<C>,131 genD: Arb<D>,132 genE: Arb<E>,133 genF: Arb<F>,134 property: suspend PropertyContext.(A, B, C, D, E, F) -> Unit135 ): PropertyContext =136 checkAll(137 iterations,138 genA,139 genB,140 genC,141 genD,142 genE,143 genF,144 property145 )146 public suspend fun <A, B, C, D, E, F, G> checkAll(147 gena: Arb<A>,148 genb: Arb<B>,149 genc: Arb<C>,150 gend: Arb<D>,151 gene: Arb<E>,152 genf: Arb<F>,153 geng: Arb<G>,154 fn: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F, g: G) -> Unit155 ) {156 checkAll(gena, genb, genc, gend, gene, Arb.bind(genf, geng, ::Pair)) { a, b, c, d, e, (f, g) ->157 fn(a, b, c, d, e, f, g)158 }159 }160 public suspend fun <A, B, C, D, E, F, G, H> checkAll(161 gena: Arb<A>,162 genb: Arb<B>,163 genc: Arb<C>,164 gend: Arb<D>,165 gene: Arb<E>,166 genf: Arb<F>,167 geng: Arb<G>,168 genh: Arb<H>,169 fn: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H) -> Unit170 ) {171 checkAll(gena, genb, genc, gend, gene, Arb.bind(genf, geng, genh, ::Triple)) { a, b, c, d, e, (f, g, h) ->172 fn(a, b, c, d, e, f, g, h)173 }174 }175 public suspend fun <A, B, C, D, E, F, G, H, I> checkAll(176 gena: Arb<A>,177 genb: Arb<B>,178 genc: Arb<C>,179 gend: Arb<D>,180 gene: Arb<E>,181 genf: Arb<F>,182 geng: Arb<G>,183 genh: Arb<H>,184 geni: Arb<I>,185 fn: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I) -> Unit186 ) {187 checkAll(gena, genb, genc, gend, gene, Arb.bind(genf, geng, genh, geni, ::Tuple4)) { a, b, c, d, e, (f, g, h, i) ->188 fn(a, b, c, d, e, f, g, h, i)189 }190 }191 public suspend fun <A, B, C, D, E, F, G, H, I, J> checkAll(192 gena: Arb<A>,193 genb: Arb<B>,194 genc: Arb<C>,195 gend: Arb<D>,196 gene: Arb<E>,197 genf: Arb<F>,198 geng: Arb<G>,199 genh: Arb<H>,200 geni: Arb<I>,201 genj: Arb<J>,202 fn: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, j: J) -> Unit203 ) {204 checkAll(205 gena,206 genb,207 genc,208 gend,209 gene,210 Arb.bind(genf, geng, genh, geni, genj, ::Tuple5)211 ) { a, b, c, d, e, (f, g, h, i, j) ->212 fn(a, b, c, d, e, f, g, h, i, j)213 }214 }215 public suspend fun forFew(216 iterations: Int,217 property: suspend PropertyContext.(Unit) -> Unit218 ): PropertyContext =219 checkAll(220 iterations,221 Arb.unit(),222 property223 )224}...

Full Screen

Full Screen

ResultTest.kt

Source:ResultTest.kt Github

copy

Full Screen

1package arrow.core.computations2import arrow.core.Eval3import arrow.core.Tuple104import arrow.core.composeErrors5import arrow.core.flatMap6import arrow.core.handleErrorWith7import arrow.core.redeemWith8import arrow.core.test.UnitSpec9import arrow.core.test.generators.result10import arrow.core.test.generators.suspend11import arrow.core.test.generators.throwable12import arrow.core.zip13import io.kotest.assertions.fail14import io.kotest.matchers.nulls.shouldNotBeNull15import io.kotest.matchers.result.shouldBeFailureOfType16import io.kotest.matchers.shouldBe17import io.kotest.property.Arb18import io.kotest.property.arbitrary.int19import io.kotest.property.arbitrary.map20import io.kotest.property.arbitrary.string21import io.kotest.property.checkAll22import kotlin.Result.Companion.failure23import kotlin.Result.Companion.success24import kotlin.coroutines.CoroutineContext25import kotlinx.coroutines.CompletableDeferred26import kotlinx.coroutines.CoroutineScope27import kotlinx.coroutines.Deferred28import kotlinx.coroutines.Dispatchers29import kotlinx.coroutines.async30import kotlinx.coroutines.awaitAll31import kotlinx.coroutines.suspendCancellableCoroutine32class ResultTest : UnitSpec() {33 init {34 "flatMap" {35 checkAll(Arb.result(Arb.int()), Arb.result(Arb.string())) { ints, strs ->36 val res = ints.flatMap { strs }37 if (ints.isFailure) res shouldBe ints38 else res shouldBe strs39 }40 }41 "handleErrorWith" {42 checkAll(Arb.result(Arb.int()), Arb.result(Arb.string())) { ints, strs ->43 val res = ints.handleErrorWith { strs }44 if (ints.isFailure) res shouldBe strs45 else res shouldBe ints46 }47 }48 "redeemWith" {49 checkAll(Arb.result(Arb.int()), Arb.result(Arb.string()), Arb.result(Arb.string())) { ints, failed, success ->50 val res = ints.redeemWith({ failed }, { success })51 if (ints.isFailure) res shouldBe failed52 else res shouldBe success53 }54 }55 "zip" {56 checkAll(57 Arb.result(Arb.int()),58 Arb.result(Arb.int()),59 Arb.result(Arb.int()),60 Arb.result(Arb.int()),61 Arb.result(Arb.int()),62 Arb.result(Arb.int()),63 Arb.result(Arb.int()),64 Arb.result(Arb.int()),65 Arb.result(Arb.int()),66 Arb.result(Arb.int()),67 ) { a, b, c, d, e, f, g, h, i, j ->68 val res = a.zip(b, c, d, e, f, g, h, i, j, ::Tuple10)69 val all = listOf(a, b, c, d, e, f, g, h, i, j)70 if (all.all { it.isSuccess }) res shouldBe success(71 Tuple10(72 a.getOrThrow(),73 b.getOrThrow(),74 c.getOrThrow(),75 d.getOrThrow(),76 e.getOrThrow(),77 f.getOrThrow(),78 g.getOrThrow(),79 h.getOrThrow(),80 i.getOrThrow(),81 j.getOrThrow()82 )83 ) else res shouldBe failure(84 composeErrors(85 a.exceptionOrNull(),86 b.exceptionOrNull(),87 c.exceptionOrNull(),88 d.exceptionOrNull(),89 e.exceptionOrNull(),90 f.exceptionOrNull(),91 g.exceptionOrNull(),92 h.exceptionOrNull(),93 i.exceptionOrNull(),94 j.exceptionOrNull()95 ).shouldNotBeNull()96 )97 }98 }99 "immediate values" {100 checkAll(Arb.result(Arb.int())) { res ->101 result {102 res.bind()103 } shouldBe res104 }105 }106 "suspended value" {107 checkAll(Arb.result(Arb.int())) { res ->108 result {109 res.suspend().bind()110 } shouldBe res111 }112 }113 "Rethrows immediate exceptions" {114 checkAll(Arb.throwable(), Arb.int(), Arb.int()) { e, a, b ->115 result<Int> {116 success(a).bind()117 success(b).suspend().bind()118 throw e119 } shouldBe failure(e)120 }121 }122 "result captures exception" {123 checkAll(Arb.throwable(), Arb.int(), Arb.int()) { e, a, b ->124 result<Int> {125 success(a).bind()126 success(b).suspend().bind()127 e.suspend()128 } shouldBe failure(e)129 }130 }131 "Can short-circuit from nested blocks" {132 checkAll(Arb.throwable()) { e ->133 result {134 val x = eval {135 failure<Int>(e).suspend().bind()136 5L137 }138 x.value()139 } shouldBe failure<Int>(e)140 }141 }142 "Can short-circuit suspended from nested blocks" {143 checkAll(Arb.throwable().map { failure<Int>(it) }) { res ->144 result {145 val x = eval {146 res.suspend().bind()147 5L148 }149 x.value()150 } shouldBe res151 }152 }153 "Can short-circuit after bind from nested blocks" {154 checkAll(Arb.throwable().map { failure<Int>(it) }) { res ->155 result {156 val x = eval {157 Eval.Now(1L).suspend().bind()158 res.suspend().bind()159 5L160 }161 1162 } shouldBe res163 }164 }165 "Short-circuiting cancels KotlinX Coroutines" {166 suspend fun completeOnCancellation(latch: CompletableDeferred<Unit>, cancelled: CompletableDeferred<Unit>): Unit =167 suspendCancellableCoroutine { cont ->168 cont.invokeOnCancellation {169 if (!cancelled.complete(Unit)) fail("cancelled latch was completed twice")170 else Unit171 }172 if (!latch.complete(Unit)) fail("latch was completed twice")173 else Unit174 }175 val scope = CoroutineScope(Dispatchers.Default)176 val latch = CompletableDeferred<Unit>()177 val cancelled = CompletableDeferred<Unit>()178 result {179 val deferreds: List<Deferred<Int>> = listOf(180 scope.async {181 completeOnCancellation(latch, cancelled)182 success(1).bind()183 },184 scope.async {185 latch.await()186 failure<Int>(RuntimeException()).bind()187 }188 )189 deferreds.awaitAll().sum()190 }.shouldBeFailureOfType<RuntimeException>()191 cancelled.await()192 }193 "Computation blocks run on parent context" {194 suspend fun currentContext(): CoroutineContext =195 kotlin.coroutines.coroutineContext196 val parentCtx = currentContext()197 result {198 currentContext() shouldBe parentCtx199 }200 }201 }202}...

Full Screen

Full Screen

ComparisonKtTest.kt

Source:ComparisonKtTest.kt Github

copy

Full Screen

1package arrow.core2import arrow.core.test.UnitSpec3import io.kotest.assertions.assertSoftly4import io.kotest.property.Arb5import io.kotest.property.checkAll6import io.kotest.matchers.shouldBe7import io.kotest.property.arbitrary.bind8import io.kotest.property.arbitrary.byte9import io.kotest.property.arbitrary.int10import io.kotest.property.arbitrary.long11import io.kotest.property.arbitrary.short12import io.kotest.property.arbitrary.string13data class Person(val age: Int, val name: String) : Comparable<Person> {14 companion object {15 val comparator: Comparator<Person> = Comparator { a, b ->16 val res = a.age.compareTo(b.age)17 if (res != 0) res18 else a.name.compareTo(b.name)19 }20 }21 override fun compareTo(other: Person): Int =22 comparator.compare(this, other)23}24fun Arb.Companion.person(): Arb<Person> =25 Arb.bind(Arb.int(), Arb.string(), ::Person)26class ComparisonKtTest : UnitSpec({27 "Arberic - sort2" {28 checkAll(Arb.person(), Arb.person()) { a, b ->29 val (first, second) = sort(a, b)30 val (aa, bb) = listOf(a, b).sorted()31 assertSoftly {32 first shouldBe aa33 second shouldBe bb34 }35 }36 }37 "Arberic - sort3" {38 checkAll(Arb.person(), Arb.person(), Arb.person()) { a, b, c ->39 val (first, second, third) = sort(a, b, c)40 val (aa, bb, cc) = listOf(a, b, c).sorted()41 assertSoftly {42 first shouldBe aa43 second shouldBe bb44 third shouldBe cc45 }46 }47 }48 "Arberic - sortAll" {49 checkAll(Arb.person(), Arb.array(Arb.person(), 0..50)) { a, aas ->50 val res = sort(a, *aas)51 val expected = listOf(a, *aas).sorted()52 res shouldBe expected53 }54 }55 "Arberic - comparator - sort2" {56 checkAll(Arb.person(), Arb.person()) { a, b ->57 val (first, second) = sort(a, b, Person.comparator)58 val (aa, bb) = listOf(a, b).sorted()59 assertSoftly {60 first shouldBe aa61 second shouldBe bb62 }63 }64 }65 "Arberic - comparator - sort3" {66 checkAll(Arb.person(), Arb.person(), Arb.person()) { a, b, c ->67 val (first, second, third) = sort(a, b, c, Person.comparator)68 val (aa, bb, cc) = listOf(a, b, c).sorted()69 assertSoftly {70 first shouldBe aa71 second shouldBe bb72 third shouldBe cc73 }74 }75 }76 "Byte - sort2" {77 checkAll(Arb.byte(), Arb.byte()) { a, b ->78 val (first, second) = sort(a, b)79 val (aa, bb) = listOf(a, b).sorted()80 assertSoftly {81 first shouldBe aa82 second shouldBe bb83 }84 }85 }86 "Byte - sort3" {87 checkAll(Arb.byte(), Arb.byte(), Arb.byte()) { a, b, c ->88 val (first, second, third) = sort(a, b, c)89 val (aa, bb, cc) = listOf(a, b, c).sorted()90 assertSoftly {91 first shouldBe aa92 second shouldBe bb93 third shouldBe cc94 }95 }96 }97 "Byte - sortAll" {98 checkAll(Arb.byte(), Arb.byte(), Arb.byte(), Arb.byte()) { a, b, c, d ->99 val res = sort(a, b, c, d)100 val expected = listOf(a, b, c, d).sorted()101 res shouldBe expected102 }103 }104 "Short - sort2" {105 checkAll(Arb.short(), Arb.short()) { a, b ->106 val (first, second) = sort(a, b)107 val (aa, bb) = listOf(a, b).sorted()108 assertSoftly {109 first shouldBe aa110 second shouldBe bb111 }112 }113 }114 "Short - sort3" {115 checkAll(Arb.short(), Arb.short(), Arb.short()) { a, b, c ->116 val (first, second, third) = sort(a, b, c)117 val (aa, bb, cc) = listOf(a, b, c).sorted()118 assertSoftly {119 first shouldBe aa120 second shouldBe bb121 third shouldBe cc122 }123 }124 }125 "Short - sortAll" {126 checkAll(Arb.short(), Arb.short(), Arb.short(), Arb.short()) { a, b, c, d ->127 val res = sort(a, b, c, d)128 val expected = listOf(a, b, c, d).sorted()129 res shouldBe expected130 }131 }132 "Int - sort2" {133 checkAll(Arb.int(), Arb.int()) { a, b ->134 val (first, second) = sort(a, b)135 val (aa, bb) = listOf(a, b).sorted()136 first shouldBe aa137 second shouldBe bb138 }139 }140 "Int - sort3" {141 checkAll(Arb.int(), Arb.int(), Arb.int()) { a, b, c ->142 val (first, second, third) = sort(a, b, c)143 val (aa, bb, cc) = listOf(a, b, c).sorted()144 assertSoftly {145 first shouldBe aa146 second shouldBe bb147 third shouldBe cc148 }149 }150 }151 "Int - sortAll" {152 checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d ->153 val res = sort(a, b, c, d)154 val expected = listOf(a, b, c, d).sorted()155 res shouldBe expected156 }157 }158 "Long - sort2" {159 checkAll(Arb.long(), Arb.long()) { a, b ->160 val (first, second) = sort(a, b)161 val (aa, bb) = listOf(a, b).sorted()162 assertSoftly {163 first shouldBe aa164 second shouldBe bb165 }166 }167 }168 "Long - sort3" {169 checkAll(Arb.long(), Arb.long(), Arb.long()) { a, b, c ->170 val (first, second, third) = sort(a, b, c)171 val (aa, bb, cc) = listOf(a, b, c).sorted()172 assertSoftly {173 first shouldBe aa174 second shouldBe bb175 third shouldBe cc176 }177 }178 }179 "Long - sortAll" {180 checkAll(Arb.long(), Arb.long(), Arb.long(), Arb.long()) { a, b, c, d ->181 val res = sort(a, b, c, d)182 val expected = listOf(a, b, c, d).sorted()183 res shouldBe expected184 }185 }186})...

Full Screen

Full Screen

StreamSpec.kt

Source:StreamSpec.kt Github

copy

Full Screen

1package arrow.fx.coroutines.stream2import arrow.fx.coroutines.ArrowFxSpec3import arrow.fx.coroutines.suspend4import io.kotest.property.Arb5import io.kotest.property.Shrinker6import io.kotest.property.arbitrary.arb7import io.kotest.property.arbitrary.bind8import io.kotest.property.arbitrary.choice9import io.kotest.property.arbitrary.choose10import io.kotest.property.arbitrary.constant11import io.kotest.property.arbitrary.list12import io.kotest.property.arbitrary.map13import kotlin.math.abs14/**15 * A Spec that allows you to specify depth for all `Arb` used inside the spec.16 *17 * A `Int.Range` of `0..10` is equivalent to `Arb.list` as where it generates `0..100` by default.18 *19 * `Stream` is randomly generated among it's constructors, but it guarantees a depth of maxmimum `10x range.last`.20 * So for `0..10` it will generate at most a `Stream` with `10` `Chunk`s of `10` elements.21 */22abstract class StreamSpec(23 iterations: Int = 350,24 val depth: IntRange = 0..100,25 spec: StreamSpec.() -> Unit = {}26) : ArrowFxSpec(iterations) {27 init {28 spec()29 }30 fun Arb.Companion.long(range: LongRange = Long.MIN_VALUE..Long.MAX_VALUE): Arb<Long> {31 val edgecases = listOf(0L, 1, -1, Long.MAX_VALUE, Long.MIN_VALUE).filter { it in range }32 return arb(LongShrinker(range), edgecases) { it.random.nextLong(range.first, range.last) }33 }34 class LongShrinker(private val range: LongRange) : Shrinker<Long> {35 override fun shrink(value: Long): List<Long> =36 when (value) {37 0L -> emptyList()38 1L, -1L -> listOf(0)39 else -> {40 val a = listOf(abs(value), value / 3, value / 2, value * 2 / 3)41 val b = (1..5L).map { value - it }.reversed().filter { it > 0 }42 (a + b).distinct().filter { it in range && it != value }43 }44 }45 }46 inline fun <reified O, R> Arb.Companion.pull(47 arbO: Arb<O>,48 arbR: Arb<R>,49 range: IntRange = depth50 ): Arb<Pull<O, R>> =51 Arb.choice<Pull<O, R>>(52 Arb.bind(Arb.stream(arbO, range), arbR) { s, r ->53 s.asPull().map { r }54 },55 arbR.map { Pull.just(it) } as Arb<Pull<O, R>>,56 arbR.map { Pull.effect { it } }57 )58 fun <O> Arb.Companion.stream(59 arb: Arb<O>,60 range: IntRange = depth61 ): Arb<Stream<O>> =62 Arb.choose(63 10 to Arb.list(arb, range).map { os ->64 Stream.iterable(os)65 },66 10 to Arb.list(arb, range).map { os ->67 Stream.iterable(os).unchunk()68 },69 5 to arb.map { fo -> Stream.effect { fo } },70 1 to Arb.bind(Arb.suspended(arb), Arb.list(arb, range), Arb.suspended(Arb.constant(Unit))) { acquire, use, release ->71 Stream.bracketCase(acquire, { _, _ -> release.invoke() }).flatMap { Stream.iterable(use) }72 }73 )74 fun <O> Arb.Companion.suspended(arb: Arb<O>): Arb<suspend () -> O> =75 arb.map { suspend { it.suspend() } }76}...

Full Screen

Full Screen

Arb.Companion.unit

Using AI Code Generation

copy

Full Screen

1Arb . int ( 0 , 100 ). bind { x ->2Arb . int ( 0 , 100 ). bind { y ->3Arb . int ( 0 , 100 ). bind { z ->4Arb . int ( 0 , 100 ). map { w ->5Arb . int ( 0 , 100 ). map { v ->6Arb . int ( 0 , 100 ). map { u ->7Arb . int ( 0 , 100 ). map { t ->8Arb . int ( 0 , 100 ). map { s ->9Arb . int ( 0 , 100 ). map { r ->10Arb . int ( 0 , 100 ). map { q ->11Arb . int ( 0 , 100 ). map { p ->

Full Screen

Full Screen

Arb.Companion.unit

Using AI Code Generation

copy

Full Screen

1val arb = Arb.bind( Arb.int(), Arb.int(), Arb.int() ) { a, b, c -> Triple( a, b, c ) }2val arb = Arb.bind( Arb.int(), Arb.int(), Arb.int(), Arb.int() ) { a, b, c, d -> Quad( a, b, c, d ) }3val arb = Arb.bind( Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int() ) { a, b, c, d, e -> Quint( a, b, c, d, e ) }4val arb = Arb.bind( Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int() ) { a, b, c, d, e, f -> Sext( a, b, c, d, e, f ) }5val arb = Arb.bind( Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int() ) { a, b, c, d, e, f, g -> Sept( a, b, c, d, e, f, g ) }6val arb = Arb.bind( Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int() ) { a, b, c, d, e, f, g, h -> Oct( a, b, c, d, e, f, g, h ) }7val arb = Arb.bind( Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int(), Arb.int() ) { a, b, c, d, e, f, g, h, i -> Non( a, b, c, d, e, f, g, h, i ) }

Full Screen

Full Screen

Arb.Companion.unit

Using AI Code Generation

copy

Full Screen

1val arb = Arb.bind( Arb.int( 0 , 100 ), Arb.int( 0 , 100 )) { a, b -> a + b }2val arb = Arb.bind( Arb.int( 0 , 100 ), Arb.int( 0 , 100 )) { a, b -> a + b }.unit()3val arb = Arb.bind( Arb.int( 0 , 100 ), Arb.int( 0 , 100 )) { a, b -> a + b }4val arb = Arb.bind( Arb.int( 0 , 100 ), Arb.int( 0 , 100 )) { a, b -> a + b }.unit()5val arb = Arb.bind( Arb.int( 0 , 100 ), Arb.int( 0 , 100 )) { a, b -> a + b }6val arb = Arb.bind( Arb.int( 0 , 100 ), Arb.int( 0 , 100 )) { a, b -> a + b }.unit()7val arb = Arb.bind( Arb.int( 0 , 100 ), Arb.int( 0 , 100 )) { a, b -> a + b }8val arb = Arb.bind( Arb.int( 0 , 100 ), Arb.int( 0 , 100 )) { a, b -> a + b }.unit()9val arb = Arb.bind( Arb.int( 0 , 100 ), Arb.int( 0 , 100 )) { a, b -> a + b }10val arb = Arb.bind( Arb.int( 0 , 100 ), Arb.int( 0 , 100 )) { a, b -> a + b }.unit()11val arb = Arb.bind( Arb.int( 0 , 100 ), Arb.int( 0 , 100 )) { a, b -> a + b }12val arb = Arb.bind( Arb.int( 0 , 100 ), Arb.int( 0 , 100 )) { a, b -> a

Full Screen

Full Screen

Arb.Companion.unit

Using AI Code Generation

copy

Full Screen

1 fun test2() {2 Arb.bind(3 Arb.int(1..20),4 Arb.int(1..20)5 ) { x, y ->6 }.checkAll()7 }8 fun test3() {9 Arb.bind(10 Arb.int(1..20),11 Arb.int(1..20),12 Arb.int(1..20)13 ) { x, y, z ->14 }.checkAll()15 }16 fun test4() {17 Arb.bind(18 Arb.int(1..20),19 Arb.int(1..20),20 Arb.int(1..20),21 Arb.int(1..20)22 ) { x, y, z, a ->23 }.checkAll()24 }25 fun test5() {26 Arb.bind(27 Arb.int(1..20),28 Arb.int(1..20),29 Arb.int(1..20),30 Arb.int(1..20),31 Arb.int(1..20)32 ) { x, y, z, a, b ->33 }.checkAll()34 }

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