dave08
07/21/2024, 11:37 AMrandom
?CLOVIS
07/22/2024, 7:42 AMrandom.nextInt
and ensure you always have different values each time it is called within a single test?CLOVIS
07/22/2024, 8:36 AMprivate val randomIntCache by prepared { HashSet<Int>() }
suspend fun TestDsl.randomUniqueInt(): Int {
val random = random()
val randomIntCache = randomIntCache()
while (coroutineContext.isActive) {
val candidate = random.nextInt()
if (candidate !in randomIntCache) {
randomIntCache += candidate
return candidate
}
}
}
As always with random values, it is your responsibility that nextInt
calls are always executed in the exact same order on every execution, otherwise setting the seed won't reproduce the exact same executionsdave08
07/22/2024, 10:11 AM