-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWGraph_AlgoTest.java
106 lines (90 loc) · 2.8 KB
/
WGraph_AlgoTest.java
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package tests;
import org.junit.jupiter.api.Test;
import ex1.src.WGraph_Algo;
import ex1.src.node_info;
import ex1.src.weighted_graph;
import ex1.src.weighted_graph_algorithms;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class WGraph_AlgoTest {
@Test
void isConnected() {
weighted_graph g0 = WGraph_DSTest.graph_creator(0,0,1);
weighted_graph_algorithms ag0 = new WGraph_Algo();
ag0.init(g0);
assertTrue(ag0.isConnected());
g0 = WGraph_DSTest.graph_creator(1,0,1);
ag0 = new WGraph_Algo();
ag0.init(g0);
assertTrue(ag0.isConnected());
g0 = WGraph_DSTest.graph_creator(2,0,1);
ag0 = new WGraph_Algo();
ag0.init(g0);
assertFalse(ag0.isConnected());
g0 = WGraph_DSTest.graph_creator(2,1,1);
ag0 = new WGraph_Algo();
ag0.init(g0);
assertTrue(ag0.isConnected());
g0 = WGraph_DSTest.graph_creator(10,30,1);
ag0.init(g0);
boolean b = ag0.isConnected();
assertTrue(b);
}
@Test
void shortestPathDist() {
weighted_graph g0 = small_graph();
weighted_graph_algorithms ag0 = new WGraph_Algo();
ag0.init(g0);
assertTrue(ag0.isConnected());
double d = ag0.shortestPathDist(0,10);
assertEquals(d, 5.1);
}
@Test
void shortestPath() {
weighted_graph g0 = small_graph();
weighted_graph_algorithms ag0 = new WGraph_Algo();
ag0.init(g0);
List<node_info> sp = ag0.shortestPath(0,10);
//double[] checkTag = {0.0, 1.0, 2.0, 3.1, 5.1};
int[] checkKey = {0, 1, 5, 7, 10};
int i = 0;
for(node_info n: sp) {
//assertEquals(n.getTag(), checkTag[i]);
assertEquals(n.getKey(), checkKey[i]);
i++;
}
}
@Test
void save_load() {
weighted_graph g0 = WGraph_DSTest.graph_creator(10,30,1);
weighted_graph_algorithms ag0 = new WGraph_Algo();
ag0.init(g0);
String str = "g0.obj";
ag0.save(str);
weighted_graph g1 = WGraph_DSTest.graph_creator(10,30,1);
ag0.load(str);
assertEquals(g0,g1);
g0.removeNode(0);
assertNotEquals(g0,g1);
}
private weighted_graph small_graph() {
weighted_graph g0 = WGraph_DSTest.graph_creator(11,0,1);
g0.connect(0,1,1);
g0.connect(0,2,2);
g0.connect(0,3,3);
g0.connect(1,4,17);
g0.connect(1,5,1);
g0.connect(2,4,1);
g0.connect(3, 5,10);
g0.connect(3,6,100);
g0.connect(5,7,1.1);
g0.connect(6,7,10);
g0.connect(7,10,2);
g0.connect(6,8,30);
g0.connect(8,10,10);
g0.connect(4,10,30);
g0.connect(3,9,10);
g0.connect(8,10,10);
return g0;
}
}