Add test RouteResultPreparationTest.java
This commit is contained in:
parent
45ea4d46cc
commit
d480cbc9d2
4 changed files with 270 additions and 1 deletions
|
@ -9,6 +9,8 @@
|
||||||
<property name="bin.dir" value="bin" />
|
<property name="bin.dir" value="bin" />
|
||||||
<property name="bin.absolute.dir" location="${bin.dir}" />
|
<property name="bin.absolute.dir" location="${bin.dir}" />
|
||||||
<property name="lib.dir" value="libs" />
|
<property name="lib.dir" value="libs" />
|
||||||
|
<property name="unit.dir" value="test/java" />
|
||||||
|
<property name="unit.absolute.dir" location="${unit.dir}" />
|
||||||
<property name="lib.absolute.dir" location="${lib.dir}" />
|
<property name="lib.absolute.dir" location="${lib.dir}" />
|
||||||
<property name="java.encoding" value="UTF-8" />
|
<property name="java.encoding" value="UTF-8" />
|
||||||
|
|
||||||
|
@ -18,6 +20,11 @@
|
||||||
</fileset>
|
</fileset>
|
||||||
</path>
|
</path>
|
||||||
|
|
||||||
|
<path id="unit.test.path">
|
||||||
|
<path refid="build.path"/>
|
||||||
|
<pathelement path="test/java"/>
|
||||||
|
</path>
|
||||||
|
|
||||||
<target name="-dirs">
|
<target name="-dirs">
|
||||||
<mkdir dir="${bin.absolute.dir}" />
|
<mkdir dir="${bin.absolute.dir}" />
|
||||||
</target>
|
</target>
|
||||||
|
@ -27,6 +34,29 @@
|
||||||
<delete file="OsmAnd-core.jar" />
|
<delete file="OsmAnd-core.jar" />
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
<target name="compileUnitTests" depends="compile">
|
||||||
|
<javac srcdir="test/" destdir="${bin.absolute.dir}">
|
||||||
|
<classpath refid="unit.test.path"/>
|
||||||
|
</javac>
|
||||||
|
<copy todir="${bin.absolute.dir}">
|
||||||
|
<fileset dir="test/java">
|
||||||
|
<include name="**/*.json" />
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="run-route-test" >
|
||||||
|
<junit printsummary="yes" haltonfailure="yes" showoutput="yes">
|
||||||
|
<classpath>
|
||||||
|
<pathelement path="bin"/>
|
||||||
|
<path refid="build.path"/>
|
||||||
|
</classpath>
|
||||||
|
<test name="net.osmand.router.RouteResultPreparationTest" haltonfailure="no" outfile="result">
|
||||||
|
<formatter type="plain"/>
|
||||||
|
<formatter type="xml"/>
|
||||||
|
</test>
|
||||||
|
</junit>
|
||||||
|
</target>
|
||||||
|
|
||||||
<target name="copy_resources">
|
<target name="copy_resources">
|
||||||
<copy todir="${src.absolute.dir}/net/osmand/router/">
|
<copy todir="${src.absolute.dir}/net/osmand/router/">
|
||||||
|
@ -90,7 +120,7 @@
|
||||||
<antcall target="jar" />
|
<antcall target="jar" />
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="jar" depends="compile">
|
<target name="jar" depends="compile, compileUnitTests">
|
||||||
<manifestclasspath property="lib.list" jarfile="OsmAnd-core.jar">
|
<manifestclasspath property="lib.list" jarfile="OsmAnd-core.jar">
|
||||||
<classpath refid="build.path" />
|
<classpath refid="build.path" />
|
||||||
</manifestclasspath>
|
</manifestclasspath>
|
||||||
|
@ -111,6 +141,9 @@
|
||||||
<fileset dir="${src.absolute.dir}">
|
<fileset dir="${src.absolute.dir}">
|
||||||
<include name="**/*.java" />
|
<include name="**/*.java" />
|
||||||
</fileset>
|
</fileset>
|
||||||
|
<fileset dir="${unit.absolute.dir}">
|
||||||
|
<include name="**/*.java" />
|
||||||
|
</fileset>
|
||||||
</jar>
|
</jar>
|
||||||
<jar destfile="OsmAnd-core-android.jar" manifest="MANIFEST.MF">
|
<jar destfile="OsmAnd-core-android.jar" manifest="MANIFEST.MF">
|
||||||
<fileset dir="${bin.absolute.dir}">
|
<fileset dir="${bin.absolute.dir}">
|
||||||
|
|
|
@ -0,0 +1,151 @@
|
||||||
|
package net.osmand.router;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.binary.BinaryMapIndexReader;
|
||||||
|
import net.osmand.data.LatLon;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by yurkiss on 04.03.16.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RunWith(Parameterized.class)
|
||||||
|
public class RouteResultPreparationTest {
|
||||||
|
|
||||||
|
private static RoutePlannerFrontEnd fe;
|
||||||
|
private static RoutingContext ctx;
|
||||||
|
|
||||||
|
private String testName;
|
||||||
|
private LatLon startPoint;
|
||||||
|
private LatLon endPoint;
|
||||||
|
private Map<Long, String> expectedResults;
|
||||||
|
|
||||||
|
private Log log = PlatformUtil.getLog(RouteResultPreparationTest.class);
|
||||||
|
|
||||||
|
public RouteResultPreparationTest(String testName, LatLon startPoint, LatLon endPoint, Map<Long, String> expectedResults) {
|
||||||
|
this.testName = testName;
|
||||||
|
this.startPoint = startPoint;
|
||||||
|
this.endPoint = endPoint;
|
||||||
|
this.expectedResults = expectedResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUp() throws Exception {
|
||||||
|
String fileName = "../../../osmand/Turn_lanes_test.obf";
|
||||||
|
String fileName2 = "../../../osmand/World_basemap_2.obf";
|
||||||
|
|
||||||
|
File fl = new File(fileName);
|
||||||
|
File fl2 = new File(fileName2);
|
||||||
|
|
||||||
|
RandomAccessFile raf = new RandomAccessFile(fl, "r");
|
||||||
|
RandomAccessFile raf2 = new RandomAccessFile(fl2, "r");
|
||||||
|
|
||||||
|
fe = new RoutePlannerFrontEnd(false);
|
||||||
|
RoutingConfiguration.Builder builder = RoutingConfiguration.getDefault();
|
||||||
|
Map<String, String> params = new LinkedHashMap<String, String>();
|
||||||
|
params.put("car", "true");
|
||||||
|
params.put("short_way", "true");
|
||||||
|
RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3, params);
|
||||||
|
BinaryMapIndexReader[] binaryMapIndexReaders = {new BinaryMapIndexReader(raf2, fl2), new BinaryMapIndexReader(raf, fl)};
|
||||||
|
ctx = fe.buildRoutingContext(config, null, binaryMapIndexReaders,
|
||||||
|
RoutePlannerFrontEnd.RouteCalculationMode.NORMAL);
|
||||||
|
ctx.leftSideNavigation = false;
|
||||||
|
RouteResultPreparation.PRINT_TO_CONSOLE_ROUTE_INFORMATION_TO_TEST = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Parameterized.Parameters(name = "{index}: {0}")
|
||||||
|
public static Collection<Object[]> data() throws IOException {
|
||||||
|
|
||||||
|
InputStream inputStream = RouteResultPreparationTest.class.getResourceAsStream("test_routes.json");
|
||||||
|
//InputStream inputStream = new FileInputStream("test_routes.json");
|
||||||
|
Reader reader = new InputStreamReader(inputStream);
|
||||||
|
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) {
|
||||||
|
Object[] arr = new Object[]{
|
||||||
|
testEntries[i].getTestName(),
|
||||||
|
testEntries[i].getStartPoint(),
|
||||||
|
testEntries[i].getEndPoint(),
|
||||||
|
testEntries[i].getExpectedResults()
|
||||||
|
};
|
||||||
|
twoDArray.add(arr);
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
return twoDArray;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLanes() throws Exception {
|
||||||
|
|
||||||
|
List<RouteSegmentResult> routeSegments = fe.searchRoute(ctx, startPoint, endPoint, null);
|
||||||
|
|
||||||
|
int prevSegment = -1;
|
||||||
|
for (int i = 0; i <= routeSegments.size(); i++) {
|
||||||
|
if (i == routeSegments.size() || routeSegments.get(i).getTurnType() != null) {
|
||||||
|
if (prevSegment >= 0) {
|
||||||
|
String lanes = getLanesString(routeSegments.get(prevSegment));
|
||||||
|
String name = routeSegments.get(prevSegment).getDescription();
|
||||||
|
|
||||||
|
long segmentId = routeSegments.get(prevSegment).getObject().getId();
|
||||||
|
String expectedResult = expectedResults.get(segmentId);
|
||||||
|
if (expectedResult != null) {
|
||||||
|
Assert.assertEquals("Segment " + segmentId, expectedResult, lanes);
|
||||||
|
} else {
|
||||||
|
//TODO: action if needed when expectedResults is null
|
||||||
|
}
|
||||||
|
|
||||||
|
//Assert.fail("FAILED!");
|
||||||
|
System.out.println("segmentId: " + segmentId + " description: " + name);
|
||||||
|
|
||||||
|
}
|
||||||
|
prevSegment = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String getLanesString(RouteSegmentResult segment) {
|
||||||
|
String turn = segment.getTurnType().toString();
|
||||||
|
final int[] lns = segment.getTurnType().getLanes();
|
||||||
|
if (lns != null) {
|
||||||
|
String s = "";
|
||||||
|
for (int h = 0; h < lns.length; h++) {
|
||||||
|
if (h > 0) {
|
||||||
|
s += ", ";
|
||||||
|
}
|
||||||
|
if (lns[h] % 2 == 1) {
|
||||||
|
s += "+";
|
||||||
|
}
|
||||||
|
int pt = TurnType.getPrimaryTurn(lns[h]);
|
||||||
|
if (pt == 0) {
|
||||||
|
pt = 1;
|
||||||
|
}
|
||||||
|
s += TurnType.valueOf(pt, false).toXmlString();
|
||||||
|
int st = TurnType.getSecondaryTurn(lns[h]);
|
||||||
|
if (st != 0) {
|
||||||
|
s += ";" + TurnType.valueOf(st, false).toXmlString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
s += "";
|
||||||
|
turn += s;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
51
OsmAnd-java/test/java/net/osmand/router/TestEntry.java
Normal file
51
OsmAnd-java/test/java/net/osmand/router/TestEntry.java
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package net.osmand.router;
|
||||||
|
|
||||||
|
import net.osmand.data.LatLon;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by User on 07.03.2016.
|
||||||
|
*/
|
||||||
|
public class TestEntry {
|
||||||
|
|
||||||
|
private String testName;
|
||||||
|
private LatLon startPoint;
|
||||||
|
private LatLon endPoint;
|
||||||
|
private Map<Long, String> expectedResults;
|
||||||
|
|
||||||
|
public LatLon getStartPoint() {
|
||||||
|
return startPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartPoint(LatLon startPoint) {
|
||||||
|
this.startPoint = startPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LatLon getEndPoint() {
|
||||||
|
return endPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndPoint(LatLon endPoint) {
|
||||||
|
this.endPoint = endPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Long, String> getExpectedResults() {
|
||||||
|
return expectedResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExpectedResults(Map<Long, String> expectedResults) {
|
||||||
|
this.expectedResults = expectedResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTestName() {
|
||||||
|
return testName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TestEntry(String testName, LatLon startPoint, LatLon endPoint, Map<Long, String> expectedResults) {
|
||||||
|
this.testName = testName;
|
||||||
|
this.startPoint = startPoint;
|
||||||
|
this.endPoint = endPoint;
|
||||||
|
this.expectedResults = expectedResults;
|
||||||
|
}
|
||||||
|
}
|
34
OsmAnd-java/test/java/net/osmand/router/test_routes.json
Normal file
34
OsmAnd-java/test/java/net/osmand/router/test_routes.json
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"testName": "Amstelveenseweg",
|
||||||
|
"startPoint": {
|
||||||
|
"longitude": 35.51630312204361,
|
||||||
|
"latitude": 45.6971206184178
|
||||||
|
},
|
||||||
|
"endPoint": {
|
||||||
|
"longitude": 35.51303619146347,
|
||||||
|
"latitude": 45.6952846638807
|
||||||
|
},
|
||||||
|
"expectedResults": {
|
||||||
|
"-94307": "+TL, +TL, +TL, C, TR, TR",
|
||||||
|
"-96062": "+TL, +TL, +TL, +C, TR, TR",
|
||||||
|
"-96063": "+TL, +TL, +TL, C, TR, TR"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"testName": "Amstelveenseweg2",
|
||||||
|
"startPoint": {
|
||||||
|
"longitude": 35.51630312204361,
|
||||||
|
"latitude": 45.6971206184178
|
||||||
|
},
|
||||||
|
"endPoint": {
|
||||||
|
"longitude": 35.51303619146347,
|
||||||
|
"latitude": 45.6952846638807
|
||||||
|
},
|
||||||
|
"expectedResults": {
|
||||||
|
"-96061": "+TL, +TL, +TL, +C, TR, TR",
|
||||||
|
"-96062": "+TL, +TL, +TL, C, TR, TR",
|
||||||
|
"-96063": "+TL, +TL, +TL, +C, TR, TR"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
Loading…
Reference in a new issue