Merge pull request #88 from zolotov/fix-reverse-and-sort-for-lists

Fix reverse and sort functions for lists
This commit is contained in:
James Strachan
2012-07-02 03:42:05 -07:00
16 changed files with 71 additions and 39 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() }
}
}
+24 -7
View File
@@ -325,16 +325,33 @@ class CollectionTest {
assertEquals(arrayList("bar", "foo"), rev)
}
test fun sort() {
val coll: List<String> = arrayList("foo", "bar", "abc")
test fun reverseFunctionShouldReturnReversedCopyForList() {
val list : List<Int> = arrayList(2, 3, 1)
expect(arrayList(1, 3, 2)) { list.reverse() }
expect(arrayList(2, 3, 1)) { list }
}
// TODO fixme
// Some sort of in/out variance thing - or an issue with Java interop?
//coll.sort()
test fun reverseFunctionShouldReturnReversedCopyForIterable() {
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 sortFunctionShouldReturnSortedCopyForList() {
// TODO fixme Some sort of in/out variance thing - or an issue with Java interop?
todo {
assertEquals(3, coll.size)
assertEquals(arrayList("abc", "bar", "foo"), coll)
// val list : List<Int> = arrayList<Int>(2, 3, 1)
// expect(arrayList(1, 2, 3)) { list.sort() }
// expect(arrayList(2, 3, 1)) { list }
}
}
test fun sortFunctionShouldReturnSortedCopyForIterable() {
// TODO fixme Some sort of in/out variance thing - or an issue with Java interop?
todo {
// val list : java.lang.Iterable<Int> = arrayList(2, 3, 1)
// expect(arrayList(1, 2, 3)) { list.sort() }
// expect(arrayList(2, 3, 1)) { list }
}
}