From c5e3a5080a6fa8d6654ec9ea04852e54a70bc6c3 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 4 Aug 2016 00:19:37 +0200 Subject: [PATCH] Fix tests --- .../osmand/router/RouteTestingTestIgnore.java | 106 +++++++++--------- OsmAnd-java/test/resources/test_routing.json | 19 ++-- 2 files changed, 61 insertions(+), 64 deletions(-) diff --git a/OsmAnd-java/test/java/net/osmand/router/RouteTestingTestIgnore.java b/OsmAnd-java/test/java/net/osmand/router/RouteTestingTestIgnore.java index 439d16d2ff..6b5defb6f7 100644 --- a/OsmAnd-java/test/java/net/osmand/router/RouteTestingTestIgnore.java +++ b/OsmAnd-java/test/java/net/osmand/router/RouteTestingTestIgnore.java @@ -7,9 +7,11 @@ import java.io.RandomAccessFile; import java.io.Reader; import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; @@ -33,20 +35,11 @@ import com.google.gson.GsonBuilder; @RunWith(Parameterized.class) public class RouteTestingTestIgnore { + private TestEntry te; - private LatLon startPoint; - private LatLon endPoint; - private Map expectedResults; - private Map params; - - - public RouteTestingTestIgnore(String testName, LatLon startPoint, LatLon endPoint, Map expectedResults, - Map params) { - this.startPoint = startPoint; - this.endPoint = endPoint; - this.expectedResults = expectedResults; - this.params = params; + public RouteTestingTestIgnore(String name, TestEntry te) { + this.te = te; } @BeforeClass @@ -55,62 +48,65 @@ public class RouteTestingTestIgnore { } @Parameterized.Parameters(name = "{index}: {0}") - public static Collection data() throws IOException { + public static Iterable data() throws IOException { String fileName = "/test_routing.json"; Reader reader = new InputStreamReader(RouteTestingTestIgnore.class.getResourceAsStream(fileName)); Gson gson = new GsonBuilder().setPrettyPrinting().create(); TestEntry[] testEntries = gson.fromJson(reader, TestEntry[].class); - ArrayList twoDArray = new ArrayList(); - for (int i = 0; i < testEntries.length; ++i) { - if (!testEntries[i].isIgnore()) { - Object[] arr = new Object[] { testEntries[i].getTestName(), testEntries[i].getStartPoint(), - testEntries[i].getEndPoint(), testEntries[i].getExpectedResults(), - testEntries[i].getParams()}; - twoDArray.add(arr); - } + ArrayList arrayList = new ArrayList<>(); + for(TestEntry te : testEntries) { + arrayList.add(new Object[] {te.getTestName(), te}); } reader.close(); - return twoDArray; + return arrayList; } @Test - public void testRouting() throws Exception { - String fl = "../../resources/test-resources/Routing_test.obf"; - RandomAccessFile raf = new RandomAccessFile(fl, "r"); - RoutePlannerFrontEnd fe = new RoutePlannerFrontEnd(false); - + public void testRouting() throws Exception { + String fl = "../../resources/test-resources/Routing_test.obf"; + RandomAccessFile raf = new RandomAccessFile(fl, "r"); + RoutePlannerFrontEnd fe = new RoutePlannerFrontEnd(false); + BinaryMapIndexReader[] binaryMapIndexReaders = { new BinaryMapIndexReader(raf, new File(fl)) }; RoutingConfiguration.Builder builder = RoutingConfiguration.getDefault(); - RoutingConfiguration config = builder.build(params.containsKey("vehicle") ? - params.get("vehicle") : "car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3, params); - RoutingContext ctx = fe.buildRoutingContext(config, null, binaryMapIndexReaders, - RoutePlannerFrontEnd.RouteCalculationMode.NORMAL); - ctx.leftSideNavigation = false; - List routeSegments = fe.searchRoute(ctx, startPoint, endPoint, null); - Set reachedSegments = new TreeSet(); - Assert.assertNotNull(routeSegments); - int prevSegment = -1; - for (int i = 0; i <= routeSegments.size(); i++) { - if (i == routeSegments.size() || routeSegments.get(i).getTurnType() != null) { - if (prevSegment >= 0) { - String name = routeSegments.get(prevSegment).getDescription(); - long segmentId = routeSegments.get(prevSegment).getObject().getId() >> (BinaryInspector.SHIFT_ID ); - System.out.println("segmentId: " + segmentId + " description: " + name); - } - prevSegment = i; - } - if (i < routeSegments.size()) { - reachedSegments.add(routeSegments.get(i).getObject().getId() >> (BinaryInspector.SHIFT_ID )); - } - } + Map params = te.getParams(); + RoutingConfiguration config = builder.build(params.containsKey("vehicle") ? params.get("vehicle") : "car", + RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3, params); + RoutingContext ctx = fe.buildRoutingContext(config, null, binaryMapIndexReaders, + RoutePlannerFrontEnd.RouteCalculationMode.NORMAL); + ctx.leftSideNavigation = false; + List routeSegments = fe.searchRoute(ctx, te.getStartPoint(), te.getEndPoint(), null); + Set reachedSegments = new TreeSet(); + Assert.assertNotNull(routeSegments); + int prevSegment = -1; + for (int i = 0; i <= routeSegments.size(); i++) { + if (i == routeSegments.size() || routeSegments.get(i).getTurnType() != null) { + if (prevSegment >= 0) { + String name = routeSegments.get(prevSegment).getDescription(); + long segmentId = routeSegments.get(prevSegment).getObject().getId() >> (BinaryInspector.SHIFT_ID); + System.out.println("segmentId: " + segmentId + " description: " + name); + } + prevSegment = i; + } + if (i < routeSegments.size()) { + reachedSegments.add(routeSegments.get(i).getObject().getId() >> (BinaryInspector.SHIFT_ID)); + } + } + Map expectedResults = te.getExpectedResults(); + Iterator> it = expectedResults.entrySet().iterator(); + while (it.hasNext()) { + Entry es = it.next(); + if (es.getValue().equals("false")) { + Assert.assertTrue("Expected segment " + (es.getKey()) + " was wrongly reached in route segments " + + reachedSegments.toString(), !reachedSegments.contains(es.getKey())); + } else { + Assert.assertTrue("Expected segment " + (es.getKey()) + " weren't reached in route segments " + + reachedSegments.toString(), reachedSegments.contains(es.getKey())); + } + } - Set expectedSegments = expectedResults.keySet(); - for (Long expSegId : expectedSegments){ - Assert.assertTrue("Expected segment " + (expSegId ) + - " weren't reached in route segments " + reachedSegments.toString(), reachedSegments.contains(expSegId)); - } - } + } diff --git a/OsmAnd-java/test/resources/test_routing.json b/OsmAnd-java/test/resources/test_routing.json index a052932000..bcba306bb6 100644 --- a/OsmAnd-java/test/resources/test_routing.json +++ b/OsmAnd-java/test/resources/test_routing.json @@ -4,9 +4,10 @@ "description": "При planRoadDirection='-1' маршрут неверный, при 0 - верный", "params": { "vehicle": "car", - "shortWay": "true", + "short_way": "true", "planRoadDirection": "0" }, + "ignore":true, "startPoint": { "latitude": 45.90810929390909, "longitude": 35.25023227930072 @@ -25,7 +26,7 @@ "description": "Подтверждается только неверный маршрут. От дистанции не зависит, но зависит от planRoadDirection. При -1 маршрут верный, при 0 - нет", "params": { "vehicle": "car", - "shortWay": "true", + "short_way": "true", "planRoadDirection": "0" }, "startPoint": { @@ -45,7 +46,7 @@ "description": "Не воспроизводится", "params": { "vehicle": "car", - "shortWay": "true", + "short_way": "true", "planRoadDirection": "-1" }, "startPoint": { @@ -65,7 +66,7 @@ "description": "Не воспроизводится", "params": { "vehicle": "car", - "shortWay": "true", + "short_way": "true", "planRoadDirection": "-1" }, "startPoint": { @@ -86,10 +87,10 @@ }, { "testName": "10.Longer route preferred? https://github.com/osmandapp/Osmand/issues/1941", - "description": "shortWay строит не самый короткий путь. Транзит через MEX 261 короче.", + "description": "short_way строит не самый короткий путь. Транзит через MEX 261 короче.", "params": { "vehicle": "car", - "shortWay": "true", + "short_way": "true", "planRoadDirection": "-1" }, "startPoint": { @@ -108,7 +109,7 @@ "testName": "12.Bizarre navigation at Sundance dr & Sentinel dr in Fremont, CA, USA https://github.com/osmandapp/Osmand/issues/1743", "params": { "vehicle": "car", - "shortWay": "true", + "short_way": "true", "planRoadDirection": "-1" }, "startPoint": { @@ -128,7 +129,7 @@ "testName": "12.1.Bizarre navigation at Sundance dr & Sentinel dr in Fremont, CA, USA (transit2 point) https://github.com/osmandapp/Osmand/issues/1743", "params": { "vehicle": "car", - "shortWay": "true", + "short_way": "true", "planRoadDirection": "-1" }, "startPoint": { @@ -151,7 +152,7 @@ "testName": "12.2.Bizarre navigation at Sundance dr & Sentinel dr in Fremont, CA, USA (reverse) https://github.com/osmandapp/Osmand/issues/1743", "params": { "vehicle": "car", - "shortWay": "true", + "short_way": "true", "planRoadDirection": "-1" }, "startPoint": {