tty-solitaire/tests/card_test.c

82 lines
1.4 KiB
C
Raw Normal View History

2011-02-07 01:31:55 +00:00
#include <assert.h>
2011-05-08 02:09:39 +00:00
#include "test_helper.h"
2011-05-31 06:03:13 +00:00
#include "../src/card.h"
2011-02-07 01:31:55 +00:00
void test_card_init() {
2011-02-12 18:28:58 +00:00
struct card *card;
card_malloc(&card);
card_init(card);
2011-02-12 18:28:58 +00:00
assert(card->value == NO_VALUE);
assert(card->suit == NO_SUIT);
assert(card->face == NO_FACE);
card_free(card);
2011-02-12 18:28:58 +00:00
}
void test_card_dup() {
2011-05-01 06:06:43 +00:00
struct card *card_0, *card_1;
2011-05-09 03:38:31 +00:00
const int begin_y = 5, begin_x = 10;
2011-05-01 06:06:43 +00:00
card_malloc(&card_0);
card_set(card_0, ACE, SPADES, EXPOSED, begin_y, begin_x);
card_1 = card_dup(card_0);
2011-05-01 06:06:43 +00:00
assert(card_0 != card_1);
assert(cards_equal(card_0, card_1));
card_free(card_0);
card_free(card_1);
2011-05-01 06:06:43 +00:00
}
void test_card_set() {
2011-02-12 18:28:58 +00:00
struct card *card;
2011-05-09 03:38:31 +00:00
int begin_y = 5;
int begin_x = 10;
2011-02-12 18:28:58 +00:00
card_malloc(&card);
card_init(card);
card_set(card, ACE, SPADES, EXPOSED, begin_y, begin_x);
2011-02-12 18:28:58 +00:00
assert(card->value == ACE);
assert(card->suit == SPADES);
assert(card->face == EXPOSED);
2011-05-09 03:38:31 +00:00
assert(card->frame->begin_y == begin_y);
assert(card->frame->begin_x == begin_x);
2011-02-12 18:28:58 +00:00
card_free(card);
2011-02-12 18:28:58 +00:00
}
void test_card_expose() {
2011-02-12 18:28:58 +00:00
struct card *card;
card_malloc(&card);
card_init(card);
card_expose(card);
2011-02-12 18:28:58 +00:00
assert(card->face == EXPOSED);
card_free(card);
2011-02-12 18:28:58 +00:00
}
void test_card_cover() {
2011-02-12 18:28:58 +00:00
struct card *card;
card_malloc(&card);
card_init(card);
card_cover(card);
2011-02-12 18:28:58 +00:00
assert(card->face == COVERED);
card_free(card);
2011-02-12 18:28:58 +00:00
}
2011-02-07 01:31:55 +00:00
void test_card() {
test_card_init();
test_card_dup();
test_card_set();
test_card_expose();
test_card_cover();
2011-02-07 01:31:55 +00:00
}