1 /*
2 * Copyright (c) 2003, The JUNG Authors
3 *
4 * All rights reserved.
5 *
6 * This software is open-source under the BSD license; see either
7 * "license.txt" or
8 * https://github.com/jrtom/jung/blob/master/LICENSE for a description.
9 */
10 package edu.uci.ics.jung.algorithms.generators.random;
11
12 import junit.framework.Assert;
13 import junit.framework.Test;
14 import junit.framework.TestCase;
15 import junit.framework.TestSuite;
16
17 import com.google.common.base.Supplier;
18
19 import edu.uci.ics.jung.graph.Graph;
20 import edu.uci.ics.jung.graph.SparseMultigraph;
21
22 /**
23 * @author Scott White
24 */
25 public class TestEppsteinPowerLawGenerator extends TestCase {
26
27 Supplier<Graph<Integer,Number>> graphFactory;
28 Supplier<Integer> vertexFactory;
29 Supplier<Number> edgeFactory;
30
31 public static Test suite() {
32 return new TestSuite(TestEppsteinPowerLawGenerator.class);
33 }
34
35 @Override
36 protected void setUp() {
37 graphFactory = new Supplier<Graph<Integer,Number>>() {
38 public Graph<Integer,Number> get() {
39 return new SparseMultigraph<Integer,Number>();
40 }
41 };
42 vertexFactory = new Supplier<Integer>() {
43 int count;
44 public Integer get() {
45 return count++;
46 }
47 };
48 edgeFactory =
49 new Supplier<Number>() {
50 int count;
51 public Number get() {
52 return count++;
53 }
54 };
55 }
56
57 public void testSimpleDirectedCase() {
58
59 for (int r=0; r<10; r++) {
60 EppsteinPowerLawGenerator<Integer, Number> generator =
61 new EppsteinPowerLawGenerator<Integer, Number>(graphFactory, vertexFactory, edgeFactory, 10,40,r);
62 generator.setSeed(2);
63
64 Graph<Integer, Number> graph = generator.get();
65 Assert.assertEquals(graph.getVertexCount(),10);
66 Assert.assertEquals(graph.getEdgeCount(),40);
67 }
68
69 }
70
71 // TODO: convert what is needed for this test
72 // public void testPowerLawProperties() {
73 //
74 // //long start = System.currentTimeMillis();
75 // EppsteinPowerLawGenerator generator = new EppsteinPowerLawGenerator(vertexFactory, edgeFactory,
76 // 500,1500,100000);
77 // generator.setSeed(5);
78 // Graph graph = (Graph) generator.generateGraph();
79 // //long stop = System.currentTimeMillis();
80 // //System.out.println((stop-start)/1000l);
81 //
82 // DoubleArrayList degreeList = DegreeDistributions.getOutdegreeValues(graph.getVertices());
83 // int maxDegree = (int) Descriptive.max(degreeList);
84 // Histogram degreeHistogram = GraphStatistics.createHistogram(degreeList,0,maxDegree,1);
85 // //for (int index=0;index<maxDegree;index++) {
86 // // System.out.println(degreeHistogram.binIndex(index) + " " + degreeHistogram.binHeight(index));
87 // //}
88 // //if it's power law, 0 is going to have the highest bin count
89 // Assert.assertTrue(degreeHistogram.binHeight(0) + degreeHistogram.binHeight(1) > degreeHistogram.binHeight(2) + degreeHistogram.binHeight(3));
90 //
91 // generator = new EppsteinPowerLawGenerator(500,1500,0);
92 // graph = (Graph) generator.generateGraph();
93 // degreeList = DegreeDistributions.getOutdegreeValues(graph.getVertices());
94 // maxDegree = (int) Descriptive.max(degreeList);
95 // degreeHistogram = GraphStatistics.createHistogram(degreeList,0,maxDegree,1);
96 // //for (int index=0;index<maxDegree;index++) {
97 // // System.out.println(degreeHistogram.binIndex(index) + " " + degreeHistogram.binHeight(index));
98 // //}
99 // //if it's not power law, 0 is not going to have the highest bin count rather it will start to go up
100 // Assert.assertTrue(degreeHistogram.binHeight(0) < degreeHistogram.binHeight(1));
101 //
102 //
103 //
104 // }
105
106 }