|
| 1 | +package net.osmtracker.util; |
| 2 | + |
| 3 | +import static org.junit.Assert.*; |
| 4 | +import org.junit.Test; |
| 5 | +import org.junit.runner.RunWith; |
| 6 | +import org.junit.runners.Parameterized; |
| 7 | + |
| 8 | +import java.util.Arrays; |
| 9 | +import java.util.Collection; |
| 10 | + |
| 11 | +@RunWith(Parameterized.class) |
| 12 | +public class MercatorProjectionTest { |
| 13 | + |
| 14 | + @Parameterized.Parameter(0) |
| 15 | + public double minLat; |
| 16 | + |
| 17 | + @Parameterized.Parameter(1) |
| 18 | + public double lat; |
| 19 | + |
| 20 | + @Parameterized.Parameter(2) |
| 21 | + public double maxLat; |
| 22 | + |
| 23 | + @Parameterized.Parameter(3) |
| 24 | + public double minLon; |
| 25 | + |
| 26 | + @Parameterized.Parameter(4) |
| 27 | + public double lon; |
| 28 | + |
| 29 | + @Parameterized.Parameter(5) |
| 30 | + public double maxLon; |
| 31 | + |
| 32 | + @Parameterized.Parameter(6) |
| 33 | + public int expectedX; |
| 34 | + |
| 35 | + @Parameterized.Parameter(7) |
| 36 | + public int expectedY; |
| 37 | + |
| 38 | + @Parameterized.Parameter(8) |
| 39 | + public double expectedScale; |
| 40 | + |
| 41 | + @Parameterized.Parameter(9) |
| 42 | + public Float degre; |
| 43 | + |
| 44 | + @Parameterized.Parameter(10) |
| 45 | + public boolean isLat; |
| 46 | + |
| 47 | + @Parameterized.Parameter(11) |
| 48 | + public String expectedDms; |
| 49 | + |
| 50 | + @Parameterized.Parameters |
| 51 | + public static Collection<Object[]> data() { |
| 52 | + return Arrays.asList(new Object[][] { |
| 53 | + { -89, -83.83, -80, /**/ -180, -171.171, -160, /**/ 323, 879, /**/ 0.0315, -83.83f, true, "83° 49' 48\" S" }, |
| 54 | + { -45, -42.45, -40, /**/ 170, 175.175, 180, /**/ 373, 630, /**/ 0.0138, -42.45f, false, "42° 27' 0\" W" }, |
| 55 | + { 45, 48.48, 50, /**/ -160, -151.151, -150, /**/ 637, 541, /**/ 0.0138, 48.48f, true, "48° 28' 47\" N" }, |
| 56 | + { 80, 82.82, 85, /**/ 110, 111.111, 120, /**/ 235, 668, /**/ 0.0311, 82.82f, false, "82° 49' 11\" E" }, |
| 57 | + { 89, 89.89, 90, /**/ 111, 111.111, 112, /**/ 80, 640, /**/ 0.0013, null, true, "" } |
| 58 | + }); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void testProject() { |
| 63 | + MercatorProjection projection = new MercatorProjection(minLat, minLon, maxLat, maxLon, 720, 1280); |
| 64 | + int[] point = projection.project(lon, lat); |
| 65 | + assertNotNull(point); |
| 66 | + assertEquals(expectedX, point[MercatorProjection.X]); |
| 67 | + assertEquals(expectedY, point[MercatorProjection.Y]); |
| 68 | + assertEquals(expectedScale, projection.getScale(), 0.0001); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void testFormatDegreesAsDMS() { |
| 73 | + String formattedDms = MercatorProjection.formatDegreesAsDMS(degre, isLat); |
| 74 | + assertEquals(expectedDms, formattedDms); |
| 75 | + } |
| 76 | + |
| 77 | +} |
0 commit comments