https://kotlinlang.org logo
Title
d

dave08

05/19/2021, 11:42 AM
Is there any way to use one arb's result to feed the function params for another arb and make a pair out of them (arb1, arb2 cartesian product)?
s

sam

05/19/2021, 11:43 AM
map ?
d

dave08

05/19/2021, 11:43 AM
In map there's no RandomSource
s

sam

05/19/2021, 11:44 AM
hmmm true
d

dave08

05/19/2021, 11:44 AM
And it'll only produce one arb2 per arb1
s

sam

05/19/2021, 11:45 AM
map could return a pair, but yeah no RS
d

dave08

05/19/2021, 11:45 AM
I need a set of Arb2's for each Arb1, and end up with Pair<Arb1, Arb2> as a cartesian product
s

sam

05/19/2021, 11:46 AM
then what are you doing with the pair
d

dave08

05/19/2021, 11:46 AM
using it in checkAll to run the tests
s

sam

05/19/2021, 11:47 AM
so you want to do checkAll(arb1, arb2) { a, b -> }
d

dave08

05/19/2021, 11:47 AM
There's a Context object for setting up the repositories and the useCase, and there's a Request object that needs to be set up based on the Context but in many permutations...
yes
s

sam

05/19/2021, 11:48 AM
checkAll(arb1) { a ->
  checkAll(Arb2(a)) { b ->
  }
}
d

dave08

05/19/2021, 11:48 AM
Oh... I see
s

sam

05/19/2021, 11:48 AM
will that do what you want ?
d

dave08

05/19/2021, 11:49 AM
I guess that would do it... but there's nothing to check in the outer checkAll... 🙃
s

sam

05/19/2021, 11:50 AM
doesn't matter, you're just nesting
d

dave08

05/19/2021, 11:50 AM
Ok, I guess that'll do, thanks!
s

sam

05/19/2021, 11:51 AM
cool
m

mitch

05/19/2021, 12:26 PM
@dave08 you may be interested in
Arb<A>.flatMap(fn: (A) -> Arb<B>): Arb<B>
d

dave08

05/19/2021, 12:26 PM
I don't think that has a RandomSource either...
Actually... maybe I wouldn't need one there?
m

mitch

05/19/2021, 12:29 PM
If you need access to rs you can do
arb.flatMap { a -> arbitrary { rs -> ... } }
🤩 1
Under the hood kotest will propagate that from the time data is generated from the arb so it's better than nesting check all
👍🏻 1
d

dave08

05/19/2021, 12:31 PM
That could be a good idea! I'll give it a try, thanks!
Actually, in my current case it's much simpler than I thought:
val contextWithRequestArb = contextArb.flatMap { context ->
        requestArb(context.currState).map { request ->
                context to request
        }
    }
But sometimes that rs is needed, so it's good to know that trick too!
m

mitch

05/19/2021, 1:19 PM
Awesome!