Common shuffle/shuffled with the specified random source

KT-17261, KT-9010
This commit is contained in:
Ilya Gorbunov
2018-07-03 03:45:09 +03:00
parent cc031e3a40
commit 7e4528e217
4 changed files with 42 additions and 11 deletions
@@ -5,6 +5,7 @@
package test.collections
import kotlin.random.Random
import kotlin.test.*
@@ -114,4 +115,16 @@ class MutableCollectionTest {
assertEquals(list.size, shuffled.distinct().size)
}
@Test fun shuffledPredictably() {
val list = List(10) { it }
val shuffled1 = list.shuffled(Random(1))
val shuffled11 = list.shuffled(Random(1))
assertEquals(shuffled1, shuffled11)
assertEquals("[1, 4, 0, 6, 2, 8, 9, 7, 3, 5]", shuffled1.toString())
val shuffled2 = list.shuffled(Random(42))
assertEquals("[5, 0, 4, 9, 2, 8, 1, 7, 6, 3]", shuffled2.toString())
}
}