@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 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); }