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