Compare camera positions with delta in instrumentation tests (#2507)
This commit is contained in:
@@ -5,13 +5,45 @@ import org.maplibre.android.camera.CameraUpdateFactory
|
||||
import org.maplibre.android.geometry.LatLng
|
||||
import org.maplibre.android.testapp.action.MapLibreMapAction.invoke
|
||||
import org.maplibre.android.testapp.activity.EspressoTest
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.maplibre.android.camera.CameraPosition
|
||||
import kotlin.math.abs
|
||||
|
||||
fun almostEquals(first: Double, second: Double, delta: Double): Boolean {
|
||||
return abs(first - second) < delta
|
||||
}
|
||||
|
||||
fun cameraPositionAlmostEquals(first: CameraPosition, second: CameraPosition, delta: Double = 0.00001): Boolean {
|
||||
if (delta == 0.0) return first == second
|
||||
if (first == second) return true
|
||||
|
||||
if (!almostEquals(first.zoom, second.zoom, delta) ||
|
||||
!almostEquals(first.tilt, second.tilt, delta) ||
|
||||
!almostEquals(first.bearing, second.bearing, delta)
|
||||
) return false
|
||||
|
||||
if (first.padding != null && second.padding != null) {
|
||||
// !! needed here https://discuss.kotlinlang.org/t/what-is-the-reason-behind-smart-cast-being-impossible-to-perform-when-referenced-class-is-in-another-module/2201
|
||||
if (first.padding!!.size != second.padding!!.size) return false
|
||||
for (index in first.padding!!.indices) {
|
||||
if (!almostEquals(first.padding!![index], second.padding!![index], delta)) return false
|
||||
}
|
||||
}
|
||||
|
||||
if (first.target != null && second.target != null) {
|
||||
if (!almostEquals(first.target!!.altitude, second.target!!.altitude, delta) ||
|
||||
!almostEquals(first.target!!.latitude, second.target!!.latitude, delta) ||
|
||||
!almostEquals(first.target!!.longitude, second.target!!.longitude, delta)) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
class TransformTest : EspressoTest() {
|
||||
|
||||
companion object {
|
||||
val initialCameraUpdate = CameraUpdateFactory.newLatLngZoom(LatLng(12.0, 12.0), 12.0)!!
|
||||
val initialCameraUpdate = CameraUpdateFactory.newLatLngZoom(LatLng(12.0, 12.0), 12.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -27,7 +59,7 @@ class TransformTest : EspressoTest() {
|
||||
maplibreMap.scrollBy(400.0f, 0.0f)
|
||||
val actualCameraPosition = maplibreMap.cameraPosition
|
||||
|
||||
assertEquals("Camera position should match", expectedCameraPosition, actualCameraPosition)
|
||||
assertTrue("Camera position should match $expectedCameraPosition $actualCameraPosition", cameraPositionAlmostEquals(expectedCameraPosition, actualCameraPosition))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.maplibre.android.testapp.activity.style.GridSourceActivity.Companion.
|
||||
import org.maplibre.android.testapp.utils.TestingAsyncUtils
|
||||
import org.junit.Assert
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
|
||||
class CustomGeometrySourceTest : BaseTest() {
|
||||
@@ -54,6 +55,7 @@ class CustomGeometrySourceTest : BaseTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("https://github.com/maplibre/maplibre-native/issues/2488")
|
||||
@Test
|
||||
fun threadsRestartedWhenSourceReAddedTest() {
|
||||
validateTestSetup()
|
||||
|
||||
Reference in New Issue
Block a user