André Martins
04/01/2022, 9:14 AMfun Arb.Companion.student(): Arb<Student> = arbitrary { rs ->
Student(
id = Arb.uuid(V4,false).next(rs)
name = Arb.string().next(rs),
number = <http://Arb.int|Arb.int>().next(rs), ...
)
}
What can I add here to lock the number I which my generated student have?
Arb.student().<here>?
// Something like
Arb.student().with(number, 123)
Anyway I can do this?Emil Kantis
04/01/2022, 9:17 AMArb.student().copy(number = 123)
perhaps?André Martins
04/01/2022, 9:18 AMAndré Martins
04/01/2022, 9:19 AMphldavies
04/01/2022, 9:32 AMfun Arb.Companion.student(
idArb: Arb<UUID> = uuid(V4, false),
nameArb: Arb<String> = string(),
numberArb: Arb<Int> = int()
): Arb<Student> = arbitrary {
Student(
id = idArb.bind(),
name = nameArb.bind(),
number = numberArb.bind(),
)
}
val myStudent = Arb.student(numberArb = Arb.constant(123)).single()
phldavies
04/01/2022, 9:34 AMval namedStudent = Arb.student(nameArb = Arb.name().map { (first, last) -> "$last, $first" }).single()
André Martins
04/01/2022, 9:34 AMphldavies
04/01/2022, 9:36 AMArb
, i.e.
fun Student.Companion.arbitrary(...) = ...
allowing for
Student.arbitrary()
rather than
Arb.student()
It’s just kept Arb
a little cleaner as base arbitrariesAndré Martins
04/01/2022, 9:37 AMEmil Kantis
04/01/2022, 9:39 AMArb.data<Student>(mapOf(Int::class to Arb.constant(123))
to generate the entire thing.. 🙂 Arb.data<Student>()
will create your first exmaple there, though I’m unsure if uuid binding will work without adding it explicitly.. Phil’s approach gives nice flexibility from use sites though, gonna try that out myself 🙂André Martins
04/01/2022, 9:41 AMLeoColman
04/01/2022, 6:31 PMLeoColman
04/01/2022, 6:32 PMArb.student().map { it.copy(number = 123) }