View Javadoc
1   package edu.uci.ics.jung.algorithms.generators.random;
2   
3   /**
4    * @author W. Giordano, Scott White
5    */
6   
7   import java.util.HashSet;
8   
9   import junit.framework.Test;
10  import junit.framework.TestCase;
11  import junit.framework.TestSuite;
12  
13  import com.google.common.base.Supplier;
14  
15  import edu.uci.ics.jung.graph.Graph;
16  import edu.uci.ics.jung.graph.SparseMultigraph;
17  
18  
19  public class TestBarabasiAlbert extends TestCase {
20  	public static Test suite() {
21  		return new TestSuite(TestBarabasiAlbert.class);
22  	}
23  
24  	@Override
25    protected void setUp() {
26  	}
27  
28  	public void test() 
29      {
30          int init_vertices = 1;
31          int edges_to_add_per_timestep = 1;
32          int random_seed = 0;
33          int num_tests = 10;
34          int num_timesteps = 10;
35          
36          Supplier<Graph<Integer,Number>> graphFactory =
37          	new Supplier<Graph<Integer,Number>>() {
38          	public Graph<Integer,Number> get() {
39          		return new SparseMultigraph<Integer,Number>();
40          	}
41          };
42      	Supplier<Integer> vertexFactory = 
43      		new Supplier<Integer>() {
44      			int count;
45  				public Integer get() {
46  					return count++;
47  				}};
48  		Supplier<Number> edgeFactory = 
49  		    new Supplier<Number>() {
50  			    int count;
51  				public Number get() {
52  					return count++;
53  				}};
54  
55  	    BarabasiAlbertGenerator<Integer,Number> generator = 
56              new BarabasiAlbertGenerator<Integer,Number>(graphFactory, vertexFactory, edgeFactory,
57              		init_vertices,edges_to_add_per_timestep,random_seed, new HashSet<Integer>());
58  	    for (int i = 1; i <= num_tests; i++) {
59  	        
60  	        generator.evolveGraph(num_timesteps);
61  	        Graph<Integer, Number> graph = generator.get();
62  	        assertEquals(graph.getVertexCount(), (i*num_timesteps) + init_vertices);
63  	        assertEquals(graph.getEdgeCount(), edges_to_add_per_timestep * (i*num_timesteps));
64  	    }
65  	}
66  }