forked from jieli4970/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSTTest.java
More file actions
59 lines (41 loc) · 1.18 KB
/
MSTTest.java
File metadata and controls
59 lines (41 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import org.junit.Assert;
import java.util.HashSet;
import java.util.Set;
public class MSTTest {
private EdgeWeighGraph graph;
private Set<Edge> expect;
@org.junit.Before
public void data() {
Edge edge1 = new Edge(0, 1, 1.0);
Edge edge2 = new Edge(1, 2, 2.0);
Edge edge3 = new Edge(2, 3, 3.0);
Edge edge4 = new Edge(3, 0, 4.0);
Edge edge5 = new Edge(0, 2, 5.0);
graph = new EdgeWeighGraph(4);
graph.addEdge(edge1);
graph.addEdge(edge2);
graph.addEdge(edge3);
graph.addEdge(edge4);
graph.addEdge(edge5);
expect = new HashSet<>();
expect.add(edge1);
expect.add(edge2);
expect.add(edge3);
}
@org.junit.Test
public void testPrimMST() {
test(new PrimMST(graph));
}
@org.junit.Test
public void testKruskalMST() {
test(new KruskalMST(graph));
}
private void test(MST mst) {
Set<Edge> result = mst.getResult();
Assert.assertEquals(result.size(), expect.size());
for (Edge edge : result) {
Assert.assertTrue(expect.contains(edge));
expect.remove(edge);
}
}
}