Ejemplo n.º 1
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));
  }
Ejemplo n.º 2
0
  public void testSlices() {
    Edge[] edges = {newEdge(0), newEdge(1), newEdge(2), newEdge(3)};
    for (Edge e : edges) {
      path = path.append(e.asPath());
    }
    Path p2 = path.slice(1, 3);
    assertEquals(2, p2.size());
    assertEquals(edges[1], p2.steps().iterator().next().tailEdge());
    assertEquals(edges[2], p2.tailEdge());
    try {
      path.slice(2, 1);
      fail("Allowed illegal path slice arguments");
    } catch (RuntimeException e) {
      // ok
    }

    p2 = path.slice(1, 1);
    assertEquals(0, p2.size());
    assertEquals(p2.headNode(), p2.tailNode());
    assertEquals(n[1], p2.headNode());

    p2 = path.headPath(1);
    assertEquals(1, p2.size());
    assertEquals(n[0], p2.headNode());
    assertEquals(n[1], p2.tailNode());
    try {
      path.headPath(-1);
      fail("Allowed illegal head path argument");
    } catch (RuntimeException e) {
      // ok
    }

    p2 = path.tailPath(1);
    assertEquals(1, p2.size());
    assertEquals(n[4], p2.tailNode());
    assertEquals(n[3], p2.headNode());

    try {
      path.tailPath(-1);
      fail("Allowed illegal tail path argument");
    } catch (RuntimeException e) {
      // ok
    }
  }