-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackendDeveloperTests.java
More file actions
221 lines (186 loc) · 7.76 KB
/
Copy pathBackendDeveloperTests.java
File metadata and controls
221 lines (186 loc) · 7.76 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// === CS400 File Header Information ===
// Name: Diya Sriram
// Email: dsriram3@wisc.edu
// Lecturer: Gary Dahl
// Notes to Grader: none
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class BackendDeveloperTests {
/**
* Tests that loadGraphData() loads data in properly and throws an exception
* when needed.
*/
@Test
public void test1Rolecode() throws IOException {
GraphADT<String, Double> graph = new GraphPlaceholder();
Backend backend = new Backend(graph);
// test for exception
backend.loadGraphData("./campus.dot");
Assertions.assertThrows(IOException.class, () -> backend.loadGraphData("wrong name"),
"Expected Exception not thrown");
// checks that everything is loaded properly
Assertions.assertTrue(graph.containsEdge("Union South", "Computer Sciences and Statistics"));
Assertions.assertEquals(176.0, graph.getEdge("Union South", "Computer Sciences and Statistics"));
}
/**
* Tests that getListOfAllLocations() returns a list of all locations(nodes) on
* the backend's graph
*/
@Test
public void test2Rolecode() throws IOException{
GraphADT<String, Double> graph = new GraphPlaceholder();
Backend backend = new Backend(graph);
// should be empty
ArrayList<String> expected = new ArrayList<String>();
Assertions.assertEquals(expected, backend.getListOfAllLocations());
backend.loadGraphData("./campus.dot");
// check for random locations
Assertions.assertTrue(backend.getListOfAllLocations().contains("Davis Residence Hall"),
"Missing Valid Location");
Assertions.assertTrue(!backend.getListOfAllLocations().contains("This does not exist"),
"Includes Invalid Location");
}
/**
* Tests that findShortestPath() returns the sequence of locations along the
* shortest path from startLocation to endLocation and an empty list if no such
* path exists. Tests that getTravelTimesOnPath() returns the walking times in
* seconds between each two nodes on the shortest path from startLocation to
* endLocation and an empty list of no such path exists.
*/
@Test
public void test3Rolecode() {
GraphADT<String, Double> graph = new GraphPlaceholder();
Backend backend = new Backend(graph);
ArrayList<String> expected = new ArrayList<String>();
expected.add("Union South");
expected.add("Computer Sciences and Statistics");
expected.add("Atmospheric, Oceanic and Space Sciences");
String start = "Union South";
String end = "Atmospheric, Oceanic and Space Sciences";
// checks path
Assertions.assertEquals(expected, backend.findShortestPath(start, end));
}
/**
* Tests that findShortestPathVia() returns the sequence of locations along the
* shortest path from startLocation to endLocation and an empty list if no such
* path exists. Tests that getTravelTimesOnPathVia() returns the walking times
* in seconds between each two nodes on the shortest path from startLocation to
* endLocation and an empty list of no such path exists.
*/
@Test
public void test4Rolecode() {
GraphADT<String, Double> graph = new GraphPlaceholder();
Backend backend = new Backend(graph);
String start = "Union South";
String mid = "Computer Sciences and Statistics";
String end = "Atmospheric, Oceanic and Space Sciences";
// correct outcomes
ArrayList<Double> expectedTimes = new ArrayList<Double>();
ArrayList<String> expectedPath = new ArrayList<String>();
expectedTimes.add(176.0);
expectedTimes.add(127.2);
expectedPath.add("Union South");
expectedPath.add("Computer Sciences and Statistics");
expectedPath.add("Atmospheric, Oceanic and Space Sciences");
// checks both Via paths
Assertions.assertEquals(expectedPath, backend.findShortestPathVia(start, mid, end));
Assertions.assertEquals(expectedTimes, backend.getTravelTimesOnPathVia(start, mid, end));
}
// All placeholder tests that were submitted for the midweek
/**
* Tests that loadGraphData() loads data in properly and throws an exception
* when needed.
*/
@Test
public void test1Placeholder() {
BackendInterface backend = new BackendPlaceholder(new GraphPlaceholder());
// correctly loads in data
assertDoesNotThrow(() -> backend.loadGraphData("campus.dot"));
// incorrectly loads in data and throws an exception
assertThrows(IOException.class, () -> backend.loadGraphData("campu.dot"));
}
/**
* Tests that getListOfAllLocations() returns a list of all locations(nodes) on
* the backend's graph
*/
@Test
public void test2Placeholder() {
BackendInterface backend = new BackendPlaceholder(new GraphPlaceholder());
// list of all locations
List<String> actual = backend.getListOfAllLocations();
// make sure all locations are there
assertTrue(!actual.isEmpty());
assertTrue(actual.contains("Union South"));
assertTrue(actual.contains("Computer Sciences and Statistics"));
assertTrue(actual.contains("Atmospheric, Oceanic and Space Sciences"));
}
/**
* Tests that findShortestPath() returns the sequence of locations along the
* shortest path from startLocation to endLocation and an empty list if no such
* path exists. Tests that getTravelTimesOnPath() returns the walking times in
* seconds between each two nodes on the shortest path from startLocation to
* endLocation and an empty list of no such path exists.
*/
@Test
public void test3Placeholder() {
BackendInterface backend = new BackendPlaceholder(new GraphPlaceholder());
// get lists
String start = "Union South";
String end = "Atmospheric, Oceanic and Space Sciences";
List<String> path = backend.findShortestPath(start, end);
List<Double> times = backend.getTravelTimesOnPath(start, end);
// check path
assertTrue(!path.isEmpty());
assertEquals(3, path.size());
assertEquals("Union South", path.get(0));
assertEquals("Computer Sciences and Statistics", path.get(1));
assertEquals("Atmospheric, Oceanic and Space Sciences", path.get(2));
// check times
assertTrue(!times.isEmpty());
assertEquals(2, times.size());
assertEquals(176.0, times.get(0));
assertEquals(80.0, times.get(1));
// empty list if no path exists
List<String> emptyPath = backend.findShortestPath("a", end);
List<Double> emptyTimes = backend.getTravelTimesOnPath("a", end);
assertTrue(emptyPath.isEmpty());
assertTrue(emptyTimes.isEmpty());
}
/**
* Tests that findShortestPathVia() returns the sequence of locations along the
* shortest path from startLocation to endLocation and an empty list if no such
* path exists. Tests that getTravelTimesOnPathVia() returns the walking times
* in seconds between each two nodes on the shortest path from startLocation to
* endLocation and an empty list of no such path exists.
*/
@Test
public void test4Placeholder() {
BackendInterface backend = new BackendPlaceholder(new GraphPlaceholder());
// get lists
String start = "Memorial Union";
String via = "Science Hall";
String end = "Radio Hall";
List<String> path = backend.findShortestPathVia(start, via, end);
List<Double> times = backend.getTravelTimesOnPathVia(start, via, end);
// check path
assertTrue(!path.isEmpty());
assertEquals(3, path.size());
assertEquals("Memorial Union", path.get(0));
assertEquals("Science Hall", path.get(1));
assertEquals("Radio Hall", path.get(2));
// check times
assertTrue(!times.isEmpty());
assertEquals(2, times.size());
assertEquals(146.0, times.get(0));
assertEquals(30.0, times.get(1));
// empty list if no path exists
List<String> emptyPath = backend.findShortestPath("a", end);
List<Double> emptyTimes = backend.getTravelTimesOnPath("a", end);
assertTrue(emptyPath.isEmpty());
assertTrue(emptyTimes.isEmpty());
}
}