55
66package tests.contract.set
77
8+ import kotlinx.collections.immutable.implementations.immutableSet.PersistentHashSet
89import kotlinx.collections.immutable.persistentHashSetOf
10+ import kotlinx.collections.immutable.minus
11+ import kotlinx.collections.immutable.toPersistentHashSet
912import kotlin.test.Test
1013import kotlin.test.assertEquals
1114import kotlin.test.assertTrue
@@ -27,4 +30,30 @@ class PersistentHashSetTest {
2730 assertEquals(set2, builder.build().toSet())
2831 assertEquals(set2, builder.build())
2932 }
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+ }
3059}
0 commit comments