use of org.gephi.graph.api.Graph in project gephi by gephi.
the class GraphDensityNGTest method testOneNodeDensity.
@Test
public void testOneNodeDensity() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(1);
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
assertEquals(density, Double.NaN);
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class GraphDensityNGTest method testCompleteGraphWithSelfLoopsDensity.
@Test
public void testCompleteGraphWithSelfLoopsDensity() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(3);
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node n1 = undirectedGraph.getNode("0");
Node n2 = undirectedGraph.getNode("1");
Node n3 = undirectedGraph.getNode("2");
Edge currentEdge = graphModel.factory().newEdge(n1, n1, false);
undirectedGraph.addEdge(currentEdge);
currentEdge = graphModel.factory().newEdge(n2, n2, false);
undirectedGraph.addEdge(currentEdge);
currentEdge = graphModel.factory().newEdge(n3, n3, false);
undirectedGraph.addEdge(currentEdge);
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
assertEquals(density, 2.0);
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class GraphDensityNGTest method testTwoConnectedNodesDensity.
@Test
public void testTwoConnectedNodesDensity() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(2);
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
assertEquals(density, 1.0);
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class GraphDensityNGTest method testNullGraphDensity.
@Test
public void testNullGraphDensity() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
assertEquals(density, 0.0);
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class GraphDensityNGTest method testTwoCompleteGraphsDensity.
@Test
public void testTwoCompleteGraphsDensity() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(4);
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node[] nodes = new Node[4];
for (int i = 0; i < 4; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) (i + 4)).toString());
nodes[i] = currentNode;
undirectedGraph.addNode(currentNode);
}
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 4; j++) {
Edge currentEdge = graphModel.factory().newEdge(nodes[i], nodes[j], false);
undirectedGraph.addEdge(currentEdge);
}
}
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
double expectedAvDegree = 0.4286;
double diff = Math.abs(density - expectedAvDegree);
assertTrue(diff < 0.01);
}
Aggregations