#KT-2341 Fixed

This commit is contained in:
Michael Zehender
2013-12-12 16:14:57 +01:00
committed by Alexander Udalov
parent e179e6bb2f
commit 6546d7a1e7
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -90,7 +90,7 @@ val <T> List<T>.lastIndex : Int
* @includeFunctionBody ../../test/ListTest.kt head
*/
val <T> List<T>.head : T?
get() = this.get(0)
get() = if (this.isNotEmpty()) this.get(0) else null
/**
* Returns all elements in this collection apart from the first one
+10
View File
@@ -11,6 +11,11 @@ class ListTest {
assertEquals("[foo, bar]", data.toString())
}
test fun emptyHead() {
val data = ArrayList<String>()
assertNull(data.head)
}
test fun head() {
val data = arrayList("foo", "bar")
assertEquals("foo", data.head)
@@ -23,6 +28,11 @@ class ListTest {
assertEquals(expected, actual)
}
test fun emptyFirst() {
val data = ArrayList<String>()
assertNull(data.first)
}
test fun first() {
val data = arrayList("foo", "bar")
assertEquals("foo", data.first)