-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_player.c
276 lines (231 loc) · 7.6 KB
/
test_player.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
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
#include <stdio.h>
#include <head-unit.h>
#include "player.h"
#include "card.h"
static struct card_t tenD;
static struct card_t sevenH;
static struct card_t fourS;
static struct card_t fiveH;
static struct card_t nineS;
static struct card_t jackD;
static struct card_t queenH;
static struct card_t kingS;
static struct card_t aceD;
static struct card_t aceH;
static struct card_t aceS;
static struct card_t tenD;
static struct card_t threeD;
static struct card_t nineD;
static struct card_t aceC;
static struct card_t twoD;
static struct card_t fiveD;
static struct card_t sixH;
static struct card_t eightD;
static struct card_t nineC;
static void setup(void)
{
tenD = make_card(TEN, DIAMONDS);
sevenH = make_card(SEVEN, HEARTS);
fourS = make_card(FOUR, SPADES);
fiveH = make_card(FIVE, HEARTS);
nineS = make_card(NINE, SPADES);
jackD = make_card(JACK, DIAMONDS);
queenH = make_card(QUEEN, HEARTS);
kingS = make_card(KING, SPADES);
aceD = make_card(ACE, DIAMONDS);
aceH = make_card(ACE, HEARTS);
aceS = make_card(ACE, SPADES);
tenD = make_card(TEN, DIAMONDS);
threeD = make_card(THREE, DIAMONDS);
nineD = make_card(NINE, DIAMONDS);
aceC = make_card(ACE, CLUBS);
twoD = make_card(TWO, DIAMONDS);
fiveD = make_card(FIVE, DIAMONDS);
sixH = make_card(SIX, HEARTS);
eightD = make_card(EIGHT, DIAMONDS);
nineC = make_card(NINE, CLUBS);
}
static void test_lowest_card_by_player(void)
{
struct player_t steve = make_player("Steve", 'h');
struct player_t james = make_player("James", 'h');
struct player_t dave = make_player("Dave", 'h');
struct player_t mike = make_player("Mike", 'h');
struct player_t players[4];
struct card_t lowest_cards[4];
deal_to_hand(&steve, tenD);
deal_to_hand(&steve, sevenH);
deal_to_hand(&steve, fourS);
deal_to_hand(&james, fourS);
deal_to_hand(&james, fiveH);
deal_to_hand(&james, nineS);
deal_to_hand(&dave, jackD);
deal_to_hand(&dave, queenH);
deal_to_hand(&dave, kingS);
deal_to_hand(&mike, aceD);
deal_to_hand(&mike, aceH);
deal_to_hand(&mike, aceS);
players[0] = steve;
players[1] = james;
players[2] = dave;
players[3] = mike;
find_lowest_card_by_player(players, 4, lowest_cards);
assert_true(cards_equal(&lowest_cards[0], &fourS));
assert_true(cards_equal(&lowest_cards[1], &fourS));
assert_true(cards_equal(&lowest_cards[2], &jackD));
assert_int_equals(ACE, lowest_cards[3].rank);
}
static void swap_first_two_cards(void)
{
struct player_t james = make_player("James", 'h');
struct swap_choice_t choice;
deal_to_hand(&james, fourS);
deal_to_hand(&james, tenD);
deal_to_hand(&james, sevenH);
sort_cards(james.hand, james.hand_size);
deal_to_face_up(&james, threeD);
deal_to_face_up(&james, nineD);
deal_to_face_up(&james, aceC);
choice.hand_choice = 1;
choice.faceup_choice = 1;
swap(&james, &choice);
assert_true(cards_equal(&james.hand[0], &threeD));
assert_true(cards_equal(&james.face_up[0], &fourS));
}
static void swap_last_two_cards(void)
{
struct player_t james = make_player("James", 'h');
struct swap_choice_t choice;
deal_to_hand(&james, fourS);
deal_to_hand(&james, aceD);
deal_to_hand(&james, sevenH);
sort_cards(james.hand, james.hand_size);
deal_to_face_up(&james, nineD);
deal_to_face_up(&james, aceC);
deal_to_face_up(&james, twoD);
choice.hand_choice = 3;
choice.faceup_choice = 3;
swap(&james, &choice);
assert_true(cards_equal(&james.hand[2], &twoD));
assert_true(cards_equal(&james.face_up[2], &sevenH));
}
static void swap_first_and_last(void)
{
struct player_t james = make_player("James", 'h');
struct swap_choice_t choice;
deal_to_hand(&james, fourS);
deal_to_hand(&james, fiveD);
deal_to_hand(&james, sixH);
sort_cards(james.hand, james.hand_size);
deal_to_face_up(&james, eightD);
deal_to_face_up(&james, nineC);
deal_to_face_up(&james, jackD);
choice.hand_choice = 1;
choice.faceup_choice = 3;
swap(&james, &choice);
assert_true(cards_equal(&james.hand[2], &jackD));
assert_true(cards_equal(&james.face_up[2], &fourS));
}
static void swap_middle_cards(void)
{
struct player_t james = make_player("James", 'h');
struct swap_choice_t choice;
deal_to_hand(&james, fourS);
deal_to_hand(&james, fiveD);
deal_to_hand(&james, sixH);
sort_cards(james.hand, james.hand_size);
deal_to_face_up(&james, eightD);
deal_to_face_up(&james, nineC);
deal_to_face_up(&james, jackD);
choice.hand_choice = 2;
choice.faceup_choice = 2;
swap(&james, &choice);
assert_true(cards_equal(&james.hand[2], &nineC));
assert_true(cards_equal(&james.face_up[1], &fiveD));
}
static void test_has_cards_when_hand_does(void)
{
struct player_t james = make_player("James", 'h');
deal_to_hand(&james, tenD);
deal_to_hand(&james, sevenH);
deal_to_hand(&james, fourS);
assert_true(has_cards(&james));
}
static void test_has_cards_when_face_up_does(void)
{
struct player_t james = make_player("James", 'h');
deal_to_face_up(&james, tenD);
deal_to_face_up(&james, sevenH);
deal_to_face_up(&james, fourS);
assert_true(has_cards(&james));
}
static void test_has_cards_when_face_down_does(void)
{
struct player_t james = make_player("James", 'h');
deal_to_face_down(&james, tenD);
deal_to_face_down(&james, sevenH);
deal_to_face_down(&james, fourS);
assert_true(has_cards(&james));
}
static void test_has_cards_when_one(void)
{
struct player_t james = make_player("James", 'h');
deal_to_hand(&james, tenD);
assert_true(has_cards(&james));
}
static void test_not_has_cards_when_none(void)
{
struct player_t james = make_player("James", 'h');
assert_false(has_cards(&james));
}
static void test_remove_from_hand(void)
{
struct player_t james = make_player("James", 'h');
deal_to_hand(&james, tenD);
deal_to_hand(&james, sevenH);
deal_to_hand(&james, fourS);
remove_from_hand(&james, &tenD);
assert_int_equals(james.hand_size, 2);
assert_false(cards_equal(&james.hand[0], &tenD));
assert_false(cards_equal(&james.hand[1], &tenD));
}
static void test_remove_from_face_up(void)
{
struct player_t james = make_player("James", 'h');
deal_to_face_up(&james, tenD);
deal_to_face_up(&james, sevenH);
deal_to_face_up(&james, fourS);
remove_from_face_up(&james, &tenD);
assert_int_equals(james.face_up_size, 2);
assert_false(cards_equal(&james.face_up[0], &tenD));
assert_false(cards_equal(&james.face_up[1], &tenD));
}
static void test_remove_from_face_down(void)
{
struct player_t james = make_player("James", 'h');
deal_to_face_down(&james, tenD);
deal_to_face_down(&james, sevenH);
deal_to_face_down(&james, fourS);
remove_from_face_down(&james, &tenD);
assert_int_equals(james.face_down_size, 2);
assert_false(cards_equal(&james.face_down[0], &tenD));
assert_false(cards_equal(&james.face_down[1], &tenD));
}
void register_player_tests(void)
{
TEST_MODULE("test_player");
SETUP(setup);
TEST(test_lowest_card_by_player);
TEST(swap_first_two_cards);
TEST(swap_last_two_cards);
TEST(swap_first_and_last);
TEST(swap_middle_cards);
TEST(test_has_cards_when_hand_does);
TEST(test_has_cards_when_face_up_does);
TEST(test_has_cards_when_face_down_does);
TEST(test_has_cards_when_one);
TEST(test_not_has_cards_when_none);
TEST(test_remove_from_hand);
TEST(test_remove_from_face_up);
TEST(test_remove_from_face_down);
}