[6.5.0][道路事件] 部分代码提交
This commit is contained in:
File diff suppressed because one or more lines are too long
113
app/src/androidTest/java/com/mogo/functions/test/RoadInfoTest.kt
Normal file
113
app/src/androidTest/java/com/mogo/functions/test/RoadInfoTest.kt
Normal file
@@ -0,0 +1,113 @@
|
||||
package com.mogo.functions.test
|
||||
|
||||
import android.util.Log
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.LargeTest
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.mogo.eagle.core.function.main.MainLauncherActivity
|
||||
import com.mogo.eagle.function.biz.v2x.v2n.utils.V2NUtils
|
||||
import com.mogo.map.MapDataWrapper
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@LargeTest
|
||||
class RoadInfoTest {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "RoadInfoTest"
|
||||
}
|
||||
|
||||
lateinit var launch: ActivityScenario<MainLauncherActivity>
|
||||
|
||||
@Before
|
||||
fun before() {
|
||||
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testGetRoadName(): Unit = runBlocking {
|
||||
val arguments = InstrumentationRegistry.getArguments()
|
||||
val millis = arguments.getString("delay", "0").toLong()
|
||||
if (millis > 0) {
|
||||
delay(millis)
|
||||
}
|
||||
val lon = arguments.getString("lon", "0").toDouble()
|
||||
val lat = arguments.getString("lat", "0").toDouble()
|
||||
val angle = arguments.getString("angle", "0").toFloat()
|
||||
val times = arguments.getString("times", "1").toInt()
|
||||
var count = 0
|
||||
Log.d(TAG, "lon: $lon, lat:$lat, angle: $angle, times: $times")
|
||||
while (count < times) {
|
||||
val roadInfo = MapDataWrapper.getRoadInfo(lon, lat, angle)
|
||||
Log.d(TAG, "road-data: $roadInfo")
|
||||
delay(millis)
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testGetLaneInfo(): Unit = runBlocking {
|
||||
val arguments = InstrumentationRegistry.getArguments()
|
||||
val millis = arguments.getString("delay", "0").toLong()
|
||||
if (millis > 0) {
|
||||
delay(millis)
|
||||
}
|
||||
val tileId = arguments.getString("tileId", "0").toLong()
|
||||
val roadId = arguments.getString("roadId", "0").toInt()
|
||||
val times = arguments.getString("times", "1").toInt()
|
||||
Log.d(TAG, "tileId: $tileId, roadId:$roadId, times: $times")
|
||||
var count = 0
|
||||
while (count < times) {
|
||||
val laneInfo = MapDataWrapper.getLaneInfo(tileId, roadId)
|
||||
Log.d(TAG, "lane-data: ${ laneInfo.joinToString(",") { itx -> itx.points.joinToString("-") { "${it.first}->${it.second}" } } }")
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testComputeOccupyLaneInfo(): Unit = runBlocking {
|
||||
val arguments = InstrumentationRegistry.getArguments()
|
||||
val millis = arguments.getString("delay", "0").toLong()
|
||||
if (millis > 0) {
|
||||
delay(millis)
|
||||
}
|
||||
val lon = arguments.getString("lon", "0").toDouble()
|
||||
val lat = arguments.getString("lat", "0").toDouble()
|
||||
val angle = arguments.getString("angle", "0").toFloat()
|
||||
val times = arguments.getString("times", "1").toInt()
|
||||
var count = 0
|
||||
while (count < times) {
|
||||
val polygon = readPolygonJson()
|
||||
Log.d(TAG, "polygon -> " + polygon.joinToString(","))
|
||||
val decision = V2NUtils.computeOccupyLanesInfo(Triple(0.0, 0.0, 1f), Triple(lon, lat, angle), polygon)
|
||||
Log.d(TAG, "decision -> $decision")
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
private fun readPolygonJson(): List<Pair<Double, Double>> {
|
||||
return InstrumentationRegistry.getInstrumentation().context.assets.open("polygon.txt").reader().use { itx ->
|
||||
val items = itx.readLines().map { xx ->
|
||||
xx.split(",").map { it.trim().toDouble() }
|
||||
}.flatten()
|
||||
val result = ArrayList<Pair<Double, Double>>()
|
||||
var first = 0.0
|
||||
for ((index, data) in items.withIndex()) {
|
||||
if ((index % 2) == 0) {
|
||||
first = data
|
||||
} else {
|
||||
result.add(Pair(first, data))
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user