Repository: graphhopper/graphhopper
Pull request #2728 (2023-01-20 11:00:55)

Test access and speed instead of just flags.isEmpty() for foot and bike parsers


Patch:
diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/OSMBikeNetworkTagParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/OSMBikeNetworkTagParser.java
index 15f11e5ce..072ca09bf 100644
--- a/core/src/main/java/com/graphhopper/routing/util/parsers/OSMBikeNetworkTagParser.java
+++ b/core/src/main/java/com/graphhopper/routing/util/parsers/OSMBikeNetworkTagParser.java
@@ -63,4 +63,8 @@ public class OSMBikeNetworkTagParser implements RelationTagParser {
         RouteNetwork routeNetwork = transformerRouteRelEnc.getEnum(false, relationFlags);
         bikeRouteEnc.setEnum(false, edgeFlags, routeNetwork);
     }
+
+    public EnumEncodedValue<RouteNetwork> getTransformerRouteRelEnc() {
+        return transformerRouteRelEnc;
+    }
 }


Test patch:
diff --git a/core/src/test/java/com/graphhopper/reader/osm/OSMReaderTest.java b/core/src/test/java/com/graphhopper/reader/osm/OSMReaderTest.java
index 91b577a7c..687426d3b 100644
--- a/core/src/test/java/com/graphhopper/reader/osm/OSMReaderTest.java
+++ b/core/src/test/java/com/graphhopper/reader/osm/OSMReaderTest.java
@@ -491,22 +491,29 @@ public class OSMReaderTest {
         osmRel.add(new ReaderRelation.Member(ReaderElement.Type.WAY, 1, ""));
         osmRel.add(new ReaderRelation.Member(ReaderElement.Type.WAY, 2, ""));
 
+        // this is pretty ugly: the bike network parser writes to the edge flags we pass into it, but at a location we
+        // don't know, so we need to get the internal enc to read the flags below
+        EnumEncodedValue<RouteNetwork> transformEnc = ((OSMBikeNetworkTagParser) osmParsers.getRelationTagParsers().get(0)).getTransformerRouteRelEnc();
+
         osmRel.setTag("route", "bicycle");
         osmRel.setTag("network", "lcn");
 
-        IntsRef flags = manager.createRelationFlags();
-        osmParsers.handleRelationTags(osmRel, flags);
-        assertFalse(flags.isEmpty());
+        IntsRef edgeFlags = manager.createRelationFlags();
+        osmParsers.handleRelationTags(osmRel, edgeFlags);
+        assertEquals(RouteNetwork.LOCAL, transformEnc.getEnum(false, edgeFlags));
 
         // unchanged network
-        IntsRef before = IntsRef.deepCopyOf(flags);
-        osmParsers.handleRelationTags(osmRel, flags);
-        assertEquals(before, flags);
+        IntsRef before = IntsRef.deepCopyOf(edgeFlags);
+        osmParsers.handleRelationTags(osmRel, edgeFlags);
+        assertEquals(before, edgeFlags);
+        assertEquals(RouteNetwork.LOCAL, transformEnc.getEnum(false, before));
+        assertEquals(RouteNetwork.LOCAL, transformEnc.getEnum(false, edgeFlags));
 
         // overwrite network
         osmRel.setTag("network", "ncn");
-        osmParsers.handleRelationTags(osmRel, flags);
-        assertNotEquals(before, flags);
+        osmParsers.handleRelationTags(osmRel, edgeFlags);
+        assertEquals(RouteNetwork.NATIONAL, transformEnc.getEnum(false, edgeFlags));
+        assertNotEquals(before, edgeFlags);
     }
 
     @Test
