-
Notifications
You must be signed in to change notification settings - Fork 3
/
testDracView.c
113 lines (101 loc) · 4.42 KB
/
testDracView.c
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
// testDracView.c ... test the DracView ADT
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "DracView.h"
int main()
{
int i;
DracView dv;
printf("Test for basic functions, just before Dracula's first move\n");
PlayerMessage messages1[] = {"Hello","Rubbish","Stuff",""};
dv = newDracView("GST.... SAO.... HZU.... MBB....", messages1);
assert(giveMeTheRound(dv) == 0);
assert(whereIs(dv,PLAYER_LORD_GODALMING) == STRASBOURG);
assert(whereIs(dv,PLAYER_DR_SEWARD) == ATLANTIC_OCEAN);
assert(whereIs(dv,PLAYER_VAN_HELSING) == ZURICH);
assert(whereIs(dv,PLAYER_MINA_HARKER) == BAY_OF_BISCAY);
assert(whereIs(dv,PLAYER_DRACULA) == UNKNOWN_LOCATION);
assert(howHealthyIs(dv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS);
printf("passed\n");
disposeDracView(dv);
printf("Test for encountering Dracula and hunter history\n");
PlayerMessage messages2[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","",""};
dv = newDracView("GST.... SAO.... HCD.... MAO.... DGE.... "
"GGED... SAO.... HCD.... MAO....", messages2);
assert(giveMeTheRound(dv) == 1);
assert(whereIs(dv,PLAYER_DRACULA) == GENEVA);
assert(howHealthyIs(dv,PLAYER_LORD_GODALMING) == 5);
assert(howHealthyIs(dv,PLAYER_DRACULA) == 30);
assert(whereIs(dv,PLAYER_LORD_GODALMING) == GENEVA);
LocationID history[TRAIL_SIZE];
giveMeTheTrail(dv,PLAYER_DRACULA,history);
assert(history[0] == GENEVA);
assert(history[2] == UNKNOWN_LOCATION);
giveMeTheTrail(dv,PLAYER_LORD_GODALMING,history);
assert(history[0] == GENEVA);
assert(history[1] == STRASBOURG);
assert(history[2] == UNKNOWN_LOCATION);
giveMeTheTrail(dv,PLAYER_DR_SEWARD,history);
assert(history[0] == ATLANTIC_OCEAN);
assert(history[1] == ATLANTIC_OCEAN);
assert(history[2] == UNKNOWN_LOCATION);
printf("passed\n");
disposeDracView(dv);
printf("Test for Dracula leaving minions\n");
PlayerMessage messages3[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","","","Drop a V","Party in Strasbourg","Party","Party","Party"};
dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. "
"GST.... SST.... HST.... MST.... DMNT... "
"GST.... SST.... HST.... MST....", messages3);
int nT, nV;
whatsThere(dv,EDINBURGH,&nT,&nV);
assert(nT == 0 && nV == 1);
whatsThere(dv,MANCHESTER,&nT,&nV);
assert(nT == 1 && nV == 0);
assert(whereIs(dv,PLAYER_DRACULA) == MANCHESTER);
giveMeTheTrail(dv,PLAYER_DRACULA,history);
assert(history[0] == MANCHESTER);
assert(history[1] == EDINBURGH);
assert(history[2] == UNKNOWN_LOCATION);
giveMeTheTrail(dv,PLAYER_MINA_HARKER,history);
assert(history[0] == STRASBOURG);
assert(history[1] == STRASBOURG);
assert(history[2] == GENEVA);
assert(history[3] == UNKNOWN_LOCATION);
printf("passed\n");
disposeDracView(dv);
printf("Test for connections\n");
int size, seen[NUM_MAP_LOCATIONS], *edges;
printf("Checking Galatz road connections\n");
PlayerMessage messages5[] = {"Gone to Galatz"};
dv = newDracView("GGA....", messages5);
edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,1,0,0);
memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));
for (i = 0; i< size ; i++) seen[edges[i]] = 1;
assert(size == 5); assert(seen[GALATZ]); assert(seen[CONSTANTA]);
assert(seen[BUCHAREST]); assert(seen[KLAUSENBURG]); assert(seen[CASTLE_DRACULA]);
free(edges);
disposeDracView(dv);
printf("Checking Ionian Sea sea connections\n");
PlayerMessage messages6[] = {"Sailing the Ionian"};
dv = newDracView("GIO....", messages6);
edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,0,0,1);
memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));
for (i = 0; i < size; i++) seen[edges[i]] = 1;
assert(size == 7); assert(seen[IONIAN_SEA]); assert(seen[BLACK_SEA]);
assert(seen[ADRIATIC_SEA]); assert(seen[TYRRHENIAN_SEA]);
assert(seen[ATHENS]); assert(seen[VALONA]); assert(seen[SALONICA]);
free(edges);
disposeDracView(dv);
printf("Checking Athens rail connections (none)\n");
PlayerMessage messages7[] = {"Leaving Athens by train"};
dv = newDracView("GAT....", messages7);
edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,0,1,0);
assert(size == 1);
assert(edges[0] == ATHENS);
free(edges);
disposeDracView(dv);
printf("passed\n");
return 0;
}