-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraphTest.java
81 lines (74 loc) · 2.67 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
// --== CS400 File Header Information ==--
// Name: Fangjun Zhou
// Email: [email protected]
// Team: CG blue
// TA: Xi
// Lecturer: Gary Dahl
// Notes to Grader: <optional extra notes>
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> graph;
/**
* Instantiate graph from last week's shortest path activity.
*/
@BeforeEach
public void createGraph() {
graph = new CS400Graph<>();
// insert vertices A-E
graph.insertVertex("A");
graph.insertVertex("B");
graph.insertVertex("C");
graph.insertVertex("D");
graph.insertVertex("E");
// insert edges from Week 09. Dijkstra's Activity
graph.insertEdge("A","B",2);
graph.insertEdge("A","D",4);
graph.insertEdge("A","E",1);
graph.insertEdge("B","C",5);
graph.insertEdge("C","A",3);
graph.insertEdge("D","B",3);
graph.insertEdge("D","C",7);
graph.insertEdge("D","E",1);
graph.insertEdge("E","C",8);
}
/**
* Checks the distance/total weight cost from the vertex labelled C to E
* (should be 4), and from the vertex labelled A to C (should be 7).
*/
@Test
public void providedTestToCheckPathCosts() {
assertTrue(graph.getPathCost("C", "E") == 4);
//System.out.println(graph.getPathCost("C", "E"));
assertTrue(graph.getPathCost("A", "C") == 7);
//System.out.println(graph.getPathCost("A", "C"));
assertTrue(graph.getPathCost("D", "B") == 3);
assertTrue(graph.getPathCost("E", "D") == 15);
}
/**
* Checks the ordered sequence of data within vertices from the vertex
* labelled C to E, and from the vertex labelled A to C.
*/
@Test
public void providedTestToCheckPathContents() {
assertTrue(graph.shortestPath("C", "E").toString().equals(
"[C, A, E]"
));
//System.out.println(graph.shortestPath("C", "E").toString());
assertTrue(graph.shortestPath("A", "C").toString().equals(
"[A, B, C]"
));
//System.out.println(graph.shortestPath("A", "C").toString());
assertTrue(graph.shortestPath("D", "B").toString().equals(
"[D, B]"
));
assertTrue(graph.shortestPath("E", "D").toString().equals(
"[E, C, A, D]"
));
}
}