diff --git a/core/src/test/java/com/graphhopper/routing/util/AbstractBikeTagParserTester.java b/core/src/test/java/com/graphhopper/routing/util/AbstractBikeTagParserTester.java
index 6c6e5282d..caa88c172 100644
--- a/core/src/test/java/com/graphhopper/routing/util/AbstractBikeTagParserTester.java
+++ b/core/src/test/java/com/graphhopper/routing/util/AbstractBikeTagParserTester.java
@@ -44,6 +44,7 @@ public abstract class AbstractBikeTagParserTester {
     protected BooleanEncodedValue roundaboutEnc;
     protected DecimalEncodedValue priorityEnc;
     protected DecimalEncodedValue avgSpeedEnc;
+    protected BooleanEncodedValue accessEnc;
 
     @BeforeEach
     public void setUp() {
@@ -53,6 +54,7 @@ public abstract class AbstractBikeTagParserTester {
         roundaboutEnc = encodingManager.getBooleanEncodedValue(Roundabout.KEY);
         priorityEnc = encodingManager.getDecimalEncodedValue(VehiclePriority.key(parser.getName()));
         avgSpeedEnc = parser.getAverageSpeedEnc();
+        accessEnc = parser.getAccessEnc();
     }
 
     protected abstract EncodingManager createEncodingManager();
@@ -276,25 +278,30 @@ public abstract class AbstractBikeTagParserTester {
 
         way = new ReaderWay(1);
         way.setTag("railway", "platform");
-        IntsRef flags = encodingManager.createEdgeFlags();
-        parser.handleWayTags(flags, way);
-        assertNotEquals(true, flags.isEmpty());
+        IntsRef edgeFlags = encodingManager.createEdgeFlags();
+        parser.handleWayTags(edgeFlags, way);
+        assertEquals(4.0, avgSpeedEnc.getDecimal(false, edgeFlags));
+        assertTrue(accessEnc.getBool(false, edgeFlags));
 
         way = new ReaderWay(1);
         way.setTag("highway", "track");
         way.setTag("railway", "platform");
-        flags = encodingManager.createEdgeFlags();
-        parser.handleWayTags(flags, way);
-        assertNotEquals(true, flags.isEmpty());
+        edgeFlags = encodingManager.createEdgeFlags();
+        parser.handleWayTags(edgeFlags, way);
+        // we use speed=2 for racingbike, 12 for normal bike and 18 for mtb, which does not really make sense
+        // todo: fix this, see #2728
+//        assertEquals(12.0, avgSpeedEnc.getDecimal(false, edgeFlags));
+        assertTrue(accessEnc.getBool(false, edgeFlags));
 
         way = new ReaderWay(1);
         way.setTag("highway", "track");
         way.setTag("railway", "platform");
         way.setTag("bicycle", "no");
 
-        flags = encodingManager.createEdgeFlags();
-        parser.handleWayTags(flags, way);
-        assertTrue(flags.isEmpty());
+        edgeFlags = encodingManager.createEdgeFlags();
+        parser.handleWayTags(edgeFlags, way);
+        assertEquals(0.0, avgSpeedEnc.getDecimal(false, edgeFlags));
+        assertFalse(accessEnc.getBool(false, edgeFlags));
     }
 
     @Test
diff --git a/core/src/test/java/com/graphhopper/routing/util/FootTagParserTest.java b/core/src/test/java/com/graphhopper/routing/util/FootTagParserTest.java
index e00b3b2c4..39c504a3d 100644
--- a/core/src/test/java/com/graphhopper/routing/util/FootTagParserTest.java
+++ b/core/src/test/java/com/graphhopper/routing/util/FootTagParserTest.java
@@ -232,32 +232,36 @@ public class FootTagParserTest {
     public void testRailPlatformIssue366() {
         ReaderWay way = new ReaderWay(1);
         way.setTag("railway", "platform");
-        IntsRef flags = encodingManager.createEdgeFlags();
-        footParser.handleWayTags(flags, way);
-        assertFalse(flags.isEmpty());
+        IntsRef edgeFlags = encodingManager.createEdgeFlags();
+        footParser.handleWayTags(edgeFlags, way);
+        assertTrue(footAccessEnc.getBool(false, edgeFlags));
+        assertEquals(5, footAvgSpeedEnc.getDecimal(false, edgeFlags));
 
         way.clearTags();
         way.setTag("highway", "track");
         way.setTag("railway", "platform");
-        flags = encodingManager.createEdgeFlags();
-        footParser.handleWayTags(flags, way);
-        assertFalse(flags.isEmpty());
+        edgeFlags = encodingManager.createEdgeFlags();
+        footParser.handleWayTags(edgeFlags, way);
+        assertTrue(footAccessEnc.getBool(false, edgeFlags));
+        assertEquals(5, footAvgSpeedEnc.getDecimal(false, edgeFlags));
 
         way.clearTags();
         // only tram, no highway => no access
         way.setTag("railway", "tram");
-        flags = encodingManager.createEdgeFlags();
-        footParser.handleWayTags(flags, way);
-        assertTrue(flags.isEmpty());
+        edgeFlags = encodingManager.createEdgeFlags();
+        footParser.handleWayTags(edgeFlags, way);
+        assertFalse(footAccessEnc.getBool(false, edgeFlags));
+        assertEquals(0, footAvgSpeedEnc.getDecimal(false, edgeFlags));
     }
 
     @Test
     public void testPier() {
         ReaderWay way = new ReaderWay(1);
         way.setTag("man_made", "pier");
-        IntsRef flags = encodingManager.createEdgeFlags();
-        footParser.handleWayTags(flags, way);
-        assertFalse(flags.isEmpty());
+        IntsRef edgeFlags = encodingManager.createEdgeFlags();
+        footParser.handleWayTags(edgeFlags, way);
+        assertTrue(footAccessEnc.getBool(false, edgeFlags));
+        assertEquals(5, footAvgSpeedEnc.getDecimal(false, edgeFlags));
     }
 
     @Test
@@ -279,16 +283,22 @@ public class FootTagParserTest {
         way.setTag("highway", "motorway");
         IntsRef flags = encodingManager.createEdgeFlags();
         footParser.handleWayTags(flags, way);
-        assertEquals(0, flags.ints[0]);
+        assertFalse(footAccessEnc.getBool(false, flags));
+        assertFalse(footAccessEnc.getBool(true, flags));
+        assertEquals(0, footAvgSpeedEnc.getDecimal(false, flags));
 
         way.setTag("sidewalk", "yes");
         flags = encodingManager.createEdgeFlags();
         footParser.handleWayTags(flags, way);
+        assertTrue(footAccessEnc.getBool(false, flags));
+        assertTrue(footAccessEnc.getBool(true, flags));
         assertEquals(5, footAvgSpeedEnc.getDecimal(false, flags), 1e-1);
 
         way.clearTags();
         way.setTag("highway", "track");
         footParser.handleWayTags(flags, way);
+        assertTrue(footAccessEnc.getBool(false, flags));
+        assertTrue(footAccessEnc.getBool(true, flags));
         assertEquals(5, footAvgSpeedEnc.getDecimal(false, flags), 1e-1);
     }
 
diff --git a/core/src/test/java/com/graphhopper/routing/util/TagParsingTest.java b/core/src/test/java/com/graphhopper/routing/util/TagParsingTest.java
index bb5767002..ff18b073a 100644
--- a/core/src/test/java/com/graphhopper/routing/util/TagParsingTest.java
+++ b/core/src/test/java/com/graphhopper/routing/util/TagParsingTest.java
@@ -176,9 +176,9 @@ class TagParsingTest {
         way.setTag("junction", "circular");
         tagParsers.forEach(p -> p.handleWayTags(edgeFlags2, way, relFlags));
 
-        assertTrue(roundaboutEnc.getBool(false, edgeFlags));
+        assertTrue(roundaboutEnc.getBool(false, edgeFlags2));
         for (BooleanEncodedValue accessEnc : accessEncs)
-            assertTrue(accessEnc.getBool(false, edgeFlags));
+            assertTrue(accessEnc.getBool(false, edgeFlags2));
     }
 
 }
\ No newline at end of file
diff --git a/core/src/test/java/com/graphhopper/routing/util/WheelchairTagParserTest.java b/core/src/test/java/com/graphhopper/routing/util/WheelchairTagParserTest.java
index 8d2b7d862..21ffd0e0f 100644
--- a/core/src/test/java/com/graphhopper/routing/util/WheelchairTagParserTest.java
+++ b/core/src/test/java/com/graphhopper/routing/util/WheelchairTagParserTest.java
@@ -298,29 +298,37 @@ public class WheelchairTagParserTest {
     public void testPier() {
         ReaderWay way = new ReaderWay(1);
         way.setTag("man_made", "pier");
-        IntsRef flags = encodingManager.createEdgeFlags();
-        wheelchairParser.handleWayTags(flags, way);
-        assertFalse(flags.isEmpty());
+        IntsRef edgeFlags = encodingManager.createEdgeFlags();
+        wheelchairParser.handleWayTags(edgeFlags, way);
+        assertTrue(wheelchairAccessEnc.getBool(false, edgeFlags));
+        assertTrue(wheelchairAccessEnc.getBool(true, edgeFlags));
+        assertEquals(5, wheelchairAvSpeedEnc.getDecimal(false, edgeFlags));
     }
 
     @Test
     public void testMixSpeedAndSafe() {
         ReaderWay way = new ReaderWay(1);
         way.setTag("highway", "motorway");
-        IntsRef flags = encodingManager.createEdgeFlags();
-        wheelchairParser.handleWayTags(flags, way);
-        assertTrue(flags.isEmpty());
+        IntsRef edgeFlags = encodingManager.createEdgeFlags();
+        wheelchairParser.handleWayTags(edgeFlags, way);
+        assertFalse(wheelchairAccessEnc.getBool(false, edgeFlags));
+        assertFalse(wheelchairAccessEnc.getBool(true, edgeFlags));
+        assertEquals(0, wheelchairAvSpeedEnc.getDecimal(false, edgeFlags));
 
         way.setTag("sidewalk", "yes");
-        flags = encodingManager.createEdgeFlags();
-        wheelchairParser.handleWayTags(flags, way);
-        assertEquals(5, wheelchairAvSpeedEnc.getDecimal(false, flags), .1);
+        edgeFlags = encodingManager.createEdgeFlags();
+        wheelchairParser.handleWayTags(edgeFlags, way);
+        assertTrue(wheelchairAccessEnc.getBool(false, edgeFlags));
+        assertTrue(wheelchairAccessEnc.getBool(true, edgeFlags));
+        assertEquals(5, wheelchairAvSpeedEnc.getDecimal(false, edgeFlags), .1);
 
         way.clearTags();
         way.setTag("highway", "track");
-        flags = encodingManager.createEdgeFlags();
-        wheelchairParser.handleWayTags(flags, way);
-        assertEquals(0, wheelchairAvSpeedEnc.getDecimal(false, flags), .1);
+        edgeFlags = encodingManager.createEdgeFlags();
+        wheelchairParser.handleWayTags(edgeFlags, way);
+        assertFalse(wheelchairAccessEnc.getBool(false, edgeFlags));
+        assertFalse(wheelchairAccessEnc.getBool(true, edgeFlags));
+        assertEquals(0, wheelchairAvSpeedEnc.getDecimal(false, edgeFlags), .1);
     }
 
     @Test