atara
10/08/2021, 2:51 AMArb.pair(ArbA, ArbB).filter {it.first != it.second}
But then the result is a pair that I need to unpack for the test.
Is there a better way?mitch
10/08/2021, 12:25 PMval arbAB = Arb.pair(arbA, arbB).filter {it.first != it.second}
checkAll(arbAB, arbC) { (a, b), c -> // notice the bracket
...
}
If your intention is to compose dependent arbs, where you want to create a more complex object, there is also arb.flatMap
which you can use to compose them.
data class Foo(val first: A, val second: B)
val arbA: Arb<A> = ...
fun arbB(a: A): Arb<B> = ...
// kotest 4.x
val arbFoo = arbA.flatMap { a ->
arbB(a).map { b -> Foo(a, b) }
}
in kotest 5.x, we have enhanced the arbitrary builder by leveraging continuation. With the new builder you’ll be able to do this
// this is available in kotest 5.x
val arbFoo: Arb<Foo> = arbitrary {
val a: A = arbA.bind()
val b: B = arbB(a).bind()
Foo(a, b)
}
in terms of checkAll, we’re still trying to figure out how might we improve the ergonomics for cases like this, e.g. enabling syntax like following.
checkAll {
val a: A = arbA.value()
val b: B = arbB.filter { it != a }.value()
// etc...
}
There are still some challenges that we need to solve, so that’s not ready yet.atara
10/11/2021, 11:24 PM