standard library: 'max' and 'min' functions added (KT-3714, KT-3843, KT-3126)

This commit is contained in:
nik
2013-11-27 23:09:30 +04:00
parent 47d3e2e1bb
commit bf36eb07e9
14 changed files with 340 additions and 0 deletions
+22
View File
@@ -59,6 +59,28 @@ class ArraysJVMTest {
}
}
test fun min() {
expect(null, { intArray().min() })
expect(1, { intArray(1).min() })
expect(2, { intArray(2, 3).min() })
expect(2000000000000, { longArray(3000000000000, 2000000000000).min() })
expect(1, { byteArray(1, 3, 2).min() })
expect(2, { shortArray(3, 2).min() })
expect(2.0, { floatArray(3.0, 2.0).min() })
expect(2.0, { doubleArray(2.0, 3.0).min() })
}
test fun max() {
expect(null, { intArray().max() })
expect(1, { intArray(1).max() })
expect(3, { intArray(2, 3).max() })
expect(3000000000000, { longArray(3000000000000, 2000000000000).max() })
expect(3, { byteArray(1, 3, 2).max() })
expect(3, { shortArray(3, 2).max() })
expect(3.0, { floatArray(3.0, 2.0).max() })
expect(3.0, { doubleArray(2.0, 3.0).max() })
}
test fun sum() {
expect(0) { intArray().sum() }
expect(14) { intArray(2, 3, 9).sum() }
+18
View File
@@ -101,6 +101,24 @@ class ArraysTest {
assertEquals(false, arr[1])
}
test fun min() {
expect(null, { array<Int>().min() })
expect(1, { array(1).min() })
expect(2, { array(2, 3).min() })
expect(2000000000000, { array(3000000000000, 2000000000000).min() })
expect('a', { array('a', 'b').min() })
expect("a", { array("a", "b").min() })
}
test fun max() {
expect(null, { array<Int>().max() })
expect(1, { array(1).max() })
expect(3, { array(2, 3).max() })
expect(3000000000000, { array(3000000000000, 2000000000000).max() })
expect('b', { array('a', 'b').max() })
expect("b", { array("a", "b").max() })
}
test fun sum() {
expect(0) { array<Int>().sum() }
expect(14) { array(2, 3, 9).sum() }
+22
View File
@@ -414,6 +414,28 @@ class CollectionTest {
expect(arrayList(2, 3, 1)) { list }
}
test fun min() {
expect(null, { listOf<Int>().min() })
expect(1, { listOf(1).min() })
expect(2, { listOf(2, 3).min() })
expect(2000000000000, { listOf(3000000000000, 2000000000000).min() })
expect('a', { listOf('a', 'b').min() })
expect("a", { listOf("a", "b").min() })
expect(null, { listOf<Int>().iterator().min() })
expect(2, { listOf(2, 3).iterator().min() })
}
test fun max() {
expect(null, { listOf<Int>().max() })
expect(1, { listOf(1).max() })
expect(3, { listOf(2, 3).max() })
expect(3000000000000, { listOf(3000000000000, 2000000000000).max() })
expect('b', { listOf('a', 'b').max() })
expect("b", { listOf("a", "b").max() })
expect(null, { listOf<Int>().iterator().max() })
expect(3, { listOf(2, 3).iterator().max() })
}
test fun sum() {
expect(0) { ArrayList<Int>().sum() }
expect(14) { arrayListOf(2, 3, 9).sum() }