Ejemplo n.º 1
0
  @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();
  }
Ejemplo n.º 2
0
  @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) {
    }
  }
Ejemplo n.º 3
0
  @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);
  }
Ejemplo n.º 4
0
  @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);
  }