Hi, just getting to grips with kotest 4+. It looks...
# kotest
d
Hi, just getting to grips with kotest 4+. It looks great. I have a few questions. 1. Where you use
Arb.choice(Arb.long(1L..10L), Arb.long(-10L..-1L)).next(rs)
, I totally didn't expect
0
to be generated, or
Long.MAX/MIN
. This seems to be because the Arb.long(...) has edgecases defined, and because choice takes Gen instances:
choice(vararg gens: Gen<A>)
which includes all the Arb.edgecases as well because it calls Gen.generate, which combines them with the arb.values. Wondering if it should be a
Arb choice(vararg arbs: Arb<A>)
, or some other differently named function to use the values from the arb, such that
Arb.choice(...).next(rs)
would only return values passed arbs, and
Arb.choice(...).edgecases()
would allow access to the edge cases of the passed arbs. I guess it's not a question but a suggestion, be interested to hear your thoughts. I'm thinking something like this
Copy code
fun <A> Arb.Companion.combine(vararg arbs: Arb<A>): Arb<A> = arb (arbs.flatMap(Arb<A>::edgecases)){ rs ->
    val iters = arbs.map { it.values(rs).iterator() }
    fun next(): Sample<A>? {
        val iter = iters.shuffled(rs.random).first()
        val x = if (iter.hasNext()) iter.next() else null
        return x
    }
    sequence {
        while (true) {
            var next: Sample<A>? = null
            while (next == null)
                next = next()
            yield(next.value)
        }
    }
}
I suspect you're going to tell me something like this already exists ­čÖé If so - apologies. 2. How do you envisage Arb.orNull() working?