@Test
  public void testCopyTo() {
    graph = createGraph();
    initExampleGraph(graph);
    GraphStorage gs = newRAMGraph();
    gs.setSegmentSize(8000);
    gs.create(10);
    try {
      graph.copyTo(gs);
      checkExampleGraph(gs);
    } catch (Exception ex) {
      ex.printStackTrace();
      assertTrue(ex.toString(), false);
    }

    try {
      Helper.close((Closeable) graph);
      graph = createGraph();
      gs.copyTo(graph);
      checkExampleGraph(graph);
    } catch (Exception ex) {
      ex.printStackTrace();
      assertTrue(ex.toString(), false);
    }
    Helper.close((Closeable) graph);
  }
  @Test
  public void testSinglePoints120() {
    Graph g = createSampleGraph(new EncodingManager("car"));
    idx = createIndex(g, -1);

    assertEquals(1, findID(idx, 1.637, 2.23));
    assertEquals(10, findID(idx, 3.649, 1.375));
    assertEquals(9, findID(idx, 3.3, 2.2));
    assertEquals(6, findID(idx, 3.0, 1.5));

    assertEquals(10, findID(idx, 3.8, 0));
    assertEquals(10, findID(idx, 3.8466, 0.021));
    Helper.close((Closeable) g);
  }
 @Test
 public void testNoErrorOnEdgeCase_lastIndex() {
   final EncodingManager encodingManager = new EncodingManager("car");
   int locs = 10000;
   Graph g =
       AbstractLocationIndexTester.this.createGHStorage(
           new MMapDirectory(location), encodingManager, false);
   NodeAccess na = g.getNodeAccess();
   Random rand = new Random(12);
   for (int i = 0; i < locs; i++) {
     na.setNode(i, (float) rand.nextDouble() * 10 + 10, (float) rand.nextDouble() * 10 + 10);
   }
   idx = createIndex(g, 200);
   Helper.close((Closeable) g);
 }
  @Test
  public void testSinglePoints32() {
    Graph g = createSampleGraph(new EncodingManager("car"));
    idx = createIndex(g, -1);

    // 10 or 6
    assertEquals(10, findID(idx, 3.649, 1.375));
    assertEquals(10, findID(idx, 3.8465748, 0.021762699));
    if (hasEdgeSupport()) {
      assertEquals(4, findID(idx, 2.485, 1.373));
    } else {
      assertEquals(6, findID(idx, 2.485, 1.373));
    }
    assertEquals(0, findID(idx, 0.64628404, 0.53006625));
    Helper.close((Closeable) g);
  }
  @Test
  public void testGetLocations() {
    graph = createGraph();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 12, 23);
    na.setNode(1, 22, 23);
    assertEquals(2, graph.getNodes());

    graph.edge(0, 1, 10, true);
    assertEquals(2, graph.getNodes());

    graph.edge(0, 2, 10, true);
    assertEquals(3, graph.getNodes());
    Helper.close((Closeable) graph);

    graph = createGraph();
    assertEquals(0, graph.getNodes());
  }
  @Test
  public void testSimpleGraph() {
    Graph g = AbstractLocationIndexTester.this.createGHStorage(new EncodingManager("car"));
    initSimpleGraph(g);

    idx = createIndex(g, -1);
    assertEquals(4, findID(idx, 5, 2));
    assertEquals(3, findID(idx, 1.5, 2));
    assertEquals(0, findID(idx, -1, -1));

    if (hasEdgeSupport())
    // now get the edge 1-4 and not node 6
    {
      assertEquals(4, findID(idx, 4, 0));
    } else {
      assertEquals(6, findID(idx, 4, 0));
    }
    Helper.close((Closeable) g);
  }
  @Test
  public void testDifferentVehicles() {
    final EncodingManager encodingManager = new EncodingManager("car,foot");
    Graph g = AbstractLocationIndexTester.this.createGHStorage(encodingManager);
    initSimpleGraph(g);
    idx = createIndex(g, -1);
    assertEquals(1, findID(idx, 1, -1));

    // now make all edges from node 1 accessible for CAR only
    EdgeIterator iter = g.createEdgeExplorer().setBaseNode(1);
    CarFlagEncoder carEncoder = (CarFlagEncoder) encodingManager.getEncoder("car");
    while (iter.next()) {
      iter.setFlags(carEncoder.setProperties(50, true, true));
    }
    idx.close();

    idx = createIndex(g, -1);
    FootFlagEncoder footEncoder = (FootFlagEncoder) encodingManager.getEncoder("foot");
    assertEquals(2, idx.findClosest(1, -1, new DefaultEdgeFilter(footEncoder)).getClosestNode());
    Helper.close((Closeable) g);
  }
  @Test
  public void testSimpleGraph2() {
    Graph g = AbstractLocationIndexTester.this.createGHStorage(new EncodingManager("car"));
    initSimpleGraph(g);

    idx = createIndex(g, -1);
    assertEquals(4, findID(idx, 5, 2));
    assertEquals(3, findID(idx, 1.5, 2));
    assertEquals(0, findID(idx, -1, -1));
    assertEquals(6, findID(idx, 4.5, -0.5));
    if (hasEdgeSupport()) {
      assertEquals(4, findID(idx, 4, 1));
      assertEquals(4, findID(idx, 4, 0));
    } else {
      assertEquals(6, findID(idx, 4, 1));
      assertEquals(6, findID(idx, 4, 0));
    }
    assertEquals(6, findID(idx, 4, -2));
    assertEquals(5, findID(idx, 3, 3));
    Helper.close((Closeable) g);
  }
  @Test
  public void testClone() {
    graph = createGraph();
    graph.edge(1, 2, 10, true);
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 12, 23);
    na.setNode(1, 8, 13);
    na.setNode(2, 2, 10);
    na.setNode(3, 5, 9);
    graph.edge(1, 3, 10, true);

    Graph clone = graph.copyTo(createGraph(locationParent + "/clone", false));
    assertEquals(graph.getNodes(), clone.getNodes());
    assertEquals(
        count(carOutExplorer.setBaseNode(1)),
        count(clone.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    clone.edge(1, 4, 10, true);
    assertEquals(3, count(clone.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    assertEquals(graph.getBounds(), clone.getBounds());
    Helper.close((Closeable) clone);
  }
  @Test
  public void testGrid() {
    Graph g = createSampleGraph(new EncodingManager("car"));
    int locs = g.getNodes();

    idx = createIndex(g, -1);
    // if we would use less array entries then some points gets the same key so avoid that for this
    // test
    // e.g. for 16 we get "expected 6 but was 9" i.e 6 was overwritten by node j9 which is a bit
    // closer to the grid center
    // go through every point of the graph if all points are reachable
    NodeAccess na = g.getNodeAccess();
    for (int i = 0; i < locs; i++) {
      double lat = na.getLatitude(i);
      double lon = na.getLongitude(i);
      assertEquals("nodeId:" + i + " " + (float) lat + "," + (float) lon, i, findID(idx, lat, lon));
    }

    // hit random lat,lon and compare result to full index
    Random rand = new Random(12);
    LocationIndex fullIndex;
    if (hasEdgeSupport()) fullIndex = new Location2IDFullWithEdgesIndex(g);
    else fullIndex = new Location2IDFullIndex(g);

    DistanceCalc dist = new DistanceCalcEarth();
    for (int i = 0; i < 100; i++) {
      double lat = rand.nextDouble() * 5;
      double lon = rand.nextDouble() * 5;
      int fullId = findID(fullIndex, lat, lon);
      double fullLat = na.getLatitude(fullId);
      double fullLon = na.getLongitude(fullId);
      float fullDist = (float) dist.calcDist(lat, lon, fullLat, fullLon);
      int newId = findID(idx, lat, lon);
      double newLat = na.getLatitude(newId);
      double newLon = na.getLongitude(newId);
      float newDist = (float) dist.calcDist(lat, lon, newLat, newLon);

      if (testGridIgnore(i)) {
        continue;
      }

      assertTrue(
          i
              + " orig:"
              + (float) lat
              + ","
              + (float) lon
              + " full:"
              + fullLat
              + ","
              + fullLon
              + " fullDist:"
              + fullDist
              + " found:"
              + newLat
              + ","
              + newLon
              + " foundDist:"
              + newDist,
          Math.abs(fullDist - newDist) < 50000);
    }
    fullIndex.close();
    Helper.close((Closeable) g);
  }
 @After
 public void tearDown() {
   Helper.close((Closeable) graph);
   Helper.removeDir(new File(locationParent));
 }