コード例 #1
0
ファイル: PathTest.java プロジェクト: unidesigner/pyconto
 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());
 }
コード例 #2
0
ファイル: PathTest.java プロジェクト: unidesigner/pyconto
  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
    }
  }
コード例 #3
0
ファイル: PathTest.java プロジェクト: unidesigner/pyconto
 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]));
 }
コード例 #4
0
ファイル: PathTest.java プロジェクト: unidesigner/pyconto
  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));
  }
コード例 #5
0
ファイル: PathTest.java プロジェクト: unidesigner/pyconto
 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());
 }
コード例 #6
0
ファイル: PathTest.java プロジェクト: unidesigner/pyconto
  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());
  }
コード例 #7
0
ファイル: PathTest.java プロジェクト: unidesigner/pyconto
  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
    }
  }
コード例 #8
0
ファイル: PathTest.java プロジェクト: unidesigner/pyconto
 public void testRoot() {
   assertEquals(root, path.headNode());
   Edge e = g.newEdge(n[1], n[0]);
   Path p = e.asPath();
   assertEquals(n[1], p.headNode());
 }