Best Kotest code snippet using io.kotest.property.exhaustive.cartesian.Exhaustive.Companion.cartesianPairs
cartesian.kt
Source:cartesian.kt
1package io.kotest.property.exhaustive2import io.kotest.property.Exhaustive3fun <A, B, C> Exhaustive<A>.cartesian(other: Exhaustive<B>, f: (A, B) -> C): Exhaustive<C> {4 val cs = values.flatMap { _a ->5 other.values.map { _b ->6 f(_a, _b)7 }8 }9 return cs.exhaustive()10}11fun <A, B> Exhaustive<A>.cartesianPairs(other: Exhaustive<B>): Exhaustive<Pair<A, B>> {12 val pairs = values.flatMap { _a ->13 other.values.map { _b ->14 Pair(_a, _b)15 }16 }17 return pairs.exhaustive()18}19/**20 * Returns the cartesian join of this exhaustive with itself, with the results as pairs.21 */22fun <A> Exhaustive<A>.cartesianPairs(): Exhaustive<Pair<A, A>> {23 val cs = values.flatMap { _a ->24 values.map { _b ->25 Pair(_a, _b)26 }27 }28 return cs.exhaustive()29}30fun <A, B, C> Exhaustive.Companion.cartesian(a: Exhaustive<A>, b: Exhaustive<B>, f: (A, B) -> C): Exhaustive<C> {31 val cs = a.values.flatMap { _a ->32 b.values.map { _b ->33 f(_a, _b)34 }35 }36 return cs.exhaustive()37}38fun <A, B> Exhaustive.Companion.cartesianPairs(a: Exhaustive<A>, b: Exhaustive<B>): Exhaustive<Pair<A, B>> {39 val pairs = a.values.flatMap { _a ->40 b.values.map { _b ->41 Pair(_a, _b)42 }43 }44 return pairs.exhaustive()45}46fun <A, B, C, D> Exhaustive.Companion.cartesian(47 a: Exhaustive<A>,48 b: Exhaustive<B>,49 c: Exhaustive<C>,50 f: (A, B, C) -> D51): Exhaustive<D> {52 val ds = a.values.flatMap { _a ->53 b.values.flatMap { _b ->54 c.values.map { _c ->55 f(_a, _b, _c)56 }57 }58 }59 return ds.exhaustive()60}61fun <A, B, C, D, E> Exhaustive.Companion.cartesian(62 a: Exhaustive<A>,63 b: Exhaustive<B>,64 c: Exhaustive<C>,65 d: Exhaustive<D>,66 f: (A, B, C, D) -> E67): Exhaustive<E> {68 val es = a.values.flatMap { _a ->69 b.values.flatMap { _b ->70 c.values.flatMap { _c ->71 d.values.map { _d ->72 f(_a, _b, _c, _d)73 }74 }75 }76 }77 return es.exhaustive()78}79fun <A, B, C, D, E, F> Exhaustive.Companion.cartesian(80 a: Exhaustive<A>,81 b: Exhaustive<B>,82 c: Exhaustive<C>,83 d: Exhaustive<D>,84 e: Exhaustive<E>,85 f: (A, B, C, D, E) -> F86): Exhaustive<F> {87 val fs = a.values.flatMap { _a ->88 b.values.flatMap { _b ->89 c.values.flatMap { _c ->90 d.values.flatMap { _d ->91 e.values.map { _e ->92 f(_a, _b, _c, _d, _e)93 }94 }95 }96 }97 }98 return fs.exhaustive()99}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!