added drop(n) and dropWhile(predicates) for KT-2067 - also tail() now returns the usual idea of tail() - namely everything but the head - rather than just the last element. Finally added more test sample code to the kdoc

This commit is contained in:
James Strachan
2012-05-23 09:35:16 +01:00
parent 53a9fff0bc
commit 939f0e9085
7 changed files with 133 additions and 34 deletions
+23
View File
@@ -302,6 +302,29 @@ class CollectionTest {
}
}
test fun drop() {
val coll = arrayList("foo", "bar", "abc")
assertEquals(arrayList("bar", "abc"), coll.drop(1))
assertEquals(arrayList("abc"), coll.drop(2))
}
test fun dropWhile() {
val coll = arrayList("foo", "bar", "abc")
assertEquals(arrayList("bar", "abc"), coll.dropWhile{ it.startsWith("f") })
}
test fun take() {
val coll = arrayList("foo", "bar", "abc")
assertEquals(arrayList("foo"), coll.take(1))
assertEquals(arrayList("foo", "bar"), coll.take(2))
}
test fun takeWhile() {
val coll = arrayList("foo", "bar", "abc")
assertEquals(arrayList("foo"), coll.takeWhile{ it.startsWith("f") })
assertEquals(arrayList("foo", "bar", "abc"), coll.takeWhile{ it.size == 3 })
}
test fun toArray() {
val data = arrayList("foo", "bar")
val arr = data.toArray()