-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStagTester.java
More file actions
670 lines (550 loc) · 30.4 KB
/
StagTester.java
File metadata and controls
670 lines (550 loc) · 30.4 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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
import StagEngine.StagTokenizer;
import StagExceptions.StagException;
import java.io.*;
import java.net.Socket;
import java.util.ArrayList;
/**
* StagTester is based on the StagCheck class that was provided. I created this class to prevent any potential overwrite
* by the automated testing scripts.
*
* I used this class to check that my StagServer was performing as required.
*
* I compiled my code in IntelliJ, and the running of this class assumes the file structure used by IntelliJ.
*
* */
public class StagTester {
static String playerOne = "Alpha";
static String playerTwo = "Beta";
static String playerThree = "Gamma";
static String playerWithSpaces = "Eta and Epsilon";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_RESET = "\u001B[0m";
public static void main(String args[])
{
Process serverOne = startNewServer();
System.out.println("Built-in Commands Tests Summary");
System.out.println("_______________________________");
builtInCommandTests();
System.out.println("\nAll built in commands tests completed.\n");
killOldServer(serverOne);
Process serverTwo = startNewServer();
System.out.println("Dynamic Commands Tests Summary");
System.out.println("_______________________________");
dynamicCommandTests();
killOldServer(serverTwo);
System.out.println("\nAll dynamic commands tests completed.\n");
Process serverThree = startNewServer();
System.out.println("Multiplayer Tests Summary");
System.out.println("_________________________");
multiplayerTests();
killOldServer(serverThree);
System.out.println("\nAll multiplayer tests completed.\n");
System.out.println("Tokenizer Tests Summary");
System.out.println("_______________________");
tokenizerTests();
System.out.println(ANSI_GREEN + "\nTESTING COMPLETE\n" + ANSI_RESET);
}
public static String executeCommand(String command) {
try {
String response = "";
String incoming;
Socket socket = new Socket("127.0.0.1", 8888);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.write(command + "\n");
out.flush();
while((incoming = in.readLine()) != null) response = response + incoming + "\n";
in.close();
out.close();
socket.close();
return response;
} catch(IOException ioe) {
System.out.println(ioe);
return "";
}
}
private static Process startNewServer() {
String homeDirectory = System.getProperty("user.dir");
String libsPath = homeDirectory + File.separator + "libs";
String serverPath = homeDirectory + File.separator + "out" + File.separator + "production" + File.separator + "STAG";
String dotParserPath = libsPath + File.separator + "dot-parser.jar";
String jsonParserPath = libsPath + File.separator + "json-parser.jar";
String classPath = serverPath + ":" + dotParserPath + ":" + jsonParserPath + ":" + ".";
try {
String[] command = {"java", "-classpath", classPath, "StagServer", "data/entities.dot", "data/actions.json"};
Process process = Runtime.getRuntime().exec(command);
// Sleep for a bit to give the server some time to warm up
Thread.sleep(2000);
return process;
} catch(InterruptedException ie) {
return null;
} catch(IOException ioe) {
return null;
}
}
private static void killOldServer(Process server) {
try {
server.destroy();
server.waitFor();
} catch(InterruptedException ie) {
}
}
public static void tokenizerTests() {
String command = "player: The player \t said ;, \"show me my inventory.\"";
StagTokenizer tokenizer = new StagTokenizer(command);
ArrayList<String> tokens = new ArrayList<>();
try{
System.out.println(command);
tokenizer.splitIntoTokens(tokens);
}
catch (StagException se) {
se.toString();
}
if(tokens.size() == 12) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
if(tokens.get(tokens.size()-1).equals("\"")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
if(tokens.get(tokens.size()-2).equals(".")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
System.out.println("\nAll tokenizer tests completed.\n");
}
private static void builtInCommandTests() {
ArrayList<String> commands = new ArrayList<>();
String command;
String response;
// =============================================================================================================
// look command tests
// =============================================================================================================
commands.add(playerOne + ": look" );
commands.add(playerOne + ": look around" );
commands.add(playerOne + ": i want to look here" );
commands.add(playerOne + ": look " );
commands.add(playerOne + ": i want to stop and look around " );
commands.add(playerOne + ": look there" );
commands.add(playerOne + ": look " );
System.out.println("\nLook tests");
System.out.println("___________\n");
for (String s : commands){
response = executeCommand(s);
System.out.println(s);
if(response.contains("cabin")) {
System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
}
else {
System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
}
}
System.out.println("\nLook tests completed.\n");
// =============================================================================================================
// get, drop and inv command tests
// =============================================================================================================
System.out.println("\nGet, drop and inventory tests");
System.out.println("_____________________________\n");
// Get an artefact
command = playerOne + ": get axe";
response = executeCommand(command);
System.out.println(command);
if(response.contains("axe")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
// Check inventory
command = playerOne + ": inv";
response = executeCommand(command);
System.out.println(command);
if(response.contains("axe")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
// Check inventory variation
command = playerOne + ": inventory";
response = executeCommand(command);
System.out.println(command);
if(response.contains("axe")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
// Check inventory variation
command = playerOne + ": inventory ";
response = executeCommand(command);
System.out.println(command);
if(response.contains("axe")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
// Check inventory variation
command = playerOne + ": inv entory ";
response = executeCommand(command);
System.out.println(command);
if(response.contains("axe")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
// Check inventory variation
command = playerOne + ": show me my inventory";
response = executeCommand(command);
System.out.println(command);
if(response.contains("axe")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
// Drop the artefact
command = playerOne + ": drop axe";
response = executeCommand(command);
System.out.println(command);
if(response.contains("axe")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
// Dropping the same artefact should throw an error
command = playerOne + ": drop axe";
response = executeCommand(command);
System.out.println(command);
if(response.contains("Error")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
// Get artefact variation
command = playerOne + ": i would like to get the axe";
response = executeCommand(command);
System.out.println(command);
if(response.contains("axe")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
// Check that the artefact is in the inventory
command = playerOne + ": inventory";
response = executeCommand(command);
System.out.println(command);
if(response.contains("axe")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
// Simply stating an artefact without a trigger should throw an error
command = playerOne + ": axe";
response = executeCommand(command);
System.out.println(command);
if(response.contains("Error")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
// Check that the axe is in the inventory
command = playerOne + ": inventory";
response = executeCommand(command);
System.out.println(command);
if(response.contains("axe")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
System.out.println("\nGet, drop and inventory tests completed.\n");
// =============================================================================================================
// goto command tests
// =============================================================================================================
System.out.println("\nGoto tests");
System.out.println("__________\n");
// Basic goto command
command = playerOne + ": goto forest";
response = executeCommand(command);
System.out.println(command);
if(response.contains("key") && response.contains("forest") && response.contains("tree")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
// More formalised goto command
command = playerOne + ": I would like to goto the cabin";
response = executeCommand(command);
System.out.println(command);
if(response.contains("cabin") && response.contains("trapdoor")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
// goto command variation
command = playerOne + ": goto forest ; ?";
response = executeCommand(command);
System.out.println(command);
if(response.contains("key") && !response.contains("Error")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
System.out.println("\nGoto tests completed.\n");
// =============================================================================================================
// health command tests
// =============================================================================================================
System.out.println("\nHealth tests");
System.out.println("____________\n");
command = playerOne + ": I want to goto the cabin";
response = executeCommand(command);
System.out.println(command);
if(response.contains("cabin") && !response.contains("Error")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": get me that potion";
response = executeCommand(command);
System.out.println(command);
if(response.contains("potion") && !response.contains("Error")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": check that potion in inventory";
response = executeCommand(command);
System.out.println(command);
if(response.contains("potion") && !response.contains("Error")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": health (should be 3)";
response = executeCommand(command);
System.out.println(command);
if(response.contains("3") && !response.contains("Error")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": computer, i want to drink that potion";
response = executeCommand(command);
System.out.println(command);
if(response.contains("potion") && !response.contains("Error")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": show me my health after that potion (should be 4)";
response = executeCommand(command);
System.out.println(command);
if(response.contains("4") && !response.contains("Error")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": inventory should not contain a potion";
response = executeCommand(command);
System.out.println(command);
if(!response.contains("potion")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
}
private static void dynamicCommandTests() {
String command;
String response;
// Ensure we are starting fom the beginning
command = playerOne + ": look";
response = executeCommand(command);
System.out.println(command);
if(response.contains("cabin")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": get potion";
response = executeCommand(command);
System.out.println(command);
if(response.contains("potion")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": get axe";
response = executeCommand(command);
System.out.println(command);
if(response.contains("axe")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": get coin";
response = executeCommand(command);
System.out.println(command);
if(response.contains("coin")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": look";
response = executeCommand(command);
System.out.println(command);
if(!response.contains("axe") || !response.contains("potion") || !response.contains("coin")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": inventory";
response = executeCommand(command);
System.out.println(command);
if(response.contains("axe") && response.contains("potion") && response.contains("coin")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": goto forest";
response = executeCommand(command);
System.out.println(command);
if(response.contains("forest")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": get the key";
response = executeCommand(command);
System.out.println(command);
if(response.contains("key")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": goto the cabin";
response = executeCommand(command);
System.out.println(command);
if(response.contains("cabin")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": please unlock the trapdoor";
response = executeCommand(command);
System.out.println(command);
if(response.contains("trapdoor")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": look (should show a path to a cellar)";
response = executeCommand(command);
System.out.println(command);
if(response.contains("cellar")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": goto cellar";
response = executeCommand(command);
System.out.println(command);
if(response.contains("dusty")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": pay (just pay should produce an error)";
response = executeCommand(command);
System.out.println(command);
if(response.contains("Error")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": pay the elf";
response = executeCommand(command);
System.out.println(command);
if(response.contains("shovel")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": get the shovel";
response = executeCommand(command);
System.out.println(command);
if(response.contains("shovel")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": inv";
response = executeCommand(command);
System.out.println(command);
if(response.contains("shovel")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": goto cabin";
response = executeCommand(command);
System.out.println(command);
if(response.contains("cabin")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": goto forest";
response = executeCommand(command);
System.out.println(command);
if(response.contains("forest")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": i want to chop (should produce error)";
response = executeCommand(command);
System.out.println(command);
if(response.contains("Error")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": I want to chop the tree";
response = executeCommand(command);
System.out.println(command);
if(response.contains("axe")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": look (check for the log)";
response = executeCommand(command);
System.out.println(command);
if(response.contains("log")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": get that log";
response = executeCommand(command);
System.out.println(command);
if(response.contains("log") && response.contains("picked")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": look (check for the log again, should not be there)";
response = executeCommand(command);
System.out.println(command);
if(!response.contains("log")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": goto riverbank";
response = executeCommand(command);
System.out.println(command);
if(response.contains("riverbank")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": get horn";
response = executeCommand(command);
System.out.println(command);
if(!response.contains("log")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": blow my horn loudly";
response = executeCommand(command);
System.out.println(command);
if(response.contains("magic")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": drop horn";
response = executeCommand(command);
System.out.println(command);
if(response.contains("horn")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": blow my horn loudly again";
response = executeCommand(command);
System.out.println(command);
if(response.contains("magic")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": look for the burly woodcutter";
response = executeCommand(command);
System.out.println(command);
if(response.contains("burly")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": i want to create a bridge (too vague)";
response = executeCommand(command);
System.out.println(command);
if(response.contains("Error")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": i want to create a bridge across the river (atleast one subject)";
response = executeCommand(command);
System.out.println(command);
if(response.contains("other side")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": look (check for clearing)";
response = executeCommand(command);
System.out.println(command);
if(response.contains("clearing")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": goto clearing";
response = executeCommand(command);
System.out.println(command);
if(response.contains("clearing")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": dig into the ground with my shovel";
response = executeCommand(command);
System.out.println(command);
if(response.contains("gold")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": get that gold ASAP";
response = executeCommand(command);
System.out.println(command);
if(response.contains("gold")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": look";
response = executeCommand(command);
System.out.println(command);
if(response.contains("hole")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
System.out.println("\nJust going to teleport the player to the cellar and make him fight with the elf.\n");
command = playerOne + ": goto riverbank";
executeCommand(command);
command = playerOne + ": goto forest";
executeCommand(command);
command = playerOne + ": goto cabin";
executeCommand(command);
command = playerOne + ": goto cellar";
executeCommand(command);
command = playerOne + ": look (should be in the cellar here)";
response = executeCommand(command);
System.out.println(command);
if(response.contains("angry")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": fight the elf";
response = executeCommand(command);
System.out.println(command);
if(response.contains("health") && response.contains("lose")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": health";
response = executeCommand(command);
System.out.println(command);
if(response.contains("2")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": hit the elf";
response = executeCommand(command);
System.out.println(command);
if(response.contains("health") && response.contains("lose")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": health";
response = executeCommand(command);
System.out.println(command);
if(response.contains("1")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": slap the elf";
response = executeCommand(command);
System.out.println(command);
if(response.contains("health")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": look";
response = executeCommand(command);
System.out.println(command);
if(response.contains("cabin")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": goto cellar";
response = executeCommand(command);
System.out.println(command);
if(response.contains("angry")) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": look (expect to find gold, potion, shovel and axe)";
response = executeCommand(command);
System.out.println(command);
if(response.contains("gold") && response.contains("potion") &&
response.contains("shovel") && response.contains("axe"))
System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
}
private static void multiplayerTests() {
String command;
String response;
command = playerOne + ": look ";
executeCommand(command);
System.out.println(command);
command = playerTwo + ": look ";
response = executeCommand(command);
System.out.println(command);
if(response.contains(playerOne) && !response.contains(playerTwo)) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerThree + ": look ";
response = executeCommand(command);
System.out.println(command);
if(response.contains(playerTwo) && response.contains(playerOne)) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerWithSpaces + ": look ";
response = executeCommand(command);
System.out.println(command);
if(response.contains(playerOne) && response.contains(playerTwo) && response.contains(playerThree) && !response.contains(playerWithSpaces)) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
command = playerOne + ": goto forest";
executeCommand(command);
System.out.println(command);
command = playerOne + ": goto cabin (basically going back and checking if other players are there)";
response = executeCommand(command);
System.out.println(command);
if(response.contains(playerTwo) && response.contains(playerThree) && response.contains(playerWithSpaces) && !response.contains(playerOne)) System.out.println(ANSI_GREEN + "SUCCESS" + ANSI_RESET);
else System.out.println(ANSI_RED + "FAIL" + ANSI_RESET);
}
}