1
2
3
4
5
6
7
8
9
10 package edu.uci.ics.jung.algorithms.scoring;
11
12 import java.util.HashSet;
13 import java.util.Set;
14
15 import junit.framework.Assert;
16 import junit.framework.Test;
17 import junit.framework.TestCase;
18 import junit.framework.TestSuite;
19
20 import com.google.common.base.Supplier;
21
22 import edu.uci.ics.jung.algorithms.scoring.util.ScoringUtils;
23 import edu.uci.ics.jung.graph.DirectedGraph;
24 import edu.uci.ics.jung.graph.DirectedSparseMultigraph;
25 import edu.uci.ics.jung.graph.Graph;
26
27
28
29
30
31 public class TestPageRankWithPriors extends TestCase {
32
33
34 private DirectedGraph<Integer,Integer> graph;
35 private Supplier<Integer> edgeFactory;
36
37 public static Test suite() {
38 return new TestSuite(TestPageRankWithPriors.class);
39 }
40
41 @Override
42 protected void setUp() {
43
44 edgeFactory = new Supplier<Integer>() {
45 int i=0;
46 public Integer get() {
47 return i++;
48 }};
49 }
50
51 private void addEdge(Graph<Integer, Integer> G, Integer v1, Integer v2)
52 {
53 Integer edge = edgeFactory.get();
54 graph.addEdge(edge, v1, v2);
55
56 }
57
58 public void testGraphScoring() {
59 graph = new DirectedSparseMultigraph<Integer,Integer>();
60
61 double[] expected_score = new double[]{0.1157, 0.2463, 0.4724, 0.1653};
62
63 for(int i=0; i<4; i++) {
64 graph.addVertex(i);
65 }
66 addEdge(graph,0,1);
67 addEdge(graph,1,2);
68 addEdge(graph,2,3);
69 addEdge(graph,3,0);
70 addEdge(graph,2,1);
71
72 Set<Integer> priors = new HashSet<Integer>();
73 priors.add(2);
74
75 PageRankWithPriors<Integer, Integer> pr =
76 new PageRankWithPriors<Integer, Integer>(graph, ScoringUtils.getUniformRootPrior(priors), 0.3);
77 pr.evaluate();
78
79 double score_sum = 0;
80 for (int i = 0; i < graph.getVertexCount(); i++)
81 {
82 double score = pr.getVertexScore(i);
83 Assert.assertEquals(expected_score[i], score, pr.getTolerance());
84 score_sum += score;
85 }
86 Assert.assertEquals(1.0, score_sum, pr.getTolerance() * graph.getVertexCount());
87 }
88
89 public void testHypergraphScoring() {
90 }
91 }