-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKBNumberTest.java
More file actions
365 lines (311 loc) · 9.46 KB
/
KBNumberTest.java
File metadata and controls
365 lines (311 loc) · 9.46 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
import static org.junit.Assert.*;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
public class KBNumberTest {
/*
* Instantiated only once for all tests. Make sure multiple calls to each
* method work as expected, and leftover data/variables from the last call
* is handled properly.
*/
KBNumber bacon = new KBNumber("movies_tiny.txt");
KBNumber bacon2 = new KBNumber("moviesTest.txt");
KBNumber baconNoCollab = new KBNumber("moviesTestNone.txt");
KBNumber baconOneCollab = new KBNumber("moviesTestOne.txt");
KBNumber baconSameCollab = new KBNumber("same.txt");
KBNumber baconDisCon = new KBNumber("disconnected.txt");
KBNumber baconDisCon2 = new KBNumber("discon2.txt");
KBNumber noBacon = new KBNumber("nobacon.txt");
KBNumber longB = new KBNumber("long.txt");
KBNumber cycle = new KBNumber("cycle.txt");
KBNumber multiple = new KBNumber("multiple.txt");
@Before
public void setUp() throws Exception {
//nothing here.
}
//Zero and One collaboration between any two actors
@Test
public void testCollaborationNoneOne(){
assertEquals(baconNoCollab.mostCollaboration(), 0);
assertEquals(baconOneCollab.mostCollaboration(), 1);
}
//Same amount of collaboration between every actor
@Test
public void testCollaborationSame(){
assertEquals(baconOneCollab.mostCollaboration(), 1);
assertEquals(baconSameCollab.mostCollaboration(), 4);
}
//Only collaboration greater than 1 is between two actors
@Test
public void testCollaborationLarge(){
assertEquals(bacon2.mostCollaboration(), 7);
}
@Test
public void testCollaboration() {
assertEquals(bacon.mostCollaboration(), 3);
}
//Costars with no actors (empty list)
@Test
public void testCostarsNone(){
List<String> result = baconNoCollab.findCostars("A");
assertEquals(result.size(), 0);
assertFalse(result.contains("A"));
assertFalse(result.contains("Bacon, Kevin"));
List<String> result2 = baconNoCollab.findCostars("Bacon, Kevin");
assertEquals(result2.size(), 0);
assertFalse(result.contains("A"));
assertFalse(result.contains("Bacon, Kevin"));
assertFalse(result.contains("D"));
}
//Costars with only one other actor
@Test
public void testCostarsOne(){
List<String> result = baconOneCollab.findCostars("Z");
assertEquals(result.size(), 1);
assertTrue(result.contains("Bacon, Kevin"));
assertFalse(result.contains("A"));
assertFalse(result.contains("B"));
List<String> result2 = baconOneCollab.findCostars("Bacon, Kevin");
assertEquals(result2.size(), 1);
assertFalse(result2.contains("Bacon, Kevin"));
assertTrue(result2.contains("Z"));
}
//Costars every actor
@Test
public void testCostarsEvery(){
List<String> result = baconSameCollab.findCostars("A");
assertEquals(result.size(), 5);
assertTrue(result.contains("Bacon, Kevin"));
assertTrue(result.contains("D"));
assertTrue(result.contains("E"));
assertTrue(result.contains("F"));
assertTrue(result.contains("G"));
assertFalse(result.contains("A"));
}
//Costars with no actors, but other actors are costars (disconnected)
@Test
public void testCostarsDisconnected(){
List<String> result = baconDisCon.findCostars("Z");
assertEquals(result.size(), 0);
assertFalse(result.contains("Z"));
List<String> result2 = baconDisCon.findCostars("A");
assertEquals(result2.size(), 5);
assertFalse(result2.contains("Z"));
}
//Exception tests--actor is null and actor is not in list
@Test
public void testCostarsEx(){
try {
List<String> result = baconDisCon.findCostars("Nick Cage");
assertEquals(result.size(), 0);
fail();
} catch(IllegalArgumentException e){
assertTrue(true);
}
try {
List<String> result2 = baconDisCon.findCostars(null);
assertEquals(result2.size(), 0);
fail();
} catch(IllegalArgumentException e){
assertTrue(true);
}
}
@Test
public void testCostars(){
List<String> result = bacon.findCostars("C");
assertEquals(result.size(), 3);
assertTrue(result.contains("A"));
assertTrue(result.contains("B"));
assertTrue(result.contains("D"));
}
//Exception Tests--null and if actor not in list
@Test
public void testNumEx(){
try {
int baconnum0 = baconDisCon.findBaconNumber("Nick Cage");
assertEquals(baconnum0, -1);
fail();
} catch(IllegalArgumentException e){
assertTrue(true);
}
int baconnum = baconDisCon.findBaconNumber("Z");
assertEquals(baconnum, -1);
try {
int baconnum2 = baconDisCon.findBaconNumber(null);
assertEquals(baconnum2, 0);
fail();
} catch(IllegalArgumentException e){
assertTrue(true);
}
}
//Disconnected--Bacon Number: -1
@Test
public void testFindBaconNumDis(){
int baconnum = baconDisCon.findBaconNumber("Z");
assertEquals(baconnum, -1);
int baconnum2 = baconDisCon2.findBaconNumber("Z");
assertEquals(baconnum2, -1);
}
//Bacon himself--Bacon # : 0
@Test
public void testFindBaconNum0(){
int baconN = bacon.findBaconNumber("Bacon, Kevin");
assertEquals(baconN, 0);
int baconN2 = baconOneCollab.findBaconNumber("Bacon, Kevin");
assertEquals(baconN2, 0);
}
//Bacon not in movie list: -1
@Test
public void testFindBaconNumNeg1(){
int bN = noBacon.findBaconNumber("Z");
assertEquals(bN, -1);
bN = noBacon.findBaconNumber("D");
assertEquals(bN, -1);
bN = noBacon.findBaconNumber("E");
assertEquals(bN, -1);
bN = noBacon.findBaconNumber("G");
assertEquals(bN, -1);
}
//Bacon # where Bacon is at the end of a long path, but all other paths are short
//Plus, Bacon shows up at the end of a longer path
@Test
public void testFindBaconNumlong(){
int bN = longB.findBaconNumber("F");
assertEquals(bN, 5);
}
//All Bacon numbers the same
@Test
public void testFindBaconNumberSame(){
int baconnum = baconSameCollab.findBaconNumber("A");
assertEquals(baconnum, 1);
baconnum = baconSameCollab.findBaconNumber("D");
assertEquals(baconnum, 1);
baconnum = baconSameCollab.findBaconNumber("E");
assertEquals(baconnum, 1);
}
@Test
public void testFindBaconNumber(){
int baconnum = bacon.findBaconNumber("N");
assertEquals(baconnum, 6);
}
//When the actor parameter is Bacon
@Test
public void testFindBaconToBaconPath () {
List<String> path = bacon.findBaconPath("Bacon, Kevin");
assertEquals(path.size(), 1);
Iterator<String> it = path.iterator();
String s;
s=it.next();
assertEquals(s, "Bacon, Kevin");
}
//When there isn't a bacon path (disconnected)
@Test
public void testFindBaconDis () {
try {
List<String> path = baconDisCon.findBaconPath("Nick Cage");
assertEquals(path.size(), 0);
fail();
} catch(IllegalArgumentException e){
assertTrue(true);
}
try {
List<String> path2 = baconDisCon2.findBaconPath("Z");
assertEquals(path2, null);
} catch(IllegalArgumentException e){
assertTrue(true);
}
}
//When there isn't a bacon path b/c bacon is not in the file
@Test
public void testFindBaconNoBacon () {
try {
List<String> path = noBacon.findBaconPath("Bacon, Kevin");
assertEquals(path.size(), 0);
fail();
} catch(IllegalArgumentException e){
assertTrue(true);
}
}
//When there's a possible cycle "within" the bacon path
@Test
public void testFindBaconCycle () {
List<String> path = cycle.findBaconPath("D");
assertEquals(path.size(), 7);
Iterator<String> it = path.iterator();
String s;
s=it.next();
assertEquals(s, "D");
s=it.next();
assertTrue(s.equals("Movie 6") && !s.equals("Movie 1"));
s=it.next();
assertEquals(s, "G");
s=it.next();
assertTrue(s.equals("Movie 7"));
s=it.next();
assertEquals(s, "A");
s=it.next();
assertEquals(s, "Movie 0");
s=it.next();
assertEquals(s, "Bacon, Kevin");
}
//Kevin Bacon in multiple movies
@Test
public void testFindBaconMult () {
List<String> path = multiple.findBaconPath("E");
assertEquals(path.size(), 7);
Iterator<String> it = path.iterator();
String s;
s=it.next();
assertEquals(s, "E");
s=it.next();
assertTrue(s.equals("Movie 3") || s.equals("Movie 2") || s.equals("Movie 1"));
s=it.next();
assertEquals(s, "D");
s=it.next();
assertTrue(s.equals("Movie 9"));
s=it.next();
assertEquals(s, "I");
s=it.next();
assertTrue(s.equals("Movie 14"));
s=it.next();
assertEquals(s, "Bacon, Kevin");
}
//When the name of the actor is not in the graph (exception tests)
@Test
public void testFindBaconNickCage () {
try {
List<String> path = bacon.findBaconPath("Cage, Nicolas");
assertEquals(path.size(), 0);
fail();
} catch(IllegalArgumentException e){
assertTrue(true);
}
try {
List<String> path = bacon.findBaconPath(null);
assertEquals(path.size(), 0);
fail();
} catch(IllegalArgumentException e){
assertTrue(true);
}
}
@Test
public void testFindBaconPath () {
List<String> path = bacon.findBaconPath("D");
assertEquals(path.size(), 5);
Iterator<String> it = path.iterator();
String s;
s=it.next();
assertEquals(s, "D");
s=it.next();
assertTrue(s.equals("Movie 2") || s.equals("Movie 7"));
s=it.next();
assertEquals(s, "A");
s=it.next();
assertEquals(s, "Movie 0");
s=it.next();
assertEquals(s, "Bacon, Kevin");
}
}