Repository navigation
Expand file tree
/
Copy pathGraphProcessorTest.java
More file actions
271 lines (244 loc) · 8.96 KB
/
Copy pathGraphProcessorTest.java
File metadata and controls
271 lines (244 loc) · 8.96 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
//
//Title: X-Team Exercise #4
//Files: Graph.java, GraphProcessor.java, WordProcessor.java,
// GraphProcessorTest.java
//Course: CS400, Spring 2018
//
//Authors: Dylan Breon, Steven Berry, Elliot Braem, Adam Bin Mohammed Azmil,
// Jesse Brodacz
//Emails: dbreon@wisc.edu, shberry@wisc.edu, ebraem@wisc.edu, Binmohammeda@wisc.edu, brodacz@wisc.edu
//Lecturers name: Deb Deppeler
//
//Due Date: Monday, April 16th, 10:00 pm
//
//Known Bugs: NONE
//
/**
*
* JUnit tester class that checks the full functionality of our @see graphProcessor and
* @see WordProcessor classes.
*
* NOTE: MUST enter correct file path location in order to access the word_list.txt file.
*
*/
public class GraphProcessorTest {
private GraphProcessor processor;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
this.processor = new GraphProcessor();
//MUST put correct location of words_list.txt
processor.populateGraph("/Users/stevenberry/Downloads/word_list.txt");
processor.shortestPathPrecomputation();
}
@After
public void tearDown() throws Exception {
this.processor = null;
}
@Test
/**
* words are one character different by adding an "s" to the end of "test"
* should return true
* @throws Exception
*/
public void testIsAdjacentIfWordsAreOneLetterOffByAdding() throws Exception {
String[] strings = {"test", "tests"};
assertEquals("words are one character off by adding", true,
WordProcessor.isAdjacent(strings[0], strings[1]));
}
@Test
/**
* words are one character different by subtracting an "s" from the end of "tests"
* should return true
* @throws Exception
*/
public void testIsAdjacentIfWordsAreOneLetterOffBySubtracting() throws Exception {
String[] strings = {"tests", "test"};
assertEquals("words are one character off by subtracting", true,
WordProcessor.isAdjacent(strings[0], strings[1]));
}
@Test
/**
* words are one character different by changing the "e" to an "o" to make "tost"
* should return true
* @throws Exception
*/
public void testIsAdjacentIfWordsAreOneLetterOffByChanging() throws Exception {
String[] strings = {"test", "tost"};
assertEquals("words are one character off by changing", true,
WordProcessor.isAdjacent(strings[0], strings[1]));
}
@Test
/**
* words are two characters different by adding "in" to the end of "test"
* should return false
* @throws Exception
*/
public void testIsAdjacentIfWordsAreMoreThanOneCharacterOffByAdding() throws Exception {
String[] strings = {"test", "testin"};
assertEquals("words are more than one character off by adding", false,
WordProcessor.isAdjacent(strings[0], strings[1]));
}
@Test
/**
* words are two characters different by subtracting "in" from the end of "testin"
* should return false
* @throws Exception
*/
public void testIsAdjacentIfWordsAreMoreThanOneCharacterOffBySubtracting() throws Exception {
String[] strings = {"testin", "test"};
assertEquals("words are more than one character off by adding", false,
WordProcessor.isAdjacent(strings[0], strings[1]));
}
@Test
/**
* words are two characters different by changing the "ll" in "tell" to "st"
* should return false
* @throws Exception
*/
public void testIsAdjacentIfWordsAreMoreThanOneCharacterOffByChanging() throws Exception {
String[] strings = {"tell", "test"};
assertEquals("words are more than one character off by adding", false,
WordProcessor.isAdjacent(strings[0], strings[1]));
}
@Test
/**
* words are two characters different by changing the "e" in "test" to "a" and adding a "y" to the end
* should return false
* @throws Exception
*/
public void testIsAdjacentIfWordsAreMoreThanOneCharacterOffByAddingAndChanging()
throws Exception {
String[] strings = {"test", "tasty"};
assertEquals("words are more than one character off by adding and changing", false,
WordProcessor.isAdjacent(strings[0], strings[1]));
}
@Test
/**
* words are two characters different by changing the "e" in "test" to "a" and subtracting the "s"
* should return false
* @throws Exception
*/
public void testIsAdjacentIfWordsAreMoreThanOneCharacterOffBySubtractingAndChanging()
throws Exception {
String[] strings = {"test", "tat"};
assertEquals("words are more than one character off by subtracting and changing", false,
WordProcessor.isAdjacent(strings[0], strings[1]));
}
@Test
/**
* words are two characters different by changing the "ll" in "tell" to "st"
* should return false
* @throws Exception
*/
public void testIsAdjacentIfWordsAreMoreThanOneCharacterOffByChangingTwice() throws Exception {
String[] strings = {"test", "toot"};
assertEquals("words are more than one character off by changing twice", false,
WordProcessor.isAdjacent(strings[0], strings[1]));
}
@Test
/**
* words are duplicates
* should return false
* @throws Exception
*/
public void testIsAdjacentIfWordsAreDuplicates() throws Exception {
String[] strings = {"test", "test"};
assertEquals("words are duplicates", false,
WordProcessor.isAdjacent(strings[0], strings[1]));
}
/**
* tests that the shortest path method finds and returns
* the correct path and the length the path takes from one
* vertex to another.
* @throws Exception
*/
@Test
public void testGetShortestPath() throws Exception {
List<String> path = processor.getShortestPath("Carrier", "Weather");
boolean passed = true;
for (int i = 0; i < path.size(); i++) {
if (i < path.size() - 1) {
if (!WordProcessor.isAdjacent(path.get(i), path.get(i + 1))) {
passed = false;
}
}
}
assertTrue(passed);
}
/**
* tests that the shortest path between 2 of the same
* vertices will be empty
* @throws Exception
*/
@Test
public void testGetShortestPathSameArguments() throws Exception {
List<String> path = processor.getShortestPath("Carrier", "Carrier");
assertTrue(path.isEmpty());
}
/**
* This test checks the output of the method getShortestDistance(string,string) when the arguments are
* the same value.
* Expected behavior is method will return an int value -1.
* Fails when any other value is returned.
* @throws Exception
*/
@Test
public void testGetShortestDistanceIfSameWords() throws Exception{
int actual=-1;
int distance =processor.getShortestDistance("rapine", "rapine");
assertEquals(actual,distance);
}
/**
* This test checks whether the shortest distance returned is true between two words.
* This test checks this via the arguments "charge", and "gimlets"
* Computed distance is 78.
* If any other distance is returned test will fail.
* @throws Exception
*/
@Test
public void testGetShortestDistanceIfWordsExists() throws Exception {
int actual = 78;
int distance = processor.getShortestDistance("charge", "gimlets");
assertEquals(actual, distance);
}
/**
* This test checks the distance returned when there is no path between the words.
* Tests this via the arguments "supreme" and "airfoil"
* When this happens the method should return an int of value -1.
* Will fail when any other value is returned.
* @throws Exception
*/
@Test
public void testGetShortestDistanceIfNoPathExists() throws Exception {
int actual = -1;
int distance = processor.getShortestDistance("supreme", "airfoil");
assertEquals(actual, distance);
}
/**
* tests that the shortest path will be empty if there is
* no path between 2 vertices.
* @throws Exception
*/
@Test
public void testGetShortestPathIfNoPathExists() throws Exception {
processor.shortestPathPrecomputation();
List<String> path = processor.getShortestPath("supreme", "airfoil");
assertTrue(path.isEmpty());
}
}