Cleanup ordering, improve API
This commit is contained in:
@@ -23,11 +23,7 @@ class MapJVMTest {
|
||||
|
||||
test fun toSortedMapWithComparator() {
|
||||
val map = mapOf(Pair("c", 3), Pair("bc", 2), Pair("bd", 4), Pair("abc", 1))
|
||||
val c = comparator<String>{ a, b ->
|
||||
val answer = a.length() - b.length()
|
||||
if (answer == 0) a.compareTo(b) else answer
|
||||
}
|
||||
val sorted = map.toSortedMap(c)
|
||||
val sorted = map.toSortedMap(compareBy<String> { it.length() } thenBy { it })
|
||||
assertEquals(arrayListOf("c", "bc", "bd", "abc"), sorted.keySet().toList())
|
||||
assertEquals(1, sorted["abc"])
|
||||
assertEquals(2, sorted["bc"])
|
||||
|
||||
Reference in New Issue
Block a user