@Test public void testMilitaryAccess() { ReaderWay way = new ReaderWay(1); way.setTag("highway", "track"); way.setTag("access", "military"); assertFalse(encoder.acceptWay(way) > 0); }
@Test public void testApplyBadSurfaceSpeed() { ReaderWay way = new ReaderWay(1); way.setTag("highway", "secondary"); way.setTag("surface", "unpaved"); assertEquals(30, encoder.applyBadSurfaceSpeed(way, 90), 1e-1); }
@Test public void testRoundabout() { long flags = encoder.setAccess(0, true, true); long resFlags = encoder.setBool(flags, FlagEncoder.K_ROUNDABOUT, true); assertTrue(encoder.isBool(resFlags, FlagEncoder.K_ROUNDABOUT)); assertTrue(encoder.isForward(resFlags)); assertTrue(encoder.isBackward(resFlags)); resFlags = encoder.setBool(flags, FlagEncoder.K_ROUNDABOUT, false); assertFalse(encoder.isBool(resFlags, FlagEncoder.K_ROUNDABOUT)); assertTrue(encoder.isForward(resFlags)); assertTrue(encoder.isBackward(resFlags)); ReaderWay way = new ReaderWay(1); way.setTag("highway", "motorway"); flags = encoder.handleWayTags(way, encoder.acceptBit, 0); assertTrue(encoder.isForward(flags)); assertTrue(encoder.isBackward(flags)); assertFalse(encoder.isBool(flags, FlagEncoder.K_ROUNDABOUT)); way.setTag("junction", "roundabout"); flags = encoder.handleWayTags(way, encoder.acceptBit, 0); assertTrue(encoder.isForward(flags)); assertFalse(encoder.isBackward(flags)); assertTrue(encoder.isBool(flags, FlagEncoder.K_ROUNDABOUT)); }
@Test public void testDestinationTag() { ReaderWay way = new ReaderWay(1); way.setTag("highway", "secondary"); assertEquals(60, encoder.getSpeed(way), 1e-1); way.setTag("vehicle", "destination"); long flags = encoder.handleWayTags(way, encoder.acceptWay(way), 0); assertEquals(5, encoder.getSpeed(flags), 1e-1); }
@Test public void testOneway() { ReaderWay way = new ReaderWay(1); way.setTag("highway", "primary"); long flags = encoder.handleWayTags(way, encoder.acceptWay(way), 0); assertTrue(encoder.isForward(flags)); assertTrue(encoder.isBackward(flags)); way.setTag("oneway", "yes"); flags = encoder.handleWayTags(way, encoder.acceptWay(way), 0); assertTrue(encoder.isForward(flags)); assertFalse(encoder.isBackward(flags)); way.clearTags(); way.setTag("highway", "tertiary"); flags = encoder.handleWayTags(way, encoder.acceptWay(way), 0); assertTrue(encoder.isForward(flags)); assertTrue(encoder.isBackward(flags)); way.clearTags(); way.setTag("highway", "tertiary"); way.setTag("vehicle:forward", "no"); flags = encoder.handleWayTags(way, encoder.acceptWay(way), 0); assertFalse(encoder.isForward(flags)); assertTrue(encoder.isBackward(flags)); way.clearTags(); way.setTag("highway", "tertiary"); way.setTag("vehicle:backward", "no"); flags = encoder.handleWayTags(way, encoder.acceptWay(way), 0); assertTrue(encoder.isForward(flags)); assertFalse(encoder.isBackward(flags)); way.clearTags(); }
@Test public void testCombination() { ReaderWay way = new ReaderWay(123); way.setTag("highway", "cycleway"); way.setTag("sac_scale", "hiking"); long flags = em.acceptWay(way); long edgeFlags = em.handleWayTags(way, flags, 0); assertFalse(encoder.isBackward(edgeFlags)); assertFalse(encoder.isForward(edgeFlags)); assertTrue(em.getEncoder("bike").isBackward(edgeFlags)); assertTrue(em.getEncoder("bike").isForward(edgeFlags)); }
@Test public void testMaxValue() { CarFlagEncoder instance = new CarFlagEncoder(10, 0.5, 0); EncodingManager em = new EncodingManager(instance); ReaderWay way = new ReaderWay(1); way.setTag("highway", "motorway_link"); way.setTag("maxspeed", "60 mph"); long flags = instance.handleWayTags(way, 1, 0); // double speed = AbstractFlagEncoder.parseSpeed("60 mph"); // => 96.56 * 0.9 => 86.9 assertEquals(86.9, instance.getSpeed(flags), 1e-1); flags = instance.reverseFlags(flags); assertEquals(86.9, instance.getSpeed(flags), 1e-1); // test that maxPossibleValue is not exceeded way = new ReaderWay(2); way.setTag("highway", "motorway_link"); way.setTag("maxspeed", "70 mph"); flags = instance.handleWayTags(way, 1, 0); assertEquals(101.5, instance.getSpeed(flags), .1); }
@Test public void testFordAccess() { ReaderNode node = new ReaderNode(0, 0.0, 0.0); node.setTag("ford", "yes"); ReaderWay way = new ReaderWay(1); way.setTag("highway", "unclassified"); way.setTag("ford", "yes"); // Node and way are initially blocking assertTrue(encoder.isBlockFords()); assertFalse(encoder.acceptWay(way) > 0); assertTrue(encoder.handleNodeTags(node) > 0); try { // Now they are passable encoder.setBlockFords(false); assertTrue(encoder.acceptWay(way) > 0); assertFalse(encoder.handleNodeTags(node) > 0); } finally { encoder.setBlockFords(true); } }
@Test public void testSpeed() { // limit bigger than default road speed ReaderWay way = new ReaderWay(1); way.setTag("highway", "trunk"); way.setTag("maxspeed", "110"); long allowed = encoder.acceptWay(way); long encoded = encoder.handleWayTags(way, allowed, 0); assertEquals(100, encoder.getSpeed(encoded), 1e-1); way.clearTags(); way.setTag("highway", "residential"); way.setTag("surface", "cobblestone"); allowed = encoder.acceptWay(way); encoded = encoder.handleWayTags(way, allowed, 0); assertEquals(30, encoder.getSpeed(encoded), 1e-1); way.clearTags(); way.setTag("highway", "track"); allowed = encoder.acceptWay(way); encoded = encoder.handleWayTags(way, allowed, 0); assertEquals(15, encoder.getSpeed(encoded), 1e-1); way.clearTags(); way.setTag("highway", "track"); way.setTag("tracktype", "grade1"); allowed = encoder.acceptWay(way); encoded = encoder.handleWayTags(way, allowed, 0); assertEquals(20, encoder.getSpeed(encoded), 1e-1); way.clearTags(); way.setTag("highway", "secondary"); way.setTag("surface", "compacted"); allowed = encoder.acceptWay(way); encoded = encoder.handleWayTags(way, allowed, 0); assertEquals(30, encoder.getSpeed(encoded), 1e-1); try { encoder.setSpeed(0, -1); assertTrue(false); } catch (IllegalArgumentException ex) { } }
@Test public void testSetToMaxSpeed() { ReaderWay way = new ReaderWay(12); way.setTag("maxspeed", "90"); assertEquals(90, encoder.getMaxSpeed(way), 1e-2); }
@Test public void testRailway() { ReaderWay way = new ReaderWay(1); way.setTag("highway", "secondary"); way.setTag("railway", "rail"); assertTrue(encoder.acceptWay(way) > 0); way.clearTags(); way.setTag("highway", "path"); way.setTag("railway", "abandoned"); assertTrue(encoder.acceptWay(way) == 0); way.setTag("highway", "track"); assertTrue(encoder.acceptWay(way) > 0); // this is fully okay as sometimes old rails are on the road way.setTag("highway", "primary"); way.setTag("railway", "historic"); assertTrue(encoder.acceptWay(way) > 0); way.setTag("motorcar", "no"); assertTrue(encoder.acceptWay(way) == 0); way = new ReaderWay(1); way.setTag("highway", "secondary"); way.setTag("railway", "tram"); // but allow tram to be on the same way assertTrue(encoder.acceptWay(way) > 0); way = new ReaderWay(1); way.setTag("route", "shuttle_train"); way.setTag("motorcar", "yes"); way.setTag("bicycle", "no"); // Provide the duration value in seconds: way.setTag("duration:seconds", Long.toString(35 * 60)); way.setTag("estimated_distance", 50000); // accept assertTrue(encoder.acceptWay(way) > 0); // calculate speed from estimated_distance and duration assertEquals(61, encoder.getFerrySpeed(way, 20, 30, 40), 1e-1); // Test for very short and slow 0.5km/h still realisitic ferry way = new ReaderWay(1); way.setTag("route", "ferry"); way.setTag("motorcar", "yes"); // Provide the duration of 12 minutes in seconds: way.setTag("duration:seconds", Long.toString(12 * 60)); way.setTag("estimated_distance", 100); // accept assertTrue(encoder.acceptWay(way) > 0); // We can't store 0.5km/h, but we expect the lowest possible speed (5km/h) assertEquals(2.5, encoder.getFerrySpeed(way, 20, 30, 40), 1e-1); assertEquals(5, encoder.getSpeed(encoder.setSpeed(0, 2.5)), 1e-1); // Test for an unrealisitic long duration way = new ReaderWay(1); way.setTag("route", "ferry"); way.setTag("motorcar", "yes"); // Provide the duration of 2 months in seconds: way.setTag("duration:seconds", Long.toString(87900 * 60)); way.setTag("estimated_distance", 100); // accept assertTrue(encoder.acceptWay(way) > 0); // We have ignored the unrealisitc long duration and take the unknown speed assertEquals(20, encoder.getFerrySpeed(way, 20, 30, 40), 1e-1); }
@Test public void testAccess() { ReaderWay way = new ReaderWay(1); assertFalse(encoder.acceptWay(way) > 0); way.setTag("highway", "service"); assertTrue(encoder.acceptWay(way) > 0); way.setTag("access", "no"); assertFalse(encoder.acceptWay(way) > 0); way.clearTags(); way.setTag("highway", "track"); assertTrue(encoder.acceptWay(way) > 0); way.setTag("motorcar", "no"); assertFalse(encoder.acceptWay(way) > 0); // for now allow grade1+2+3 for every country, see #253 way.clearTags(); way.setTag("highway", "track"); way.setTag("tracktype", "grade2"); assertTrue(encoder.acceptWay(way) > 0); way.setTag("tracktype", "grade4"); assertFalse(encoder.acceptWay(way) > 0); way.clearTags(); way.setTag("highway", "service"); way.setTag("access", "delivery"); assertFalse(encoder.acceptWay(way) > 0); way.clearTags(); way.setTag("highway", "unclassified"); way.setTag("ford", "yes"); assertFalse(encoder.acceptWay(way) > 0); way.setTag("motorcar", "yes"); assertTrue(encoder.acceptWay(way) > 0); way.clearTags(); way.setTag("route", "ferry"); assertTrue(encoder.acceptWay(way) > 0); assertTrue(encoder.isFerry(encoder.acceptWay(way))); way.setTag("motorcar", "no"); assertFalse(encoder.acceptWay(way) > 0); way.clearTags(); way.setTag("route", "ferry"); way.setTag("foot", "yes"); assertFalse(encoder.acceptWay(way) > 0); assertFalse(encoder.isFerry(encoder.acceptWay(way))); way.clearTags(); way.setTag("access", "yes"); way.setTag("motor_vehicle", "no"); assertFalse(encoder.acceptWay(way) > 0); way.clearTags(); way.setTag("highway", "service"); way.setTag("access", "yes"); way.setTag("motor_vehicle", "no"); assertFalse(encoder.acceptWay(way) > 0); way.clearTags(); way.setTag("highway", "service"); way.setTag("access", "no"); way.setTag("motorcar", "yes"); assertTrue(encoder.acceptWay(way) > 0); way.clearTags(); way.setTag("highway", "service"); way.setTag("access", "emergency"); assertFalse(encoder.acceptWay(way) > 0); way.clearTags(); way.setTag("highway", "service"); way.setTag("motor_vehicle", "emergency"); assertFalse(encoder.acceptWay(way) > 0); DateFormat simpleDateFormat = Helper.createFormatter("yyyy MMM dd"); way.clearTags(); way.setTag("highway", "road"); way.setTag( "access:conditional", "no @ (" + simpleDateFormat.format(new Date().getTime()) + ")"); assertFalse(encoder.acceptWay(way) > 0); way.clearTags(); way.setTag("highway", "road"); way.setTag("access", "no"); way.setTag( "access:conditional", "yes @ (" + simpleDateFormat.format(new Date().getTime()) + ")"); assertTrue(encoder.acceptWay(way) > 0); }
@Test public void testMaxSpeed() { ReaderWay way = new ReaderWay(1); way.setTag("highway", "trunk"); way.setTag("maxspeed", "500"); long allowed = encoder.acceptWay(way); long encoded = encoder.handleWayTags(way, allowed, 0); assertEquals(140, encoder.getSpeed(encoded), 1e-1); way = new ReaderWay(1); way.setTag("highway", "primary"); way.setTag("maxspeed:backward", "10"); way.setTag("maxspeed:forward", "20"); encoded = encoder.handleWayTags(way, encoder.acceptWay(way), 0); assertEquals(10, encoder.getSpeed(encoded), 1e-1); way = new ReaderWay(1); way.setTag("highway", "primary"); way.setTag("maxspeed:forward", "20"); encoded = encoder.handleWayTags(way, encoder.acceptWay(way), 0); assertEquals(20, encoder.getSpeed(encoded), 1e-1); way = new ReaderWay(1); way.setTag("highway", "primary"); way.setTag("maxspeed:backward", "20"); encoded = encoder.handleWayTags(way, encoder.acceptWay(way), 0); assertEquals(20, encoder.getSpeed(encoded), 1e-1); way = new ReaderWay(1); way.setTag("highway", "motorway"); way.setTag("maxspeed", "none"); encoded = encoder.handleWayTags(way, encoder.acceptWay(way), 0); assertEquals(125, encoder.getSpeed(encoded), .1); }