toHashSet is suboptimal for inputs with a lot of duplicates #KT-23142
This commit is contained in:
@@ -8,6 +8,7 @@ package test.text
|
||||
import kotlin.test.*
|
||||
import test.*
|
||||
import test.collections.behaviors.iteratorBehavior
|
||||
import test.collections.behaviors.setBehavior
|
||||
import test.collections.compare
|
||||
import kotlin.math.sign
|
||||
import kotlin.random.Random
|
||||
@@ -1651,4 +1652,19 @@ ${" "}
|
||||
assertFailsWith<IndexOutOfBoundsException> { "".elementAt(0) }
|
||||
assertFailsWith<IndexOutOfBoundsException> { "a c".elementAt(-1) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun toHashSet() {
|
||||
compare(hashSetOf('A', 'B', 'C'), "ACAABBAC".toHashSet()) { setBehavior() }
|
||||
|
||||
buildString {
|
||||
repeat(100) { append('1') }
|
||||
append('2')
|
||||
repeat(100) { append('3') }
|
||||
append('4')
|
||||
repeat(100) { append('5') }
|
||||
}.let {
|
||||
compare(hashSetOf('1', '2', '3', '4', '5'), it.toHashSet()) { setBehavior() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user