示例#1
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());
  }
示例#2
0
  public void testToString() {
    assertEquals("[1]", path.toString());
    path = path.append(newEdge(0, 1).asPath());
    assertEquals("[1-->2]", path.toString());

    Edge e = newEdge(2, 1);
    path = path.append(e.asPath(e.n2()));
    assertEquals("[1-->2<--3]", path.toString());
  }
示例#3
0
 public void testSize() {
   assertEquals(0, path.size());
   checkSizeInvariants();
   path = path.append(newEdge(0).asPath());
   assertEquals(1, path.size());
   checkSizeInvariants();
   path = path.append(newEdge(1).asPath());
   assertEquals(2, path.size());
   checkSizeInvariants();
 }
示例#4
0
  public void testIsCycle() {
    assertFalse(path.isCycle());
    path = path.append(newEdge(0).asPath());
    assertFalse(path.isCycle());
    path = path.append(newEdge(1, 0).asPath());
    assertTrue(path.isCycle());
    path = path.append(newEdge(0).asPath());
    assertFalse(path.isCycle());

    assertTrue(path.split(1)[1].isCycle());
  }
示例#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);
  }
示例#6
0
 public void testIndexedGets() {
   Edge[] edges = {newEdge(0), newEdge(1), newEdge(2), newEdge(3)};
   for (Edge e : edges) {
     path = path.append(e.asPath());
   }
   checkIndexedGets(path, edges, false);
 }
示例#7
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());
 }
示例#8
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());
  }
示例#9
0
 public void testNodes() {
   Edge[] edges = {newEdge(0), newEdge(1), newEdge(2), newEdge(3)};
   for (Edge e : edges) {
     path = path.append(e.asPath());
   }
   List<Node> nodes = path.nodes().drainToList();
   for (int i = 0; i < edges.length; i++) {
     assertEquals(edges[i].n1(), nodes.get(i));
   }
   assertEquals(edges[edges.length - 1].n2(), nodes.get(nodes.size() - 1));
 }
示例#10
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]));
 }
示例#11
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
    }
  }
示例#12
0
  public void testSplit() {
    Edge[] edges = {newEdge(0), newEdge(1), newEdge(2), newEdge(3)};
    for (Edge e : edges) {
      path = path.append(e.asPath());
    }
    Path[] paths = path.split(2);
    assertEquals(2, paths[0].size());
    assertEquals(2, paths[1].size());
    assertEquals(n[0], paths[0].headNode());
    assertEquals(n[2], paths[0].tailNode());
    assertEquals(n[2], paths[1].headNode());
    assertEquals(n[4], paths[1].tailNode());

    paths = paths[1].split(2);
    assertEquals(2, paths[0].size());
    assertEquals(0, paths[1].size());
    assertEquals(n[4], paths[1].headNode());
    assertEquals(n[4], paths[1].tailNode());
  }
示例#13
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
    }
  }
示例#14
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));
  }