Mervyn McCreight
12/15/2020, 3:52 PMproperty-based-testing
in Kotest. I want to create a custom arbitrary
based on already defined arbitraries
. I found this page in the documentation about it:
https://kotest.io/docs/proptest/custom-generators.html#arbitrary
In the documentation there is a code snippet about doing it:
val personArb = arbitrary { rs ->
val names = Arb.string().values(rs)
val ages = <http://Arb.int|Arb.int>().values(rs)
names.zip(ages).map { (name, age) -> Person(name.value, age.value) }
}
The concept is clear, but the function values(RandomSource)
is deprecated. What am I supposed to use as an alternative in this case? Would it be generate(RandomSource)
? The replacement description is not really applicable for this particular case I think. Using samples(RandomSource)
seems wrong, because I think it makes sense to keep the edge-cases of the arbs here 🤔 .sam
12/15/2020, 4:05 PMMervyn McCreight
12/15/2020, 4:25 PMInt
and I need an arb creating instances of that data class.
Would it be fine to just use map
on the given Arb?
E.g.:
<http://Arb.int|Arb.int>().map { MyDataClass(it) }
to define an Arb for MyDataClass
?sam
12/15/2020, 4:28 PMArb.bind(<http://Arb.int|Arb.int>()) { MyDataClass(it) }
Arb.bind(<http://Arb.int|Arb.int>(), Arb.string()) { a,b -> MyDataClass(a,b) }
Mervyn McCreight
12/15/2020, 4:30 PM