View Javadoc
1   package edu.uci.ics.jung.algorithms.generators.random;
2   
3   /**
4    * @author W. Giordano, Scott White
5    */
6   
7   import junit.framework.Assert;
8   import junit.framework.Test;
9   import junit.framework.TestCase;
10  import junit.framework.TestSuite;
11  
12  import com.google.common.base.Supplier;
13  
14  import edu.uci.ics.jung.graph.Graph;
15  import edu.uci.ics.jung.graph.UndirectedGraph;
16  import edu.uci.ics.jung.graph.UndirectedSparseMultigraph;
17  
18  
19  public class TestErdosRenyi extends TestCase {
20  	
21  	Supplier<UndirectedGraph<String,Number>> graphFactory;
22  	Supplier<String> vertexFactory;
23  	Supplier<Number> edgeFactory;
24  
25  	public static Test suite() {
26  		return new TestSuite(TestErdosRenyi.class);
27  	}
28  
29  	@Override
30    protected void setUp() {
31  		graphFactory = new Supplier<UndirectedGraph<String,Number>>() {
32  			public UndirectedGraph<String,Number> get() {
33  				return new UndirectedSparseMultigraph<String,Number>();
34  			}
35  		};
36  		vertexFactory = new Supplier<String>() {
37  			int count;
38  			public String get() {
39  				return Character.toString((char)('A'+count++));
40  			}
41  		};
42  		edgeFactory = 
43  			new Supplier<Number>() {
44  			int count;
45  			public Number get() {
46  				return count++;
47  			}
48  		};
49  	}
50  
51  	public void test() {
52  
53          int numVertices = 100;
54          int total = 0;
55  		for (int i = 1; i <= 10; i++) {
56  			ErdosRenyiGenerator<String,Number> generator = 
57  				new ErdosRenyiGenerator<String,Number>(graphFactory, vertexFactory, edgeFactory,
58  					numVertices,0.1);
59              generator.setSeed(0);
60  
61  			Graph<String,Number> graph = generator.get();
62  			Assert.assertTrue(graph.getVertexCount() == numVertices);
63              total += graph.getEdgeCount();
64  		}
65          total /= 10.0;
66          Assert.assertTrue(total > 495-50 && total < 495+50);
67  
68  	}
69  	  
70    
71  }