Tests for array's copyOf and plus.

This commit is contained in:
Ilya Gorbunov
2015-07-06 21:44:29 +03:00
parent a7bf415ad5
commit 6507cf391b
2 changed files with 56 additions and 37 deletions
@@ -13,27 +13,7 @@ class ArraysJVMTest {
expect(b[i]) { a[i] }
}
test fun copyOf() {
checkContent(booleanArrayOf(true, false, true, false, true, false).copyOf().iterator(), 6) { it % 2 == 0 }
checkContent(byteArrayOf(0, 1, 2, 3, 4, 5).copyOf().iterator(), 6) { it.toByte() }
checkContent(shortArrayOf(0, 1, 2, 3, 4, 5).copyOf().iterator(), 6) { it.toShort() }
checkContent(intArrayOf(0, 1, 2, 3, 4, 5).copyOf().iterator(), 6) { it }
checkContent(longArrayOf(0, 1, 2, 3, 4, 5).copyOf().iterator(), 6) { it.toLong() }
checkContent(floatArrayOf(0.toFloat(), 1.toFloat(), 2.toFloat(), 3.toFloat()).copyOf().iterator(), 4) { it.toFloat() }
checkContent(doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0).copyOf().iterator(), 6) { it.toDouble() }
checkContent(charArrayOf('0', '1', '2', '3', '4', '5').copyOf().iterator(), 6) { '0' + it }
}
test fun copyOfRange() {
checkContent(booleanArrayOf(true, false, true, false, true, false).copyOfRange(0, 3).iterator(), 3) { it % 2 == 0 }
checkContent(byteArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3).iterator(), 3) { it.toByte() }
checkContent(shortArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3).iterator(), 3) { it.toShort() }
checkContent(intArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3).iterator(), 3) { it }
checkContent(longArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3).iterator(), 3) { it.toLong() }
checkContent(floatArrayOf(0.toFloat(), 1.toFloat(), 2.toFloat(), 3.toFloat()).copyOfRange(0, 3).iterator(), 3) { it.toFloat() }
checkContent(doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0).copyOfRange(0, 3).iterator(), 3) { it.toDouble() }
checkContent(charArrayOf('0', '1', '2', '3', '4', '5').copyOfRange(0, 3).iterator(), 3) { '0' + it }
}
test fun reduce() {
expect(-4) { intArrayOf(1, 2, 3) reduce { a, b -> a - b } }