Files
kotlin-fork/js/js.translator/testData/_commonFiles/arrayAsserts.kt
T
Zalim Bashorov 3f0b31dc23 Speed up JS IR BE tests compiling the common parts (runtime + test common utils) once (on demand) and sharing the result between tests
It's a temporary hack until we implement IR based library format.
It relies on the fact that currently, IR BE generates stable (enough) names.​
2018-07-13 23:42:41 +03:00

25 lines
792 B
Kotlin
Vendored

package kotlin
fun <T> assertArrayEquals(expected: Array<out T>, actual: Array<out T>, message: String? = null) {
if (!arraysEqual(expected, actual)) {
val msg = if (message == null) "" else ", message = '$message'"
fail("Unexpected array: expected = '$expected', actual = '$actual'$msg")
}
}
private fun <T> arraysEqual(first: Array<out T>, second: Array<out T>): Boolean {
if (first === second) return true
if (first.size != second.size) return false
for (index in 0..first.size - 1) {
if (!equal(first[index], second[index])) return false
}
return true
}
private fun equal(first: Any?, second: Any?) =
if (first is Array<*> && second is Array<*>) {
arraysEqual(first, second)
}
else {
first == second
}