2011-02-07 01:31:55 +00:00
|
|
|
#include <assert.h>
|
2011-05-08 02:09:39 +00:00
|
|
|
#include "test_helper.h"
|
2011-02-07 01:31:55 +00:00
|
|
|
#include "../lib/card.h"
|
|
|
|
|
2011-02-12 18:28:58 +00:00
|
|
|
void test_initialize_card() {
|
|
|
|
struct card *card;
|
|
|
|
|
|
|
|
allocate_card(&card);
|
|
|
|
initialize_card(card);
|
|
|
|
|
|
|
|
assert(card->value == NO_VALUE);
|
|
|
|
assert(card->suit == NO_SUIT);
|
|
|
|
assert(card->face == NO_FACE);
|
|
|
|
|
2011-02-14 02:10:47 +00:00
|
|
|
free_card(card);
|
2011-02-12 18:28:58 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-01 06:06:43 +00:00
|
|
|
void test_duplicate_card() {
|
|
|
|
struct card *card_0, *card_1;
|
|
|
|
const int start_y = 5, start_x = 10;
|
|
|
|
|
|
|
|
allocate_card(&card_0);
|
|
|
|
set_card(card_0, ACE, SPADES, EXPOSED, start_y, start_x);
|
|
|
|
card_1 = duplicate_card(card_0);
|
|
|
|
|
|
|
|
assert(card_0 != card_1);
|
|
|
|
assert(cards_equal(card_0, card_1));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-12 18:28:58 +00:00
|
|
|
void test_set_card() {
|
|
|
|
struct card *card;
|
|
|
|
int start_y = 5;
|
|
|
|
int start_x = 10;
|
|
|
|
|
|
|
|
allocate_card(&card);
|
|
|
|
initialize_card(card);
|
|
|
|
set_card(card, ACE, SPADES, EXPOSED, start_y, start_x);
|
|
|
|
|
|
|
|
assert(card->value == ACE);
|
|
|
|
assert(card->suit == SPADES);
|
|
|
|
assert(card->face == EXPOSED);
|
|
|
|
assert(card->frame->start_y == start_y);
|
|
|
|
assert(card->frame->start_x == start_x);
|
|
|
|
|
2011-02-14 02:10:47 +00:00
|
|
|
free_card(card);
|
2011-02-12 18:28:58 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_expose_card() {
|
|
|
|
struct card *card;
|
|
|
|
|
|
|
|
allocate_card(&card);
|
|
|
|
initialize_card(card);
|
|
|
|
expose_card(card);
|
|
|
|
|
|
|
|
assert(card->face == EXPOSED);
|
|
|
|
|
2011-02-14 02:10:47 +00:00
|
|
|
free_card(card);
|
2011-02-12 18:28:58 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_cover_card() {
|
|
|
|
struct card *card;
|
|
|
|
|
|
|
|
allocate_card(&card);
|
|
|
|
initialize_card(card);
|
|
|
|
cover_card(card);
|
|
|
|
|
|
|
|
assert(card->face == COVERED);
|
|
|
|
|
2011-02-14 02:10:47 +00:00
|
|
|
free_card(card);
|
2011-02-12 18:28:58 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-07 01:31:55 +00:00
|
|
|
void test_card() {
|
2011-02-12 18:28:58 +00:00
|
|
|
test_initialize_card();
|
2011-05-01 06:06:43 +00:00
|
|
|
test_duplicate_card();
|
2011-02-12 18:28:58 +00:00
|
|
|
test_set_card();
|
|
|
|
test_expose_card();
|
|
|
|
test_cover_card();
|
2011-02-07 01:31:55 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|