Hey :slightly_smiling_face: I’m currently fiddling...
# kotest
m
Hey 🙂 I’m currently fiddling around with
property-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:
Copy code
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 🤔 .
s
Docs are prob out of date.
let me check
updated to reflect the current state
m
Cool thanks 🙂
👍🏻 1
If I have e.g. a data class just containing .. lets say an
Int
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.:
Copy code
<http://Arb.int|Arb.int>().map { MyDataClass(it) }
to define an Arb for
MyDataClass
?
s
absolutely
or
Arb.bind(<http://Arb.int|Arb.int>()) { MyDataClass(it) }
map is great for single values
bind is good for > 1
Arb.bind(<http://Arb.int|Arb.int>(), Arb.string()) { a,b -> MyDataClass(a,b) }
m
ok cool. Thanks for your help 🙂 👍
👍🏻 1