예제 #1
0
  public void testUndirectedSimple() {
    UndiGraph<String, String> graph = new LinkedUndirectedGraph<String, String>();
    graph.createNode("a");
    graph.createNode("b");
    graph.createNode("c");
    graph.connect("a", "--", "b");
    assertTrue(graph.hasNode("a"));
    assertTrue(graph.hasNode("b"));
    assertTrue(graph.hasNode("c"));
    assertFalse(graph.hasNode("d"));
    assertTrue(graph.isConnected("a", "b"));
    assertTrue(graph.isConnected("b", "a"));
    assertFalse(graph.isConnected("a", "c"));
    assertFalse(graph.isConnected("b", "c"));
    assertFalse(graph.isConnected("c", "a"));
    assertFalse(graph.isConnected("c", "b"));
    assertFalse(graph.isConnected("a", "a"));
    assertFalse(graph.isConnected("b", "b"));
    assertFalse(graph.isConnected("b", "c"));

    // Removal.
    graph.disconnect("a", "b");
    assertFalse(graph.isConnected("a", "b"));
    assertFalse(graph.isConnected("b", "a"));
  }
예제 #2
0
  public void testUndirectedNeighbors() {
    UndiGraph<String, String> graph = new LinkedUndirectedGraph<String, String>();
    graph.createNode("a");
    graph.createNode("b");
    graph.createNode("c");
    graph.createNode("d");
    graph.connect("a", "-", "b");
    graph.connect("a", "--", "b");
    graph.connect("a", "---", "b");
    graph.connect("a", "-", "c");
    graph.connect("c", "-", "d");
    assertSetEquals(graph.getNeighborNodes("a"), "b", "c");
    assertSetEquals(graph.getNeighborNodes("b"), "a");
    assertSetEquals(graph.getNeighborNodes("c"), "a", "d");
    assertListCount(graph.getNeighborNodes("a"), "b", 3);

    // Removal.
    graph.disconnect("a", "b");
    assertFalse(graph.isConnected("a", "b"));
  }
예제 #3
0
  public void testSimpleSubGraph() {
    UndiGraph<String, String> graph = new LinkedUndirectedGraph<String, String>();
    graph.createNode("a");
    graph.createNode("b");
    graph.createNode("c");
    graph.connect("a", "--", "b");

    SubGraph<String, String> subGraph = graph.newSubGraph();
    subGraph.addNode("a");
    subGraph.addNode("b");

    try {
      subGraph.addNode("d");
      fail("SubGraph should not allow add for node that is not in graph.");
    } catch (IllegalArgumentException e) {
      // exception expected
    }

    assertFalse(subGraph.isIndependentOf("a"));
    assertFalse(subGraph.isIndependentOf("b"));
    assertTrue(subGraph.isIndependentOf("c"));
  }