package edu.uci.ics.jung.algorithms.generators.random;
/**
* @author W. Giordano, Scott White
*/
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import com.google.common.base.Supplier;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.UndirectedGraph;
import edu.uci.ics.jung.graph.UndirectedSparseMultigraph;
public class TestErdosRenyi extends TestCase {
Supplier> graphFactory;
Supplier vertexFactory;
Supplier edgeFactory;
public static Test suite() {
return new TestSuite(TestErdosRenyi.class);
}
@Override
protected void setUp() {
graphFactory = new Supplier>() {
public UndirectedGraph get() {
return new UndirectedSparseMultigraph();
}
};
vertexFactory = new Supplier() {
int count;
public String get() {
return Character.toString((char)('A'+count++));
}
};
edgeFactory =
new Supplier() {
int count;
public Number get() {
return count++;
}
};
}
public void test() {
int numVertices = 100;
int total = 0;
for (int i = 1; i <= 10; i++) {
ErdosRenyiGenerator generator =
new ErdosRenyiGenerator(graphFactory, vertexFactory, edgeFactory,
numVertices,0.1);
generator.setSeed(0);
Graph graph = generator.get();
Assert.assertTrue(graph.getVertexCount() == numVertices);
total += graph.getEdgeCount();
}
total /= 10.0;
Assert.assertTrue(total > 495-50 && total < 495+50);
}
}
Ads help maintain this website.