示例#1
0
 public void testInverse() {
   Edge[] edges = {newEdge(0), newEdge(1), newEdge(2), newEdge(3)};
   for (Edge e : edges) {
     path = path.append(e.asPath());
   }
   path = path.reverse();
   checkIndexedGets(path, new Edge[] {edges[3], edges[2], edges[1], edges[0]}, true);
   assertEquals(n[4], path.headNode());
   assertEquals(path.getEdge(0), g.anEdge(n[4], n[3]));
   assertEquals(path.getEdge(1), g.anEdge(n[3], n[2]));
   assertEquals(path.getEdge(2), g.anEdge(n[2], n[1]));
   assertEquals(path.getEdge(3), g.anEdge(n[1], n[0]));
 }
示例#2
0
  public void testHamiltonEuler() {
    path = path.append(newEdge(0, 1).asPath());
    // 0--1
    assertTrue(path.isHamilton());
    assertTrue(path.isEuler());

    path = path.append(newEdge(1, 0).asPath());
    // 0--1--0
    assertFalse(path.isHamilton());
    assertTrue(path.isEuler());

    path = path.append(newEdge(0, 2).asPath());
    // 0--1--0--2
    assertFalse(path.isHamilton());
    assertTrue(path.isEuler());

    path = path.append(newEdge(2, 1).asPath());
    // 0--1--0--2--1
    assertFalse(path.isHamilton());
    assertTrue(path.isEuler());

    path = path.append(g.anEdge(n[1], n[0]).asPath());
    // 0--1--0--2--1--0
    assertFalse(path.isHamilton());
    assertFalse(path.isEuler());
  }
示例#3
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
    }
  }
示例#4
0
  public void testFindAndContains() {
    path = path.append(newEdge(0).asPath()).append(newEdge(1).asPath());
    Path temp;
    temp = g.anEdge(n[0], n[1]).asPath();
    assertEquals(0, path.find(temp));
    assertTrue(path.contains(temp));

    temp = g.anEdge(n[1], n[2]).asPath();
    assertEquals(1, path.find(temp));
    assertTrue(path.contains(temp));

    temp = path;
    assertEquals(0, path.find(temp));
    assertTrue(path.contains(temp));

    temp = path;
    assertEquals(-1, path.find(path, 1));
    assertTrue(path.contains(temp));

    temp = n[2].asPath();
    assertEquals(2, path.find(temp));
    assertTrue(path.contains(temp));
  }
示例#5
0
  public void testEquality() {
    checkEqual(path, path, true);
    checkEqual(path, n[0].asPath(), true);
    Path p2 = path.append(newEdge(0).asPath());
    checkEqual(path, p2, false);

    path = path.append(g.anEdge(n[0], n[1]).asPath());
    checkEqual(path, p2, true);

    path = path.tailPath(0);
    checkEqual(path, p2, false);

    p2 = p2.tailPath(0);
    checkEqual(path, p2, true);
  }