2018-08-30 05:23:13 +02:00
|
|
|
package jp.juggler.subwaytooter
|
|
|
|
|
2019-02-15 02:51:22 +01:00
|
|
|
import androidx.test.runner.AndroidJUnit4
|
2021-10-28 01:37:39 +02:00
|
|
|
import jp.juggler.util.jsonArray
|
2020-01-07 09:03:32 +01:00
|
|
|
import org.jetbrains.anko.collections.forEachReversedByIndex
|
|
|
|
import org.jetbrains.anko.collections.forEachReversedWithIndex
|
2018-08-30 05:23:13 +02:00
|
|
|
import org.junit.Assert.assertEquals
|
2021-10-28 01:37:39 +02:00
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.runner.RunWith
|
2018-08-30 05:23:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Example local unit test, which will execute on the development machine (host).
|
|
|
|
*
|
|
|
|
* @see [Testing documentation](http://d.android.com/tools/testing)
|
|
|
|
*/
|
|
|
|
@RunWith(AndroidJUnit4::class)
|
|
|
|
class JsonArrayForEach {
|
2021-10-28 01:37:39 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
@Throws(Exception::class)
|
|
|
|
fun test() {
|
|
|
|
val array = jsonArray {
|
|
|
|
add("a")
|
|
|
|
add("b")
|
|
|
|
add(null)
|
|
|
|
add(null)
|
|
|
|
}
|
|
|
|
|
|
|
|
var count = 0
|
|
|
|
|
|
|
|
array.forEach {
|
|
|
|
println("JsonArray.forEach $it")
|
|
|
|
++count
|
|
|
|
}
|
|
|
|
|
|
|
|
array.forEachIndexed { i, v ->
|
|
|
|
println("JsonArray.forEachIndexed $i $v")
|
|
|
|
++count
|
|
|
|
}
|
|
|
|
|
|
|
|
array.forEachReversedByIndex {
|
|
|
|
println("JsonArray.downForEach $it")
|
|
|
|
++count
|
|
|
|
}
|
|
|
|
|
|
|
|
array.forEachReversedWithIndex { i, v ->
|
|
|
|
println("JsonArray.downForEachIndexed $i $v")
|
|
|
|
++count
|
|
|
|
}
|
|
|
|
|
|
|
|
for (o in array.iterator()) {
|
|
|
|
println("JsonArray.iterator $o")
|
|
|
|
++count
|
|
|
|
}
|
|
|
|
for (o in array.asReversed().iterator()) {
|
|
|
|
println("JsonArray.reverseIterator $o")
|
|
|
|
++count
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(count, 24)
|
|
|
|
}
|
2018-08-30 05:23:13 +02:00
|
|
|
}
|