예제 #1
0
 public void testEdgeAnnotations() {
   Graph<String, String> graph = new LinkedUndirectedGraph<String, String>();
   graph.createNode("1");
   graph.createNode("2");
   graph.createNode("3");
   graph.connect("1", "a", "2");
   graph.connect("2", "b", "3");
   GraphEdge<String, String> a = graph.getEdges("1", "2").get(0);
   GraphEdge<String, String> b = graph.getEdges("2", "3").get(0);
   checkAnnotations(graph, a, b);
 }
예제 #2
0
 public void testDirectedConnectIfNotFound(Graph<String, String> graph) {
   graph.createNode("a");
   graph.createNode("b");
   graph.connectIfNotFound("a", "-", "b");
   assertEquals(1, graph.getNodeDegree("a"));
   graph.connectIfNotFound("a", "-", "b");
   assertEquals(1, graph.getNodeDegree("a"));
   graph.connectIfNotFound("a", null, "b");
   assertEquals(2, graph.getNodeDegree("a"));
   graph.connectIfNotFound("a", null, "b");
   assertEquals(2, graph.getNodeDegree("a"));
 }
예제 #3
0
  private static void checkAnnotations(Graph<String, String> graph, Annotatable a, Annotatable b) {
    final Annotation A = new Annotation() {};
    final Annotation B = new Annotation() {};

    // Initially null.
    assertNull(a.getAnnotation());
    assertNull(b.getAnnotation());

    // Test basic setting.
    a.setAnnotation(A);
    b.setAnnotation(B);
    assertSame(A, a.getAnnotation());
    assertSame(B, b.getAnnotation());

    // Test clearing.
    graph.clearEdgeAnnotations();
    graph.clearNodeAnnotations();
    assertNull(a.getAnnotation());
    assertNull(b.getAnnotation());

    a.setAnnotation(A);
    b.setAnnotation(B);
    // Pushing clears.
    graph.pushEdgeAnnotations();
    graph.pushNodeAnnotations();
    assertNull(a.getAnnotation());
    assertNull(b.getAnnotation());
    a.setAnnotation(B);
    b.setAnnotation(B);
    graph.pushEdgeAnnotations();
    graph.pushNodeAnnotations();
    a.setAnnotation(B);
    b.setAnnotation(A);

    // Test restoring then restoring old values with pop.
    assertSame(B, a.getAnnotation());
    assertSame(A, b.getAnnotation());
    graph.popEdgeAnnotations();
    graph.popNodeAnnotations();
    assertSame(B, a.getAnnotation());
    assertSame(B, b.getAnnotation());
    graph.popEdgeAnnotations();
    graph.popNodeAnnotations();
    assertSame(A, a.getAnnotation());
    assertSame(B, b.getAnnotation());
  }
예제 #4
0
 public void testDirectedDegree(Graph<String, String> graph) {
   graph.createNode("a");
   graph.createNode("b");
   graph.createNode("c");
   graph.createNode("d");
   assertEquals(0, graph.getNodeDegree("a"));
   graph.connect("a", "-", "b");
   assertEquals(1, graph.getNodeDegree("a"));
   graph.connect("b", "-", "c");
   assertEquals(1, graph.getNodeDegree("a"));
   graph.connect("a", "-", "c");
   assertEquals(2, graph.getNodeDegree("a"));
   graph.connect("d", "-", "a");
   assertEquals(3, graph.getNodeDegree("a"));
 }
예제 #5
0
 public void testNodeAnnotations() {
   Graph<String, String> graph = new LinkedUndirectedGraph<String, String>();
   GraphNode<String, String> a = graph.createNode("a");
   GraphNode<String, String> b = graph.createNode("b");
   checkAnnotations(graph, a, b);
 }