-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_game.c
More file actions
183 lines (145 loc) · 4.21 KB
/
test_game.c
File metadata and controls
183 lines (145 loc) · 4.21 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
#include <stdio.h>
#include <string.h>
#include <head-unit.h>
#include "game.h"
static char names[MAX_NUM_PLAYERS][MAX_NAME_LEN];
static char types[MAX_NUM_PLAYERS];
static struct game_t game;
static struct player_t *player;
static int choices[4];
static int num_choices;
static void setup_game(void)
{
strcpy(names[0],"p1");
types[0] = 'h';
game = make_game(2, names, types, 3);
game.current_player = 0;
player = &game.players[game.current_player];
}
static void test_ten_on_nothing_burns(void)
{
setup_game();
player->hand[0] = make_card(TEN, SPADES);
player->hand_size = 1;
choices[0] = 0;
num_choices = 1;
make_move(&game, choices, num_choices);
assert_true(game.pile_size == 0);
}
static void test_ten_on_two_cards_burns(void)
{
setup_game();
player->hand[0] = make_card(TEN, HEARTS);
player->hand_size = 1;
choices[0] = 0;
num_choices = 1;
game.pile[0] = make_card(THREE, DIAMONDS);
game.pile[1] = make_card(NINE, DIAMONDS);
game.pile_size = 2;
make_move(&game, choices, num_choices);
assert_true(game.pile_size == 0);
}
static void test_four_of_a_kind_burns(void)
{
setup_game();
player->hand[0] = make_card(FOUR, DIAMONDS);
player->hand[1] = make_card(FOUR, HEARTS);
player->hand[2] = make_card(FOUR, SPADES);
player->hand[3] = make_card(FOUR, CLUBS);
player->hand_size = 4;
choices[0] = 0;
choices[1] = 1;
choices[2] = 2;
choices[3] = 3;
num_choices = 4;
game.pile[0] = make_card(TWO, DIAMONDS);
game.pile[1] = make_card(THREE, DIAMONDS);
game.pile_size = 2;
make_move(&game, choices, num_choices);
assert_true(game.pile_size == 0);
}
static void test_three_same_on_one_same_burns(void)
{
setup_game();
player->hand[0] = make_card(FOUR, DIAMONDS);
player->hand[1] = make_card(FOUR, HEARTS);
player->hand[2] = make_card(FOUR, SPADES);
player->hand_size = 4;
choices[0] = 0;
choices[1] = 1;
choices[2] = 2;
num_choices = 3;
game.pile[0] = make_card(TWO, DIAMONDS);
game.pile[1] = make_card(FOUR, CLUBS);
game.pile_size = 2;
make_move(&game, choices, num_choices);
assert_true(game.pile_size == 0);
}
static void test_two_same_on_two_same_burns(void)
{
setup_game();
player->hand[0] = make_card(FOUR, DIAMONDS);
player->hand[1] = make_card(FOUR, HEARTS);
player->hand_size = 4;
choices[0] = 0;
choices[1] = 1;
num_choices = 2;
game.pile[0] = make_card(TWO, DIAMONDS);
game.pile[1] = make_card(FOUR, CLUBS);
game.pile[2] = make_card(FOUR, SPADES);
game.pile_size = 3;
make_move(&game, choices, num_choices);
assert_true(game.pile_size == 0);
}
static void test_one_same_on_three_same_burns(void)
{
setup_game();
player->hand[0] = make_card(FOUR, DIAMONDS);
player->hand_size = 4;
choices[0] = 0;
num_choices = 1;
game.pile[0] = make_card(TWO, DIAMONDS);
game.pile[1] = make_card(FOUR, CLUBS);
game.pile[2] = make_card(FOUR, SPADES);
game.pile[3] = make_card(FOUR, HEARTS);
game.pile_size = 4;
make_move(&game, choices, num_choices);
assert_true(game.pile_size == 0);
}
static void test_player_on_last_cards(void)
{
setup_game();
player->hand_size = 0;
player->face_up_size = 0;
player->face_down_size = 1;
assert_true(player_on_last_cards(&game));
}
static void test_not_player_on_last_cards_when_face_up(void)
{
setup_game();
player->hand_size = 0;
player->face_up_size = 1;
player->face_down_size = 1;
assert_false(player_on_last_cards(&game));
}
static void test_not_player_on_last_cards_when_hand(void)
{
setup_game();
player->hand_size = 1;
player->face_up_size = 1;
player->face_down_size = 1;
assert_false(player_on_last_cards(&game));
}
void register_game_tests(void)
{
TEST_MODULE("test_game");
TEST(test_ten_on_nothing_burns);
TEST(test_ten_on_two_cards_burns);
TEST(test_four_of_a_kind_burns);
TEST(test_three_same_on_one_same_burns);
TEST(test_two_same_on_two_same_burns);
TEST(test_one_same_on_three_same_burns);
TEST(test_player_on_last_cards);
TEST(test_not_player_on_last_cards_when_face_up);
TEST(test_not_player_on_last_cards_when_hand);
}