Provide minWith and maxWith to find maximum and minimum values according to the given comparator.

#KT-9002 Fixed
This commit is contained in:
Ilya Gorbunov
2015-11-30 19:57:42 +03:00
parent b5e637bed5
commit 055c71e8d0
11 changed files with 433 additions and 1 deletions
@@ -4,6 +4,7 @@ import java.util.*
import kotlin.test.*
import org.junit.Test as test
import test.collections.behaviors.*
import test.compare.STRING_CASE_INSENSITIVE_ORDER
import java.io.Serializable
class CollectionTest {
@@ -496,6 +497,20 @@ class CollectionTest {
expect(3, { listOf(2, 3).asSequence().max() })
}
@test fun minWith() {
expect(null, { listOf<Int>().minWith(naturalOrder()) })
expect(1, { listOf(1).minWith(naturalOrder()) })
expect("a", { listOf("a", "B").minWith(STRING_CASE_INSENSITIVE_ORDER) })
expect("a", { listOf("a", "B").asSequence().minWith(STRING_CASE_INSENSITIVE_ORDER) })
}
@test fun maxWith() {
expect(null, { listOf<Int>().maxWith(naturalOrder()) })
expect(1, { listOf(1).maxWith(naturalOrder()) })
expect("B", { listOf("a", "B").maxWith(STRING_CASE_INSENSITIVE_ORDER) })
expect("B", { listOf("a", "B").asSequence().maxWith(STRING_CASE_INSENSITIVE_ORDER) })
}
@test fun minBy() {
expect(null, { listOf<Int>().minBy { it } })
expect(1, { listOf(1).minBy { it } })