-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphTest.java
128 lines (113 loc) · 3.42 KB
/
GraphTest.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// --== CS400 File Header Information ==--
// Name: Jack Archibald
// Email: [email protected]
// Lecturer: Florian Heimerl
// Notes to Grader:
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests the implementation of CS400Graph for the individual component of
* Project Three: the implementation of Dijsktra's Shortest Path algorithm.
*/
public class GraphTest {
private CS400Graph<String,Integer> graph;
/**
* Instantiate graph from last week's shortest path activity.
*/
@BeforeEach
public void createGraph() {
graph = new CS400Graph<>();
// insert vertices A-F
graph.insertVertex("A");
graph.insertVertex("B");
graph.insertVertex("C");
graph.insertVertex("D");
graph.insertVertex("E");
graph.insertVertex("F");
// insert edges from Week 11. Shortest Path Activity
graph.insertEdge("A","B",6);
graph.insertEdge("A","C",2);
graph.insertEdge("A","D",5);
graph.insertEdge("B","E",1);
graph.insertEdge("B","C",2);
graph.insertEdge("C","B",3);
graph.insertEdge("C","F",1);
graph.insertEdge("D","E",3);
graph.insertEdge("E","A",4);
graph.insertEdge("F","A",1);
graph.insertEdge("F","D",1);
}
/**
* Checks the distance/total weight cost from the vertex A to F.
*/
@Test
public void testPathCostAtoF() {
assertTrue(graph.getPathCost("A", "F") == 3);
}
/**
* Checks the distance/total weight cost from the vertex A to D.
*/
@Test
public void testPathCostAtoD() {
assertTrue(graph.getPathCost("A", "D") == 4);
}
/**
* Checks the ordered sequence of data within vertices from the vertex
* A to D.
*/
@Test
public void testPathAtoD() {
assertTrue(graph.shortestPath("A", "D").toString().equals(
"[A, C, F, D]"
));
}
/**
* Checks the ordered sequence of data within vertices from the vertex
* A to F.
*/
@Test
public void testPathAtoF() {
assertTrue(graph.shortestPath("A", "F").toString().equals(
"[A, C, F]"
));
}
/**
* Checks the distance/total weight cost from the vertex A to E
*/
@Test
public void testPathCostAtoE() {
assertTrue(graph.getPathCost("A", "E") == 6);
}
/**
* Checks the ordered sequence of data within vertices from the vertex
* A to E
*/
@Test
public void testPathAtoE() {
assertTrue(graph.shortestPath("A", "E").toString().equals(
"[A, C, B, E]"
));
}
/**
* Checks the distance/total weight cost from the vertex B to F
*/
@Test
public void testPathCostBtoF() {
assertTrue(graph.getPathCost("B","F") == 3);
}
/**
* Checks the ordered sequence of data within vertices from the vertex
* B to F
*/
@Test
public void testPathBtoF() {
assertTrue(graph.shortestPath("B", "F").toString().equals(
"[B, C, F]"));
}
// Checks the distance/total weight cost from the vertex F to C
@Test
public void testPathDNE() {
assertTrue(graph.getPathCost("F","C") == 3);
}
}