Exemplo n.º 1
0
 private void checkIndexedGets(Path path, Edge[] edges, boolean inverted) {
   assertEquals(edges.length, path.edgeCount());
   for (int i = 0; i < edges.length; i++) {
     Node root = inverted ? edges[i].n2() : edges[i].n1();
     Node target = edges[i].opposite(root);
     assertEquals(root, path.getNode(i));
     assertEquals(edges[i], path.getEdge(i));
     assertEquals(target, path.getNode(i + 1));
   }
 }
Exemplo n.º 2
0
  public void testReplaceAll() {
    Path p =
        n[0].asPath()
            .append(newEdge(0, 1).asPath())
            .append(newEdge(1, 0).asPath())
            .append(newEdge(0, 1).asPath());
    Path replacement1 = n[0].asPath().append(newEdge(0, 2).asPath()).append(newEdge(2, 0).asPath());
    Path result1 = p.replaceAll(p.headPath(2), replacement1);
    assertEquals(3, result1.size());
    assertEquals(n[0], result1.getNode(0));
    assertEquals(n[2], result1.getNode(1));
    assertEquals(n[0], result1.getNode(2));
    assertEquals(n[1], result1.getNode(3));

    Path result2 = p.replaceAll(n[0].asPath(), replacement1);
    // was: 0--1--0--1
    // --->  0--2--0--1--0--2--0--1
    assertEquals(7, result2.size());
    assertEquals(n[0], result2.getNode(0));
    assertEquals(n[2], result2.getNode(1));
    assertEquals(n[0], result2.getNode(2));
    assertEquals(n[1], result2.getNode(3));
    assertEquals(n[0], result2.getNode(4));
    assertEquals(n[2], result2.getNode(5));
    assertEquals(n[0], result2.getNode(6));
    assertEquals(n[1], result2.getNode(7));
  }
Exemplo n.º 3
0
  public void testReplace() {
    Path replacement = n[0].asPath().append(newEdge(0, 1).asPath()).append(newEdge(1, 0).asPath());
    Path trivial = path.replace(0, 0, replacement);
    assertEquals(2, trivial.size());
    assertTrue(trivial.isCycle());

    Path repl2 = n[0].asPath().append(newEdge(0, 5).asPath()).append(newEdge(5, 1).asPath());
    Path p = trivial.replace(0, 1, repl2);
    assertEquals(3, p.size());
    assertEquals(n[0], p.headNode());
    assertEquals(n[0], p.tailNode());
    assertEquals(n[5], p.getNode(1));
  }