Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-05-30 10:35:16 +02:00
commit 1d60b41dc7
4 changed files with 166 additions and 8 deletions

View file

@ -11,23 +11,17 @@ import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import net.osmand.IProgress;
import net.osmand.PlatformUtil;
import net.osmand.osm.edit.Entity;
import net.osmand.osm.edit.Entity.EntityId;
import net.osmand.osm.edit.Entity.EntityType;
import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Relation;
import net.osmand.osm.edit.Way;
import net.osmand.osm.edit.Entity.EntityId;
import net.osmand.osm.edit.Entity.EntityType;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

View file

@ -0,0 +1,116 @@
package net.osmand.router;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import net.osmand.binary.BinaryInspector;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.LatLon;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/**
* Created by yurkiss on 04.03.16.
*/
@RunWith(Parameterized.class)
public class RouteTestingTest {
private LatLon startPoint;
private LatLon endPoint;
private Map<Long, String> expectedResults;
private Map<String, String> params;
public RouteTestingTest(String testName, LatLon startPoint, LatLon endPoint, Map<Long, String> expectedResults,
Map<String, String> params) {
this.startPoint = startPoint;
this.endPoint = endPoint;
this.expectedResults = expectedResults;
this.params = params;
}
@BeforeClass
public static void setUp() throws Exception {
RouteResultPreparation.PRINT_TO_CONSOLE_ROUTE_INFORMATION_TO_TEST = true;
}
@Parameterized.Parameters(name = "{index}: {0}")
public static Collection<Object[]> data() throws IOException {
String fileName = "/test_routing.json";
Reader reader = new InputStreamReader(RouteTestingTest.class.getResourceAsStream(fileName));
Gson gson = new GsonBuilder().setPrettyPrinting().create();
TestEntry[] testEntries = gson.fromJson(reader, TestEntry[].class);
ArrayList<Object[]> twoDArray = new ArrayList<Object[]>();
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);
}
}
reader.close();
return twoDArray;
}
@Test
public void testRouting() throws Exception {
String fl = "../../resources/Turn_lanes_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<RouteSegmentResult> routeSegments = fe.searchRoute(ctx, startPoint, endPoint, null);
Set<Long> reachedSegments = new TreeSet<Long>();
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 ));
}
}
Set<Long> expectedSegments = expectedResults.keySet();
for (Long expSegId : expectedSegments){
Assert.assertTrue("Expected segment " + (expSegId ) +
" weren't reached in route segments " + reachedSegments.toString(), reachedSegments.contains(expSegId));
}
}
}

View file

@ -14,6 +14,7 @@ public class TestEntry {
private LatLon endPoint;
private boolean ignore;
private Map<Long, String> expectedResults;
private Map<String, String> params;
public LatLon getStartPoint() {
return startPoint;
@ -46,6 +47,14 @@ public class TestEntry {
public void setExpectedResults(Map<Long, String> expectedResults) {
this.expectedResults = expectedResults;
}
public void setParams(Map<String, String> params) {
this.params = params;
}
public Map<String, String> getParams() {
return params;
}
public String getTestName() {
return testName;

View file

@ -0,0 +1,39 @@
[
{
"testName": "1.Pedestrian Preston road TR Lorimar drive",
"startPoint": {
"latitude": 45.69539,
"longitude": 35.43936
},
"endPoint": {
"latitude": 45.69567,
"longitude": 35.440113
},
"params": {
"vehicle": "car",
"short_way": "true"
},
"expectedResults": {
"26545": "TL|C|C|C"
}
},
{
"testName": "2. Car Preston road TR Lorimar drive",
"params": {
"vehicle": "pedestrian",
"pedestrian": "true",
"short_way": "true"
},
"startPoint": {
"latitude": 45.69539,
"longitude": 35.43936
},
"endPoint": {
"latitude": 45.69567,
"longitude": 35.440113
},
"expectedResults": {
"26545": "TL|C|C|C|+TR"
}
}
]