fixed mapping sort and max functions from java.util.Collections

This commit is contained in:
Zalim Bashorov
2013-03-06 18:47:04 +04:00
parent dd7d584478
commit 220682afe2
9 changed files with 135 additions and 54 deletions
+1 -2
View File
@@ -44,8 +44,7 @@ class MapJsTest {
test fun hashMapValues() {
val map = createTestHashMap()
//todo: fixme after sort() will be fixed for JS
assertEquals(VALUES, map.values())
assertEquals(VALUES.toList(), map.values().toSortedList())
}
fun createTestHashMap(): HashMap<String, Int> {
@@ -0,0 +1,32 @@
package testPackage
import java.util.Collections
import java.util.ArrayList
import kotlin.test.*
import org.junit.Test as test
fun <T> List<T>.toArrayList() = this.toCollection(ArrayList<T>())
class JavautilCollectionsTest {
val TEST_LIST = array(2, 0, 9, 7, 1).toList()
val SORTED_TEST_LIST = array(0, 1, 2, 7, 9).toList()
val MAX_ELEMENT = 9
val COMPARATOR = comparator { (x: Int, y: Int) -> if (x > y) 1 else if (x < y) -1 else 0 }
test fun maxWithComparator() {
assertEquals(MAX_ELEMENT, Collections.max(TEST_LIST, COMPARATOR))
}
test fun sort() {
val list = TEST_LIST.toArrayList()
Collections.sort(list)
assertEquals(SORTED_TEST_LIST, list)
}
test fun sortWithComparator() {
val list = TEST_LIST.toArrayList()
Collections.sort(list, COMPARATOR)
assertEquals(SORTED_TEST_LIST, list)
}
}