How can I ensure that `Arb.set` or `Arb.list` gene...
# kotest
d
How can I ensure that
Arb.set
or
Arb.list
generates unique entries by my entity id?
s
What do you mean ?
d
Arb.list(entity1Arb()), shouldn't generate any duplicate `id`s in the list.
Which is what happens in a real database... also, sometimes there might be other unique keys...
So far, all I see is making a mutable set to store all currently generated values, and add to it in the
filter
method on the lists' arb and check if the current one was already added.
s
well Arb.set will generate only unique values because its a set
d
So, if I would override the equals() function, I could make sure id is the unique key and then map it to a list... but when I have multiple such keys, I guess that wouldn't work anymore...
s
You could create an overriden Arb.set that accepts a function for equality
👍🏼 1
d
There's no
Arb.set(...).toList()
?
s
no
d
Actually, in my case, I need to pass to varargs... I'm probably doing this wrong... My repo needs to be initialized with a random list of customers (apart from the one I need for the test).. I guess I could use next() and convert it after.
s
next() or single() will bring back one random value from an Arb
122 Views