/
testGame.c
225 lines (211 loc) · 6.92 KB
/
testGame.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
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
// Tests Game.c (extensively)
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "Game.h"
void test1(void);
void test2(void);
void test3(void);
void test4(void);
void test5(void);
void test6(void);
void test7(void);
void test8(void);
void test9 (void);
void test10(void);
int main(int argc, char const *argv[]) {
// extensive testing here!
test1();
test2();
test3();
test4();
test5();
test6();
test7();
test8();
test9 ();
test10();
printf("All tests passed, you are Awesome!\n");
return EXIT_SUCCESS;
}
// test we can build a campus
void test1(void) {
printf("\n\n\n\n");
action a;
int disciplines[] = {2,5 ,3,5 ,3,1,4,4 ,1,4 ,2,3,2,0,3,5,4,2 ,1};
int dice[] = {9,10,8,12,6,5,3,11,3,11,4,6,4,9,9,2,8,10,5};
Game g = newGame(disciplines, dice);
throwDice(g, 4);
a.actionCode = BUILD_CAMPUS;
strncpy(a.destination, "RL", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = 2, a.disciplineTo = 1;
makeAction(g, a);
assert (getCampus(g, a.destination) == 1);
}
// test isLegalAction() building GO8
void test2(void) {
printf("\n\n\n\n");
action a;
int disciplines[] = {0,1,2,1,4,5,0,3,2,3,4,5,0,1,2,3,4,5,0};
int dice[] = {12,11,10,9,8,7,6,5,4,3,2,12,11,10,9,8,7,6,5};
Game g = newGame(disciplines, dice);
throwDice(g, 5);
throwDice(g, 5);
throwDice(g, 12);
throwDice(g, 12);
a.actionCode = BUILD_GO8;
strncpy(a.destination, "", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = 3, a.disciplineTo = 2;
isLegalAction(g, a);
assert(isLegalAction (g, a) == 1);
}
void test3(void) {
printf("\n\n\n\n");
action a;
int disciplines[] = {2,5,3,5,3,1,4,4,1,4,2,3,2,0,3,5,4,2,1};
int dice[] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};
Game g = newGame(disciplines, dice);
throwDice(g, 5);
a.actionCode = BUILD_CAMPUS;
strncpy(a.destination, "RL", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = -1077724424, a.disciplineTo = 134527641;
makeAction(g, a);
assert(getCampus(g, "RL") == 1);
}
// test getExchangeRate
void test6(void) {
printf("\n\n\n\n");
action a;
int disciplines[] = {2,5,3,5,3,1,4,4,1,4,2,3,2,0,3,5,4,2,1};
int dice[] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};
Game g = newGame(disciplines, dice);
throwDice(g, 5);
a.actionCode = BUILD_CAMPUS;
strncpy(a.destination, "R", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = 1, a.disciplineTo = -1217678112;
makeAction(g, a);
assert(getExchangeRate (g, 1, 4, 1) == 2);
}
// test building ARC
void test4(void) {
printf("\n\n\n\n");
action a;
int disciplines[] = {2,5,3,5,3,1,4,4,1,4,2,3,2,0,3,5,4,2,1};
int dice[] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};
Game g = newGame(disciplines, dice);
throwDice(g, 5);
a.actionCode = OBTAIN_ARC;
strncpy(a.destination, "L", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = 134528624, a.disciplineTo = -1081831912;
assert(isLegalAction(g, a) == 1);
makeAction(g, a);
a.actionCode = OBTAIN_ARC;
strncpy(a.destination, "LR", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = 134528624, a.disciplineTo = -1081831912;
assert(isLegalAction(g, a) == 1);
}
// test getMostArcs
void test5(void) {
printf("\n\n\n\n");
action a;
int disciplines[] = {4,2,5,4,2,2,3,5,1,3,5,4,4,4,3,5,4,0,5};
int dice[] = {8,10,8,9,6,4,4,5,12,3,11,6,3,11,2,7,5,6,5};
Game g = newGame(disciplines, dice);
throwDice(g, 7);
a.actionCode = OBTAIN_ARC;
strncpy(a.destination, "L", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = 0, a.disciplineTo = 0;
makeAction(g, a);
assert(getMostARCs(g) == 1);
}
// test regions are loaded properly
void test7(void) {
printf("\n\n\n\n");
int disciplines[] = {2,5,3,5,3,1,4,4,1,4,2,3,2,0,3,5,4,2,1};
int dice[] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};
Game g = newGame(disciplines, dice);
int region = 0;
while (region < NUM_REGIONS) {
assert(getDiceValue(g, region) >= 2 && getDiceValue(g, region) <=12);
region++;
}
}
void test8(void) {
return;
}
// test starting spinoffs
void test9 (void) {
action a;
int disciplines[] = {2,5,3,5,3,1,4,4,1,4,2,3,2,0,3,5,4,2,1};
int dice[] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};
Game g = newGame(disciplines, dice);
throwDice(g, 8);
a.actionCode = OBTAIN_ARC;
strncpy(a.destination, "R", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = -1217350860, a.disciplineTo = 7;
makeAction(g, a);
a.actionCode = OBTAIN_ARC;
strncpy(a.destination, "RR", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = -1217350860, a.disciplineTo = 7;
makeAction(g, a);
a.actionCode = PASS;
strncpy(a.destination, "", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = -1078711464, a.disciplineTo = 134586891;
makeAction(g, a);
throwDice(g, 5);
a.actionCode = OBTAIN_ARC;
strncpy(a.destination, "RRLRLL", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = -1217350860, a.disciplineTo = 7;
makeAction(g, a);
a.actionCode = PASS;
strncpy(a.destination, "", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = -1078711464, a.disciplineTo = 134586891;
makeAction(g, a);
throwDice(g, 6);
a.actionCode = OBTAIN_PUBLICATION;
strncpy(a.destination, "", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = 1, a.disciplineTo = 2329;
printf("%d\n", getStudents(g, 3, 3));
makeAction(g, a);
assert(getStudents(g, 3, 3) == 1);
}
// some more isLegalAction testing
void test10 (void) {
action a;
int disciplines[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int dice[] = {6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6};
Game g = newGame(disciplines, dice);
throwDice(g, 6);
throwDice(g, 6);
throwDice(g, 6);
throwDice(g, 6);
a.actionCode = OBTAIN_ARC;
strncpy(a.destination, "R", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = 4, a.disciplineTo = 3;
makeAction(g, a);
a.actionCode = OBTAIN_ARC;
strncpy(a.destination, "RR", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = 4, a.disciplineTo = 3;
makeAction(g, a);
a.actionCode = BUILD_CAMPUS;
strncpy(a.destination, "RR", PATH_LIMIT - 1);
a.destination[PATH_LIMIT - 1] = 0;
a.disciplineFrom = 4, a.disciplineTo = 3;
assert(isLegalAction(g, a) == 1);
}