Add Comparator tests from OTM
This commit is contained in:
parent
7278a699aa
commit
11e71361f7
@ -0,0 +1,35 @@
|
|||||||
|
package ru.dbotthepony.kommons.test
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntComparators
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import ru.dbotthepony.kommons.collect.addSorted
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
|
object ComparatorTests {
|
||||||
|
@Test
|
||||||
|
@DisplayName("Comparator tests")
|
||||||
|
fun test() {
|
||||||
|
val sortedList = mutableListOf(1, 4, 6)
|
||||||
|
sortedList.addSorted(2, IntComparators.NATURAL_COMPARATOR)
|
||||||
|
sortedList.addSorted(3, IntComparators.NATURAL_COMPARATOR)
|
||||||
|
sortedList.addSorted(7, IntComparators.NATURAL_COMPARATOR)
|
||||||
|
sortedList.addSorted(-1, IntComparators.NATURAL_COMPARATOR)
|
||||||
|
|
||||||
|
assertEquals(mutableListOf(-1, 1, 2, 3, 4, 6, 7), sortedList)
|
||||||
|
|
||||||
|
val rand = Random()
|
||||||
|
val sorted2 = ArrayList<Int>()
|
||||||
|
|
||||||
|
for (i in 0 .. 100) {
|
||||||
|
sorted2.addSorted(rand.nextInt(-100, 100), IntComparators.NATURAL_COMPARATOR)
|
||||||
|
}
|
||||||
|
|
||||||
|
val sorted22 = ArrayList(sorted2)
|
||||||
|
sorted22.sort()
|
||||||
|
|
||||||
|
assertEquals(sorted22, sorted2)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user