package ru.dbotthepony.kstarbound.test

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import ru.dbotthepony.kstarbound.collect.RandomSubList

object CollectionTests {
	@Test
	@DisplayName("Sublists test")
	fun subLists() {
		val list = ArrayList<Int>()
		val list2 = ArrayList<Int>()

		for (i in 0 .. 1000) {
			list.add(i)
			list2.add(i)
		}

		val sub0 = list.subList(40, 80)
		val sub1 = RandomSubList(list2, 40, 80)

		assertEquals(list, list2)

		assertEquals(40, sub0.size)
		assertEquals(40, sub1.size)

		assertEquals(sub0, sub1)

		assertEquals(45, sub0.removeAt(5))
		assertEquals(45, sub1.removeAt(5))

		assertEquals(list, list2)
		assertEquals(sub0, sub1)

		assertEquals(46, sub0.removeAt(5))
		assertEquals(46, sub1.removeAt(5))

		assertEquals(list, list2)
		assertEquals(sub0, sub1)

		assertEquals(38, sub0.size)
		assertEquals(38, sub1.size)

		assertEquals(list, list2)
	}
}