Hey suppose I have a Student like `data class Stud...
# kotest
a
Hey suppose I have a Student like
data class Student(val id: Int, val name: String)
and I’m trying to build a Arb of Student like
Copy code
fun Arb.Companion.student(
    id: Arb<Int> = positiveInt(),
    name: Arb<String> = string()
): Arb<Student> = arbitrary { rs ->
    Student(
        id.next(rs),
        name.next(rs) // or name.bind() and ignore rs?
    )
}
Should I call
bind
or
next
with the current randomSource?
e
I think you can do
Arb.bind(id, name, ::Student)
a
?
m
@André Martins I'd recommend using .bind. that will make sure all edgecases from all arbs are incorporated
a
Ok, but then when I do
Arb.student().next(myRandomSource)
will it pass the random source to all arbs?
m
yep that’s right. next will call the random sample and discards all edgecases
a
ok thx
m
hence if i were you, i’d do your second approach as in
Copy code
fun Arb.Companion.student(
    id: Arb<Int> = positiveInt(),
    name: Arb<String> = string()
): Arb<Student> = arbitrary { 
    Student(
        id.bind(),
        name.bind()
    )
}
👍 1
🔝 1
internally that will basically do all the correct things including the propagation of random source, as well as settings for edgecases - both for id-arb and name arb, and all other composed arbs therein
a
Basically we should only use next outside and bind for composition right?
e
My example was shorthand of the above.
Arb.bind(id, name, ::Student)
takes the id and name arb and binds them using the Student constructor. 🙂
👍 2
m
yep that’s right. outside of the
arbitrary { }
scope, that’s about the only thing possible. within the builder you can compose a lot more complex arbitraries
👍 1
a
Oh ok I rather call constructor explicitly
thanks guys!
👌 1