https://kotlinlang.org logo
Title
d

dave08

05/18/2021, 2:26 PM
How can I ensure that
Arb.set
or
Arb.list
generates unique entries by my entity id?
s

sam

05/18/2021, 2:41 PM
What do you mean ?
d

dave08

05/18/2021, 2:42 PM
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

sam

05/18/2021, 2:46 PM
well Arb.set will generate only unique values because its a set
d

dave08

05/18/2021, 2:49 PM
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

sam

05/18/2021, 2:50 PM
You could create an overriden Arb.set that accepts a function for equality
👍🏼 1
d

dave08

05/18/2021, 3:51 PM
There's no
Arb.set(...).toList()
?
s

sam

05/18/2021, 3:51 PM
no
d

dave08

05/18/2021, 3:55 PM
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

sam

05/18/2021, 3:55 PM
next() or single() will bring back one random value from an Arb