Fix function List<T>.reverse().

For now all iterables (including List) return reversed *copy* of collection.
See Problem 3 at https://github.com/JetBrains/kotlin/pull/78#issuecomment-6533534
This commit is contained in:
Alexander Zolotov
2012-06-26 00:13:26 +04:00
parent 8d2bd30585
commit 1e301843f7
15 changed files with 47 additions and 23 deletions
+11
View File
@@ -88,4 +88,15 @@ class ArraysTest {
}
}
test fun reverse() {
expect(arrayList(3, 2, 1)) { intArray(1, 2, 3).reverse() }
expect(arrayList<Byte>(3, 2, 1)) { byteArray(1, 2, 3).reverse() }
expect(arrayList<Short>(3, 2, 1)) { shortArray(1, 2, 3).reverse() }
expect(arrayList<Long>(3, 2, 1)) { longArray(1, 2, 3).reverse() }
expect(arrayList(3.toFloat(), 2.toFloat(), 1.toFloat())) { floatArray(1.toFloat(), 2.toFloat(), 3.toFloat()).reverse() }
expect(arrayList(3.0, 2.0, 1.0)) { doubleArray(1.0, 2.0, 3.0).reverse() }
expect(arrayList('3', '2', '1')) { charArray('1', '2', '3').reverse() }
expect(arrayList(false, false, true)) { booleanArray(true, false, false).reverse() }
}
}
+12 -2
View File
@@ -325,6 +325,18 @@ class CollectionTest {
assertEquals(arrayList("bar", "foo"), rev)
}
test fun reverseFunctionShouldReturnSortedCopyForList() {
val list : List<Int> = arrayList(2, 3, 1)
expect(arrayList(1, 3, 2)) { list.reverse() }
expect(arrayList(2, 3, 1)) { list }
}
test fun reverseFunctionShouldReturnSortedCopyForIterable() {
val iterable : java.lang.Iterable<Int> = arrayList(2, 3, 1)
expect(arrayList(1, 3, 2)) { iterable.reverse() }
expect(arrayList(2, 3, 1)) { iterable }
}
test fun sort() {
val coll: List<String> = arrayList("foo", "bar", "abc")
@@ -334,7 +346,6 @@ class CollectionTest {
todo {
assertEquals(3, coll.size)
assertEquals(arrayList("abc", "bar", "foo"), coll)
}
}
@@ -445,7 +456,6 @@ class CollectionTest {
// assertFalse(IterableWrapper(linkedList<Int>()).contains(15))
}
class IterableWrapper<T>(collection : java.lang.Iterable<T>) : java.lang.Iterable<T> {
private val collection = collection