package com.evsuite.abrp; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Test; /** The Grid map's tile arithmetic and the server's road tiles — pure JVM. */ public class MapGeometryTest { @Test public void tilesMatchTheServer() { // Alexanderplatz, Berlin: the tile the server tests use too. assertEquals(8802, MapGeometry.tileX(13.4125)); assertEquals(5373, MapGeometry.tileY(52.5219)); long key = MapGeometry.key(8802, 5373); assertEquals(8802, MapGeometry.keyX(key)); assertEquals(5373, MapGeometry.keyY(key)); } @Test public void metresPerUnitShrinkTowardsThePoles() { // A zoom-14 tile is about 2.4 km across at the equator, in 4096 units. assertEquals(0.597, MapGeometry.metresPerUnit(0), 0.001); assertEquals(0.363, MapGeometry.metresPerUnit(52.52), 0.001); } @Test public void unusablePositions() { assertFalse(MapGeometry.usable(Double.NaN, 13)); assertFalse(MapGeometry.usable(0, 0)); // a GPS that has nothing yet assertFalse(MapGeometry.usable(89, 13)); assertTrue(MapGeometry.usable(52.52, 13.41)); } @Test public void roadTilesParse() { RoadTile t = RoadTile.parse("{\"z\":14,\"x\":8802,\"y\":5373,\"extent\":4096,\"ways\":[" + "{\"c\":1,\"p\":[-115,1236,82,1080,100,1000]},{\"c\":3,\"p\":[0,0,10,10]}]}", 8802, 5373); assertNotNull(t); assertEquals(2, t.classes.length); assertEquals(1, t.classes[0]); assertEquals(6, t.points[0].length); assertEquals(-115, t.bounds[0][0]); assertEquals(1000, t.bounds[0][1]); assertEquals(100, t.bounds[0][2]); assertEquals(1236, t.bounds[0][3]); } @Test public void badRoadTilesAreNoTile() { String head = "{\"z\":14,\"x\":1,\"y\":2,\"extent\":4096,\"ways\":"; assertNotNull(RoadTile.parse(head + "[]}", 1, 2)); assertNull("another tile", RoadTile.parse(head + "[]}", 1, 3)); assertNull("another zoom", RoadTile.parse("{\"z\":13,\"x\":1,\"y\":2,\"extent\":4096,\"ways\":[]}", 1, 2)); assertNull("unknown class", RoadTile.parse(head + "[{\"c\":7,\"p\":[0,0,1,1]}]}", 1, 2)); assertNull("one point", RoadTile.parse(head + "[{\"c\":1,\"p\":[0,0]}]}", 1, 2)); assertNull("odd count", RoadTile.parse(head + "[{\"c\":1,\"p\":[0,0,1]}]}", 1, 2)); assertNull("far outside", RoadTile.parse(head + "[{\"c\":1,\"p\":[0,0,99999,1]}]}", 1, 2)); assertNull("not JSON", RoadTile.parse("", 1, 2)); } }