Exemplo n.º 1
0
 public void testEdge() {
   try {
     path.tailEdge();
     fail();
   } catch (NoSuchElementException ok) {
   }
   assertEquals(n[0], path.headNode());
   assertEquals(n[0], path.tailNode());
   Edge e = newEdge(0);
   path = path.append(e.asPath());
   assertEquals(e, path.tailEdge());
   assertEquals(e.n2(), path.tailNode());
   e = newEdge(1);
   path = path.append(e.asPath());
   assertEquals(e, path.tailEdge());
   assertEquals(e.n2(), path.tailNode());
 }
Exemplo n.º 2
0
 public void testDefaultEdgePathOrientation() {
   Graph g = new PrimaryGraph();
   Node n1 = g.newNode();
   Node n2 = g.newNode();
   Edge e = g.newEdge(n1, n2);
   Path p = e.asPath();
   assertEquals(n1, p.headNode());
   assertEquals(n2, p.tailNode());
 }
Exemplo n.º 3
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
    }
  }
Exemplo n.º 4
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));
  }
Exemplo n.º 5
0
  public void testAppend() {
    Path p2 = n[1].asPath();
    p2 = p2.append(newEdge(1).asPath());

    try {
      Path p3 = path.append(p2);
      fail("Allowed illegal path concatenation");
    } catch (RuntimeException e) {
      // ok
    }
    Path p3 = newEdge(0).asPath();
    path = path.append(p3);
    assertEquals(1, path.size());
    path = path.append(newEdge(1).asPath());
    assertEquals(2, path.size());
    path = path.tailPath(1);
    assertEquals(1, path.size());
    assertEquals(n[1], path.headNode());
    assertEquals(n[2], path.tailNode());
  }
Exemplo n.º 6
0
  public void testReplaceFirst() {
    path = path.append(newEdge(0).asPath()).append(newEdge(1).asPath());
    Path p = path.replaceFirst(g.anEdge(n[0], n[1]).asPath(), n[1].asPath());
    assertEquals(1, p.size());
    assertEquals(n[1], p.headNode());
    assertEquals(n[2], p.tailNode());

    try {
      Path p2 = path.replaceFirst(g.anEdge(n[0], n[1]).asPath(), n[0].asPath());
      fail("Illegal replacement path allowed");
    } catch (RuntimeException e) {
      // ok
    }

    try {
      Path p3 = path.replaceFirst(g.anEdge(n[0], n[1]).asPath(), g.newEdge(n[0], n[2]).asPath());
      fail("Illegal replacement path allowed");
    } catch (RuntimeException e) {
      // ok
    }
  }