Package org.graphstream.graph

Examples of org.graphstream.graph.Graph


  }

  @Test
  public void Test1_GraphToWardGraph() {
    Graph source = new MultiGraph("g1");
    Graph target = new MultiGraph("g2");

    // Start to populate the graph to test the "replay" feature of the
    // proxy.

    source.addNode("A");
    source.addNode("B");
    source.addNode("C");
    source.addEdge("AB", "A", "B");
    source.addEdge("BC", "B", "C");
    source.addEdge("CA", "C", "A");

    source.getNode("A").addAttribute("A1", "foo");
    source.getNode("A").addAttribute("A2", "foo");

    ThreadProxyPipe proxy = new ThreadProxyPipe();
    proxy.addSink(target);
    proxy.init(source, true);

    Thread other = new Thread(new AnotherThread(proxy, target) {
      public void run() {
        // The second part of the test starts
        // in this target thread.

        boolean loop = true;

        do {
          proxy.pump();

          if (target.hasAttribute("STOP!"))
            loop = false;
        } while (loop);
      }

    });
View Full Code Here


      e.printStackTrace();
    }
  }

  public void testOne() throws IOException {
    Graph g = new AdjacencyListGraph("g");
    ThreadProxyPipe tpp = new ThreadProxyPipe();
    tpp.init(g);

    FileSinkDGS dgs1 = new FileSinkDGS();
    FileSinkDGS dgs2 = new FileSinkDGS();
    StringWriter w1 = new StringWriter();
    StringWriter w2 = new StringWriter();

    Actor a = new Actor(tpp);
    Thread t = new Thread(a);

    g.addSink(dgs1);
    tpp.addSink(dgs2);

    dgs1.begin(w1);
    dgs2.begin(w2);
View Full Code Here

import static org.junit.Assert.fail;

public class TestFileSourceGEXF {

  protected Graph readRessource(String url) {
    Graph g = new AdjacencyListGraph(url);
    FileSourceGEXF gexf = new FileSourceGEXF();

    gexf.addSink(g);

    try {
View Full Code Here

    return g;
  }

  @Test
  public void testBasic() {
    Graph g = readRessource("data/basic.gexf");

    assertNotNull(g.getNode("0"));
    assertNotNull(g.getNode("1"));
    assertNotNull(g.getEdge("0"));

    assertEquals(g.getEdge("0").getSourceNode().getId(), "0");
    assertEquals(g.getEdge("0").getTargetNode().getId(), "1");

    assertTrue(g.getNode("0").hasLabel("label"));
    assertTrue(g.getNode("1").hasLabel("label"));

    assertEquals(g.getNode("0").getLabel("label"), "Hello");
    assertEquals(g.getNode("1").getLabel("label"), "Word");

    assertTrue(g.getEdge("0").isDirected());
  }
View Full Code Here

    assertTrue(g.getEdge("0").isDirected());
  }

  @Test
  public void testData() {
    Graph g = readRessource("data/data.gexf");

    String[] nodeLabels = { "Gephi", "Webatlas", "RTGI", "BarabasiLab" };
    String[] edges = { "0", "1", "0", "2", "1", "0", "2", "1", "0", "3" };
    String[] urlValues = { "http://gephi.org", "http://webatlas.fr",
        "http://rtgi.fr", "http://barabasilab.com" };
    Float[] indegreeValues = { 1.0f, 2.0f, 1.0f, 1.0f };
    Boolean[] frogValues = { true, true, true, false };

    assertEquals(g.getAttribute("lastmodifieddate"), "2009-03-20");
    assertEquals(g.getAttribute("creator"), "Gephi.org");
    assertEquals(g.getAttribute("description"), "A Web network");

    for (int i = 0; i < 4; i++) {
      String nid = Integer.toString(i);

      assertNotNull(g.getNode(nid));
      assertTrue(g.getNode(nid).hasLabel("label"));
      assertEquals(g.getNode(nid).getLabel("label"), nodeLabels[i]);

      assertEquals(g.getNode(nid).getAttribute("url"), urlValues[i]);
      assertEquals(g.getNode(nid).getAttribute("indegree"),
          indegreeValues[i]);
      assertEquals(g.getNode(nid).getAttribute("frog"), frogValues[i]);
    }

    for (int i = 0; i < 5; i++) {
      String eid = Integer.toString(i);

      assertNotNull(g.getEdge(eid));
      assertTrue(g.getEdge(eid).isDirected());

      assertEquals(g.getEdge(eid).getSourceNode().getId(), edges[2 * i]);
      assertEquals(g.getEdge(eid).getTargetNode().getId(),
          edges[2 * i + 1]);
    }
  }
View Full Code Here

    }
  }

  @Test
  public void checkAdjacencyListGraph() {
    Graph g = new AdjacencyListGraph("g");

    g.setNodeFactory(new MyALGNodeFactory());
    g.setEdgeFactory(new MyALGEdgeFactory());

    new TestAddRemoveNode<MyALGNode>(g);
    new TestForEachNode<MyALGNode>(g);
    new TestNodeCollection<MyALGNode>(g);
    new TestAddRemoveEdge<MyALGEdge>(g);
View Full Code Here

    new TestEdgeExtremities<MyALGNode>(g);
  }

  @Test
  public void checkSingleGraph() {
    Graph g = new SingleGraph("g");

    g.setNodeFactory(new MySingleNodeFactory());
    g.setEdgeFactory(new MySingleEdgeFactory());

    new TestAddRemoveNode<MySingleNode>(g);
    new TestForEachNode<MySingleNode>(g);
    new TestNodeCollection<MySingleNode>(g);
    new TestAddRemoveEdge<MySingleEdge>(g);
View Full Code Here

    new TestEdgeExtremities<MySingleNode>(g);
  }

  @Test
  public void checkMultiGraph() {
    Graph g = new MultiGraph("g");

    g.setNodeFactory(new MyMultiNodeFactory());
    g.setEdgeFactory(new MyMultiEdgeFactory());

    new TestAddRemoveNode<MyMultiNode>(g);
    new TestForEachNode<MyMultiNode>(g);
    new TestNodeCollection<MyMultiNode>(g);
    new TestAddRemoveEdge<MyMultiEdge>(g);
View Full Code Here

  protected File newTemporaryFile(String suffix) throws IOException {
    return File.createTempFile(getClass().getSimpleName(), suffix);
  }

  protected Graph getGraph(String resource) throws IOException {
    Graph g = new AdjacencyListGraph("test");
    FileSourceDGS in = new FileSourceDGS();

    in.addSink(g);
    in.readAll(getClass().getResourceAsStream(resource));
    in.removeSink(g);
View Full Code Here

    return g;
  }

  @Test
  public void testArrayAttribute() throws IOException {
    Graph g = getGraph("data/attributes_array.dgs");
    Node n = g.getNode(0);

    if (!n.hasArray("a1"))
      fail();

    if (!n.hasArray("a2"))
View Full Code Here

TOP

Related Classes of org.graphstream.graph.Graph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.