Implemented indexOfFirst/Last(predicate). #KT-6577 Fixed

This commit is contained in:
Valery Kharitonov
2015-01-04 14:12:32 +03:00
committed by Ilya Ryzhenkov
parent 38a4f86db2
commit c8094e7587
4 changed files with 426 additions and 26 deletions
@@ -165,7 +165,37 @@ class ArraysTest {
expect(0) { array("cat", "dog", "bird").indexOf("cat") }
expect(1) { array("cat", "dog", "bird").indexOf("dog") }
expect(2) { array("cat", "dog", "bird").indexOf("bird") }
expect(0) { array(null, "dog", null).indexOf(null) }
expect(0) { array(null, "dog", null).indexOf(null : String?)}
expect(-1) { array("cat", "dog", "bird").indexOfFirst { it.contains("p") } }
expect(0) { array("cat", "dog", "bird").indexOfFirst { it.startsWith('c') } }
expect(1) { array("cat", "dog", "bird").indexOfFirst { it.startsWith('d') } }
expect(2) { array("cat", "dog", "bird").indexOfFirst { it.endsWith('d') } }
expect(-1) { streamOf("cat", "dog", "bird").indexOfFirst { it.contains("p") } }
expect(0) { streamOf("cat", "dog", "bird").indexOfFirst { it.startsWith('c') } }
expect(1) { streamOf("cat", "dog", "bird").indexOfFirst { it.startsWith('d') } }
expect(2) { streamOf("cat", "dog", "bird").indexOfFirst { it.endsWith('d') } }
}
test fun lastIndexOf() {
expect(-1) { array("cat", "dog", "bird").lastIndexOf("mouse") }
expect(0) { array("cat", "dog", "bird").lastIndexOf("cat") }
expect(1) { array("cat", "dog", "bird").lastIndexOf("dog") }
expect(2) { array(null, "dog", null).lastIndexOf(null : String?)}
expect(3) { array("cat", "dog", "bird", "dog").lastIndexOf("dog") }
expect(-1) { array("cat", "dog", "bird").indexOfLast { it.contains("p") } }
expect(0) { array("cat", "dog", "bird").indexOfLast { it.startsWith('c') } }
expect(2) { array("cat", "dog", "cap", "bird").indexOfLast { it.startsWith('c') } }
expect(2) { array("cat", "dog", "bird").indexOfLast { it.endsWith('d') } }
expect(3) { array("cat", "dog", "bird", "red").indexOfLast { it.endsWith('d') } }
expect(-1) { streamOf("cat", "dog", "bird").indexOfLast { it.contains("p") } }
expect(0) { streamOf("cat", "dog", "bird").indexOfLast { it.startsWith('c') } }
expect(2) { streamOf("cat", "dog", "cap", "bird").indexOfLast { it.startsWith('c') } }
expect(2) { streamOf("cat", "dog", "bird").indexOfLast { it.endsWith('d') } }
expect(3) { streamOf("cat", "dog", "bird", "red").indexOfLast { it.endsWith('d') } }
}
test fun plus() {