package ru.dbotthepony.mc.otm.tests

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.mc.otm.core.addSorted
import java.util.Random

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)
	}
}
