Files
kotlin-fork/libraries/stdlib/test/ListTest.kt
T

49 lines
1.1 KiB
Kotlin

package test.collections
import java.util.ArrayList
import kotlin.test.*
import org.junit.Test as test
class ListTest {
test fun head() {
val data = arrayList("foo", "bar")
assertEquals("foo", data.head)
}
test fun tail() {
val data = arrayList("foo", "bar", "whatnot")
assertEquals(arrayList("bar", "whatnot"), data.tail)
}
test fun first() {
val data = arrayList("foo", "bar")
assertEquals("foo", data.first)
}
test fun last() {
val data = arrayList("foo", "bar")
assertEquals("bar", data.last)
}
test fun withIndices() {
val data = arrayList("foo", "bar")
val withIndices = data.withIndices()
var index = 0
for (withIndex in withIndices) {
assertEquals(withIndex._1, index)
assertEquals(withIndex._2, data[index])
index++
}
assertEquals(data.size(), index)
}
test fun lastIndex() {
val emptyData = ArrayList<String>()
val data = arrayList("foo", "bar")
assertEquals(-1, emptyData.lastIndex)
assertEquals(1, data.lastIndex)
}
}