Does this look correct for an `Arb.frequency` func...
# kotest
s
Does this look correct for an
Arb.frequency
function? And would there be any interest for this operator? You could easily derive
choice
from this operator. It was inspired by
frequency
from
ScalaTest
, in contrast to
choice
it takes a
weight
per
Arb
.
s
We have Arb.choose, is that sufficient for what you need?
Copy code
/**
 * Returns a stream of values based on weights:
 *
 * Arb.choose(1 to 'A', 2 to 'B') will generate 'A' 33% of the time
 * and 'B' 66% of the time.
 *
 * @throws IllegalArgumentException If any negative weight is given or only
 * weights of zero are given.
 */
fun <A : Any> Arb.Companion.choose(a: Pair<Int, A>, b: Pair<Int, A>, vararg cs: Pair<Int, A>)
s
No, that isn’t sufficient for me. I’m using this to create an
Arb
from a
sealed class
but I want the create an
Arb
for every case, and I don’t want them to occur in the same frequency. Example:
Copy code
fun <A> pureIO(arb: Arb<A>): Arb<IO<A>> = arb.map { IO.just(it) }
fun failingIO(): Arb<IO<Nothing>> = Arb.throwable().map { IO.raiseError(it) }

fun <A> <http://Arb.Companion.io|Arb.Companion.io>(arb: Arb<A>): Arb<IO<A>> =
 Arb.frequency(5 to pureIO(arb), 1 to failingIO())
s
Thats what choose does?
s
Yes, but based on
A
not on
Arb<A>
Pair<Int, A>
vs
Pair<Int, Arb<A>>
s
Oh
I have added to master a version that accepts arbs rather than values. I've also added in aliases to frequency to aid discoverability for those from a haskell quickcheck background. https://github.com/kotest/kotest/issues/1499
s
Awesome 🙌