Skip to content

Commit

Permalink
Implement present/absent points check in the routing test (#21503)
Browse files Browse the repository at this point in the history
* Check present/absent points in the routing test

* Refactor with reachedSegmentPoints
  • Loading branch information
RZR-UA authored Dec 2, 2024
1 parent 409e76c commit 4df7169
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions OsmAnd-java/src/test/java/net/osmand/router/RouteTestingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public void testRouting() throws Exception {
List<RouteSegmentResult> routeSegments = fe.searchRoute(ctx, te.getStartPoint(), te.getEndPoint(),
te.getTransitPoint()).detailed;
Set<Long> reachedSegments = new TreeSet<Long>();
Set<String> reachedSegmentPoints = new TreeSet<>();
Assert.assertNotNull(routeSegments);
int prevSegment = -1;
for (int i = 0; i <= routeSegments.size(); i++) {
Expand All @@ -159,7 +160,13 @@ public void testRouting() throws Exception {
prevSegment = i;
}
if (i < routeSegments.size()) {
reachedSegments.add(routeSegments.get(i).getObject().getId() >> (RouteResultPreparation.SHIFT_ID));
RouteSegmentResult seg = routeSegments.get(i);
long id = seg.getObject().getId() >> RouteResultPreparation.SHIFT_ID;
for (int point = Math.min(seg.getStartPointIndex(), seg.getEndPointIndex());
point <= Math.max(seg.getStartPointIndex(), seg.getEndPointIndex()); point++) {
reachedSegmentPoints.add(id + ":" + point);
}
reachedSegments.add(id);
}
}
Map<String, String> expectedResults = te.getExpectedResults();
Expand All @@ -170,32 +177,33 @@ public void testRouting() throws Exception {
checkRoutingTime(ctx, params);
for (Entry<String, String> es : expectedResults.entrySet()) {
long id = RouterUtilTest.getRoadId(es.getKey());
int point = RouterUtilTest.getRoadStartPoint(es.getKey());
String pointInSegment = id + ":" + point;
switch (es.getValue()) {
case "false":
Assert.assertFalse("Expected segment " + id + " was wrongly reached in route segments "
+ reachedSegments, reachedSegments.contains(id));
if (point == -1) {
Assert.assertFalse("Expected segment " + id + " was wrongly reached in route segments "
+ reachedSegments, reachedSegments.contains(id));
} else {
Assert.assertTrue("Unexpected pointInSegment " + pointInSegment + " is found in "
+ reachedSegmentPoints, !reachedSegmentPoints.contains(pointInSegment));
}
break;
case "true":
Assert.assertTrue("Expected segment " + id + " weren't reached in route segments "
+ reachedSegments, reachedSegments.contains(id));
if (point == -1) {
Assert.assertTrue("Expected segment " + id + " weren't reached in route segments "
+ reachedSegments, reachedSegments.contains(id));
} else {
Assert.assertTrue("Expected pointInSegment " + pointInSegment + " is not found in "
+ reachedSegmentPoints, reachedSegmentPoints.contains(pointInSegment));
}
break;
case "visitedSegments":
Assert.assertTrue("Expected segments visit " + id + " less then actually visited segments "
+ ctx.getVisitedSegments(), ctx.getVisitedSegments() < id);
break;
default: // case ID:N to check exact point within the ID's segment
boolean isFound = false;
int point = Integer.parseInt(es.getValue());
for (RouteSegmentResult seg : routeSegments) {
if (seg.getObject().getId() / 64 == id) {
if (point >= Math.min(seg.getStartPointIndex(), seg.getEndPointIndex()) &&
point <= Math.max(seg.getStartPointIndex(), seg.getEndPointIndex())) {
isFound = true;
break;
}
}
}
Assert.assertTrue("Expected point " + point + " is not found in segment " + id, isFound);
default:
Assert.assertTrue("Invalid key " + es.getKey() + " value " + es.getValue(), false);
break;
}
}
Expand Down

0 comments on commit 4df7169

Please sign in to comment.