5
5
6
6
package tests.contract.set
7
7
8
+ import kotlinx.collections.immutable.implementations.immutableSet.PersistentHashSet
8
9
import kotlinx.collections.immutable.persistentHashSetOf
10
+ import kotlinx.collections.immutable.minus
11
+ import kotlinx.collections.immutable.toPersistentHashSet
9
12
import kotlin.test.Test
10
13
import kotlin.test.assertEquals
11
14
import kotlin.test.assertTrue
@@ -27,4 +30,30 @@ class PersistentHashSetTest {
27
30
assertEquals(set2, builder.build().toSet())
28
31
assertEquals(set2, builder.build())
29
32
}
33
+
34
+ /* *
35
+ * Test from issue: https://github.com/Kotlin/kotlinx.collections.immutable/issues/144
36
+ */
37
+ @Test
38
+ fun `removing multiple batches should leave only remaining elements` () {
39
+ val firstBatch = listOf (4554 , 9380 , 4260 , 6602 )
40
+ val secondBatch = listOf (1188 , 14794 )
41
+ val extraElement = 7450
42
+
43
+ val set = firstBatch.plus(secondBatch).plus(extraElement).toPersistentHashSet()
44
+ val result = set.minus(firstBatch.toPersistentHashSet()).minus(secondBatch)
45
+ assertEquals(1 , result.size)
46
+ assertEquals(extraElement, result.first())
47
+ }
48
+
49
+ @Test
50
+ fun `after removing elements from one collision the remaining one element must be promoted to the root` () {
51
+ val set1: PersistentHashSet <Int > = persistentHashSetOf(0 , 32768 , 65536 ) as PersistentHashSet <Int >
52
+ val set2: PersistentHashSet <Int > = persistentHashSetOf(0 , 32768 ) as PersistentHashSet <Int >
53
+
54
+ val expected = persistentHashSetOf(65536 )
55
+ val actual = set1 - set2
56
+
57
+ assertEquals(expected, actual)
58
+ }
30
59
}
0 commit comments