@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); }
@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 testSetSpeed0_issue367() { long flags = encoder.setProperties(10, true, true); flags = encoder.setSpeed(flags, encoder.speedFactor * 0.49); assertEquals(0, encoder.getSpeed(flags), .1); assertEquals(0, encoder.getReverseSpeed(flags), .1); assertFalse(encoder.isForward(flags)); assertFalse(encoder.isBackward(flags)); }
@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 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 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 testSetSpeed() { assertEquals(10, encoder.getSpeed(encoder.setSpeed(0, 10)), 1e-1); }