-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_lowcard_player.c
185 lines (149 loc) · 4.98 KB
/
test_lowcard_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
#include <stdio.h>
#include <head-unit.h>
#include "player.h"
#include "card.h"
static struct card_t fourD = { FOUR, DIAMONDS };
static struct card_t fiveH = { FIVE, HEARTS };
static struct card_t sixH = { SIX, HEARTS };
static struct card_t sixC = { SIX, CLUBS };
static struct card_t aceS = { ACE, SPADES };
static struct card_t aceD = { ACE, DIAMONDS };
static struct card_t twoS = { TWO, SPADES };
static struct card_t tenC = { TEN, CLUBS };
static void test_is_computer(void)
{
struct player_t low = make_player("Low", 'l');
assert_true(low.is_computer);
}
static void doesnt_swap_cards(void)
{
struct player_t low = make_player("Low", 'l');
assert_false(ask_swap_cards(&low));
}
static void always_chooses_first_face_down(void)
{
struct player_t low = make_player("Low", 'l');
assert_int_equals(1, low.ask_face_down_move());
}
static void chooses_low_from_hand_when_empty_pile()
{
int choices[20];
int nchoices;
struct player_t low = make_player("Low", 'l');
deal_to_hand(&low, fourD);
deal_to_hand(&low, sixH);
deal_to_hand(&low, aceS);
sort_cards(low.hand, low.hand_size);
struct card_t pile[0];
struct player_helper_t helper = make_helper(pile, 0);
ask_move(&low, &helper, choices, &nchoices);
assert_int_equals(1, nchoices);
assert_true(cards_equal(&fourD, &low.hand[choices[0]]));
}
static void chooses_low_from_face_up_when_empty_pile()
{
int choices[20];
int nchoices;
struct player_t low = make_player("Low", 'l');
deal_to_face_up(&low, sixH);
deal_to_face_up(&low, fourD);
deal_to_face_up(&low, aceS);
struct card_t pile[0];
struct player_helper_t helper = make_helper(pile, 0);
ask_move(&low, &helper, choices, &nchoices);
assert_int_equals(1, nchoices);
assert_true(cards_equal(&fourD, &low.face_up[choices[0]]));
}
static void chooses_lowest_from_hand_on_pile()
{
int choices[20];
int nchoices;
struct player_t low = make_player("Low", 'l');
deal_to_hand(&low, tenC);
deal_to_hand(&low, fourD);
deal_to_hand(&low, sixH);
deal_to_hand(&low, twoS);
deal_to_hand(&low, aceS);
sort_cards(low.hand, low.hand_size);
struct card_t pile[1];
pile[0] = aceD;
struct player_helper_t helper = make_helper(pile, 1);
ask_move(&low, &helper, choices, &nchoices);
assert_int_equals(1, nchoices);
assert_true(cards_equal(&aceS, &low.hand[choices[0]]));
}
static void chooses_lowest_from_face_up_on_pile()
{
int choices[20];
int nchoices;
struct player_t low = make_player("Low", 'l');
deal_to_face_up(&low, tenC);
deal_to_face_up(&low, fourD);
deal_to_face_up(&low, sixH);
deal_to_face_up(&low, twoS);
deal_to_face_up(&low, aceS);
struct card_t pile[1];
pile[0] = sixC;
struct player_helper_t helper = make_helper(pile, 1);
ask_move(&low, &helper, choices, &nchoices);
assert_int_equals(1, nchoices);
assert_true(cards_equal(&sixH, &low.face_up[choices[0]]));
}
static void chooses_two_cards_from_hand_when_can()
{
int choices[20];
int nchoices;
struct player_t low = make_player("Low", 'l');
deal_to_hand(&low, tenC);
deal_to_hand(&low, fourD);
deal_to_hand(&low, sixH);
deal_to_hand(&low, twoS);
deal_to_hand(&low, sixC);
deal_to_hand(&low, aceS);
sort_cards(low.hand, low.hand_size);
struct card_t pile[1];
pile[0] = fiveH;
struct player_helper_t helper = make_helper(pile, 1);
ask_move(&low, &helper, choices, &nchoices);
assert_int_equals(2, nchoices);
struct card_t first = low.hand[choices[0]];
struct card_t second = low.hand[choices[1]];
assert_int_equals(SIX, first.rank);
assert_int_equals(SIX, second.rank);
assert_false(cards_equal(&first, &second));
}
static void chooses_two_cards_from_face_up_when_can()
{
int choices[20];
int nchoices;
struct player_t low = make_player("Low", 'l');
deal_to_face_up(&low, tenC);
deal_to_face_up(&low, fourD);
deal_to_face_up(&low, sixH);
deal_to_face_up(&low, twoS);
deal_to_face_up(&low, sixC);
deal_to_face_up(&low, aceS);
struct card_t pile[1];
pile[0] = fiveH;
struct player_helper_t helper = make_helper(pile, 1);
ask_move(&low, &helper, choices, &nchoices);
assert_int_equals(2, nchoices);
struct card_t first = low.face_up[choices[0]];
struct card_t second = low.face_up[choices[1]];
assert_int_equals(SIX, first.rank);
assert_int_equals(SIX, second.rank);
assert_false(cards_equal(&first, &second));
}
void register_lowcard_player_tests(void)
{
TEST_MODULE("test_lowcard_player");
TEST(test_is_computer);
TEST(doesnt_swap_cards);
TEST(always_chooses_first_face_down);
TEST(chooses_low_from_hand_when_empty_pile);
TEST(chooses_low_from_face_up_when_empty_pile);
TEST(chooses_lowest_from_hand_on_pile);
TEST(chooses_lowest_from_face_up_on_pile);
TEST(chooses_two_cards_from_hand_when_can);
TEST(chooses_two_cards_from_face_up_when_can);
}