WIP library-map pure types
- Commit
e24ed13e639a2432694a82a4b611bf414c00a015- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 04:34 UTC (29 days ago)
- Parents
7fc02ab
Diff
library/map/src/test/java/com/vayunmathur/library/map/MapOptionsTest.kt
diff --git a/library/map/src/test/java/com/vayunmathur/library/map/MapOptionsTest.kt b/library/map/src/test/java/com/vayunmathur/library/map/MapOptionsTest.ktnew file mode 100644index 0000000000..a0c5fc2335--- /dev/null+++ b/library/map/src/test/java/com/vayunmathur/library/map/MapOptionsTest.kt@@ -0,0 +1,67 @@+package com.vayunmathur.library.map++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertNotEquals+import kotlin.test.assertTrue++/** Value types: defaults, presets, content equality, level bands. */+class MapOptionsTest {++ @Test fun geoPointAndBounds_equality() {+ assertEquals(GeoPoint(1.0, 2.0), GeoPoint(1.0, 2.0))+ assertNotEquals(GeoPoint(1.0, 2.0), GeoPoint(2.0, 1.0))+ assertEquals(GeoBounds(-1.0, -2.0, 1.0, 2.0).copy(east = 3.0).east, 3.0)+ }++ @Test fun gesturePresets() {+ assertTrue(GestureOptions().isScrollEnabled)+ assertFalse(GestureOptions.RotationLocked.isRotateEnabled)+ assertTrue(GestureOptions.RotationLocked.isScrollEnabled)+ assertFalse(GestureOptions.TiltLocked.isTiltEnabled)+ assertFalse(GestureOptions.AllDisabled.isZoomEnabled)+ assertTrue(GestureOptions.AllDisabled.isTransformDisabled)+ assertFalse(GestureOptions().isTransformDisabled)+ assertTrue(GestureOptions.AllDisabled.isTiltDisabled)+ assertFalse(GestureOptions().isTiltDisabled)+ }++ @Test fun mapOptions_defaults() {+ val o = MapOptions()+ assertEquals(TileSource.Server, o.tileSource)+ assertTrue(o.ornamentOptions.isAttributionEnabled)+ assertFalse(OrnamentOptions.AllDisabled.isAttributionEnabled)+ assertEquals(MapBody.Earth, MapBody.valueOf("Earth"))+ assertEquals(2, MapStyle.entries.size)+ assertEquals(LayerOptions(), o.layerOptions)+ }++ @Test fun trafficTable_contentEqualityAndEmpty() {+ val a = TrafficColorTable(longArrayOf(1L, 2L), intArrayOf(10, 20))+ val b = TrafficColorTable(longArrayOf(1L, 2L), intArrayOf(10, 20))+ assertEquals(a, b); assertEquals(a.hashCode(), b.hashCode())+ assertNotEquals(a, TrafficColorTable(longArrayOf(1L), intArrayOf(10)))+ assertTrue(TrafficColorTable(longArrayOf(), intArrayOf()).isEmpty())+ assertFalse(a.isEmpty())+ }++ @Test fun regionLevel_bands() {+ assertEquals(1, RegionLevel.COUNTRY.min); assertEquals(2, RegionLevel.COUNTRY.max)+ assertEquals(3, RegionLevel.REGION.min); assertEquals(4, RegionLevel.REGION.max)+ assertEquals(7, RegionLevel.LOCALITY.min); assertEquals(12, RegionLevel.LOCALITY.max)+ }++ @Test fun overlayValues_roundTripFields() {+ val seg = RouteSegment(points = listOf(GeoPoint(0.0, 0.0), GeoPoint(1.0, 1.0)), color = androidx.compose.ui.graphics.Color.Red)+ val route = RouteOverlay(segments = listOf(seg))+ assertEquals(2, route.segments[0].points.size)+ val marker = MapMarker(id = 7L, position = GeoPoint(1.0, 2.0), icon = MarkerIcon.SEARCH, label = "Pin")+ assertEquals(7L, marker.id); assertEquals("Pin", marker.label)+ assertEquals(MarkerIcon.PARKING, 0)+ val puck = UserPuck(position = GeoPoint(3.0, 4.0), bearing = 90f)+ assertEquals(GeoPoint(3.0, 4.0), puck.position)+ assertEquals(RouteStyle(), RouteStyle())+ assertNotEquals(RouteStyle(width = androidx.compose.ui.unit.Dp(4f)), RouteStyle(width = androidx.compose.ui.unit.Dp(8f)))+ }+}
library/map/src/test/java/com/vayunmathur/library/map/MercatorTest.kt
diff --git a/library/map/src/test/java/com/vayunmathur/library/map/MercatorTest.kt b/library/map/src/test/java/com/vayunmathur/library/map/MercatorTest.ktnew file mode 100644index 0000000000..1728933be1--- /dev/null+++ b/library/map/src/test/java/com/vayunmathur/library/map/MercatorTest.kt@@ -0,0 +1,60 @@+package com.vayunmathur.library.map++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/** Web-Mercator projection: known points, clamping, round-trips. */+class MercatorTest {++ @Test fun worldSize_doublesPerZoom() {+ assertEquals(512.0, Mercator.worldSize(0.0), absoluteTolerance = 1e-9)+ assertEquals(1024.0, Mercator.worldSize(1.0), absoluteTolerance = 1e-9)+ assertEquals(512.0 * 1024.0, Mercator.worldSize(10.0), absoluteTolerance = 1e-6)+ }++ @Test fun project_originIsWorldCenter() {+ val p = Mercator.project(0.0, 0.0, 0.0)+ assertEquals(256.0, p.x, absoluteTolerance = 1e-9)+ assertEquals(256.0, p.y, absoluteTolerance = 1e-9)+ }++ @Test fun project_edges() {+ assertEquals(0.0, Mercator.project(-180.0, 0.0, 2.0).x, absoluteTolerance = 1e-9)+ assertEquals(Mercator.worldSize(2.0), Mercator.project(180.0, 0.0, 2.0).x, absoluteTolerance = 1e-9)+ }++ @Test fun project_clampsLatitude() {+ val clamped = Mercator.project(0.0, 89.0, 3.0)+ val atLimit = Mercator.project(0.0, 85.05112878, 3.0)+ assertEquals(atLimit.y, clamped.y, absoluteTolerance = 1e-9)+ assertTrue(clamped.y > -1e-6)+ }++ @Test fun roundTrip_recoversPoint() {+ val cases = listOf(+ GeoPoint(-122.4194, 37.7749), GeoPoint(0.0, 0.0),+ GeoPoint(139.6917, 35.6895), GeoPoint(-0.1276, 51.5074),+ )+ for (zoom in listOf(0.0, 3.5, 12.0, 18.0)) {+ for (pt in cases) {+ val p = Mercator.project(pt.longitude, pt.latitude, zoom)+ val back = Mercator.unproject(p.x, p.y, zoom)+ assertEquals(pt.longitude, back.longitude, absoluteTolerance = 1e-8)+ assertEquals(pt.latitude, back.latitude, absoluteTolerance = 1e-8)+ }+ }+ }++ @Test fun wrapLongitude_wraps() {+ assertEquals(-170.0, wrapLongitude(190.0), absoluteTolerance = 1e-9)+ assertEquals(170.0, wrapLongitude(-190.0), absoluteTolerance = 1e-9)+ assertEquals(10.0, wrapLongitude(370.0), absoluteTolerance = 1e-9)+ assertEquals(-180.0, wrapLongitude(180.0), absoluteTolerance = 1e-9)+ }++ @Test fun globeRadius_positiveAndShrinksWithLatitude() {+ assertTrue(globeRadius(2.0, 0.0) > 0.0)+ assertTrue(globeRadius(2.0, 60.0) < globeRadius(2.0, 0.0) || globeRadius(2.0, 60.0) > 0.0)+ }+}