commit
379ef4322c
@ -153,8 +153,8 @@ static void shuffle_deck(struct deck *deck) {
|
||||
card[i] = stack_pop(&(deck->stock));
|
||||
}
|
||||
srand(time(NULL));
|
||||
for (int i = 0; i < NUMBER_OF_CARDS - 1; i++) {
|
||||
random = i + (rand() % (NUMBER_OF_CARDS) - i);
|
||||
for (int i = 0; i < NUMBER_OF_CARDS; i++) {
|
||||
random = rand() % (NUMBER_OF_CARDS);
|
||||
tmp = *card[i];
|
||||
*card[i] = (*card[random]);
|
||||
*card[random] = tmp;
|
||||
@ -162,6 +162,7 @@ static void shuffle_deck(struct deck *deck) {
|
||||
for (int i = 0; i < NUMBER_OF_CARDS; i++) {
|
||||
stack_push(&(deck->stock), card[i]);
|
||||
}
|
||||
free(card);
|
||||
}
|
||||
|
||||
static void deal_cards(struct deck *deck) {
|
||||
|
@ -69,6 +69,7 @@ int stack_length(struct stack *stack) {
|
||||
void stack_push(struct stack **stack, struct card *card) {
|
||||
if (card) {
|
||||
if (stack_empty(*stack)) {
|
||||
card_free((*stack)->card);
|
||||
(*stack)->card = card;
|
||||
} else {
|
||||
/* Allocating by hand because stack_malloc() would
|
||||
|
@ -25,6 +25,9 @@ void test_card_dup() {
|
||||
|
||||
assert(card_0 != card_1);
|
||||
assert(cards_equal(card_0, card_1));
|
||||
|
||||
card_free(card_0);
|
||||
card_free(card_1);
|
||||
}
|
||||
|
||||
void test_card_set() {
|
||||
|
@ -25,6 +25,9 @@ void test_frame_dup() {
|
||||
|
||||
assert(frame_0 != frame_1);
|
||||
assert(frames_equal(frame_0, frame_1));
|
||||
|
||||
frame_free(frame_0);
|
||||
frame_free(frame_1);
|
||||
}
|
||||
|
||||
void test_frame_set() {
|
||||
|
@ -119,7 +119,7 @@ void test_valid_move_from_waste_pile_to_foundation_stacks() {
|
||||
|
||||
stack_malloc(&waste_pile);
|
||||
stack_init(waste_pile);
|
||||
card_set(waste_pile->card, ACE, SPADES, EXPOSED, WASTE_PILE_BEGIN_Y, WASTE_PILE_BEGIN_X);
|
||||
card_set(waste_pile->card, TWO, SPADES, EXPOSED, WASTE_PILE_BEGIN_Y, WASTE_PILE_BEGIN_X);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
stack_malloc(&foundation_stacks[i]);
|
||||
stack_init(foundation_stacks[i]);
|
||||
@ -129,7 +129,6 @@ void test_valid_move_from_waste_pile_to_foundation_stacks() {
|
||||
card_set(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_2_BEGIN_X);
|
||||
card_set(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_3_BEGIN_X);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// TODO: fix error here
|
||||
assert(valid_move(waste_pile, foundation_stacks[i]));
|
||||
}
|
||||
stack_free(waste_pile);
|
||||
@ -143,20 +142,19 @@ void test_valid_move_from_waste_pile_to_maneuvre_stacks() {
|
||||
|
||||
stack_malloc(&waste_pile);
|
||||
stack_init(waste_pile);
|
||||
card_set(waste_pile->card, ACE, SPADES, EXPOSED, WASTE_PILE_BEGIN_Y, WASTE_PILE_BEGIN_X);
|
||||
card_set(waste_pile->card, ACE, DIAMONDS, EXPOSED, WASTE_PILE_BEGIN_Y, WASTE_PILE_BEGIN_X);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
stack_malloc(&maneuvre_stacks[i]);
|
||||
stack_init(maneuvre_stacks[i]);
|
||||
}
|
||||
card_set(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
card_set(maneuvre_stacks[0]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, TWO, CLUBS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, TWO, CLUBS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, TWO, CLUBS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
// TODO: fix error here
|
||||
assert(valid_move(waste_pile, maneuvre_stacks[i]));
|
||||
}
|
||||
stack_free(waste_pile);
|
||||
@ -219,15 +217,14 @@ void test_valid_move_from_foundation_stack_to_foundation_stacks() {
|
||||
stack_init(foundation_stacks[i]);
|
||||
}
|
||||
card_set(foundation_stacks[0]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_0_BEGIN_X);
|
||||
card_set(foundation_stacks[1]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_1_BEGIN_X);
|
||||
card_set(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_2_BEGIN_X);
|
||||
card_set(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_3_BEGIN_X);
|
||||
card_set(foundation_stacks[1]->card, TWO, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_1_BEGIN_X);
|
||||
card_set(foundation_stacks[2]->card, THREE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_2_BEGIN_X);
|
||||
card_set(foundation_stacks[3]->card, FOUR, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_3_BEGIN_X);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (i == j) {
|
||||
if (i != j + 1) {
|
||||
assert(!valid_move(foundation_stacks[i], foundation_stacks[j]));
|
||||
} else {
|
||||
// TODO: fix error here
|
||||
assert(valid_move(foundation_stacks[i], foundation_stacks[j]));
|
||||
}
|
||||
}
|
||||
@ -247,22 +244,21 @@ void test_valid_move_from_foundation_stack_to_maneuvre_stacks() {
|
||||
}
|
||||
card_set(foundation_stacks[0]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_0_BEGIN_X);
|
||||
card_set(foundation_stacks[1]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_1_BEGIN_X);
|
||||
card_set(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_2_BEGIN_X);
|
||||
card_set(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_3_BEGIN_X);
|
||||
card_set(foundation_stacks[2]->card, ACE, CLUBS, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_2_BEGIN_X);
|
||||
card_set(foundation_stacks[3]->card, ACE, CLUBS, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_3_BEGIN_X);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
stack_malloc(&maneuvre_stacks[i]);
|
||||
stack_init(maneuvre_stacks[i]);
|
||||
}
|
||||
card_set(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
card_set(maneuvre_stacks[0]->card, TWO, HEARTS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, TWO, HEARTS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, TWO, HEARTS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, TWO, HEARTS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, TWO, DIAMONDS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, TWO, DIAMONDS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, TWO, DIAMONDS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 7; j++) {
|
||||
// TODO: fix error here
|
||||
assert(valid_move(foundation_stacks[i], maneuvre_stacks[j]));
|
||||
}
|
||||
}
|
||||
@ -342,16 +338,15 @@ void test_valid_move_from_maneuvre_stack_to_foundation_stacks() {
|
||||
stack_malloc(&maneuvre_stacks[i]);
|
||||
stack_init(maneuvre_stacks[i]);
|
||||
}
|
||||
card_set(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
card_set(maneuvre_stacks[0]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
// TODO: fix error here
|
||||
assert(valid_move(maneuvre_stacks[i], foundation_stacks[j]));
|
||||
}
|
||||
}
|
||||
@ -371,18 +366,17 @@ void test_valid_move_from_maneuvre_stack_to_maneuvre_stacks() {
|
||||
stack_init(maneuvre_stacks[i]);
|
||||
}
|
||||
card_set(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, TWO, HEARTS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, THREE, CLUBS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, FOUR, DIAMONDS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, FIVE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, SIX, DIAMONDS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, SEVEN, CLUBS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
for (int j = 0; j < 7; j++) {
|
||||
if (i == j) {
|
||||
if (i + 1 != j) {
|
||||
assert(!valid_move(maneuvre_stacks[i], maneuvre_stacks[j]));
|
||||
} else {
|
||||
// TODO: fix error here
|
||||
assert(valid_move(maneuvre_stacks[i], maneuvre_stacks[j]));
|
||||
}
|
||||
}
|
||||
@ -412,6 +406,8 @@ void test_move_card_from_stack_empty_stack_to_stack_empty_stack() {
|
||||
assert(destination == new_destination);
|
||||
assert(stacks_equal(destination, destination_duplicate));
|
||||
|
||||
stack_free(origin_duplicate);
|
||||
stack_free(destination_duplicate);
|
||||
stack_free(origin);
|
||||
stack_free(destination);
|
||||
}
|
||||
@ -442,6 +438,8 @@ void test_move_card_from_stack_empty_stack_to_non_stack_empty_stack() {
|
||||
assert(destination == new_destination);
|
||||
assert(stacks_equal(destination, destination_duplicate));
|
||||
|
||||
stack_free(origin_duplicate);
|
||||
stack_free(destination_duplicate);
|
||||
stack_free(origin);
|
||||
stack_free(destination);
|
||||
}
|
||||
|
@ -30,6 +30,9 @@ void test_stack_dup() {
|
||||
|
||||
assert(stack_0 != stack_1);
|
||||
assert(stacks_equal(stack_0, stack_1));
|
||||
|
||||
stack_free(stack_0);
|
||||
stack_free(stack_1);
|
||||
}
|
||||
|
||||
void test_stack_empty_on_stack_empty_stack() {
|
||||
@ -185,6 +188,7 @@ void test_stack_pop_on_stack_with_one_element() {
|
||||
assert(stack_popped_card == card);
|
||||
|
||||
stack_free(stack);
|
||||
card_free(stack_popped_card);
|
||||
}
|
||||
|
||||
void test_stack_pop_on_stack_with_more_than_one_element() {
|
||||
@ -207,6 +211,7 @@ void test_stack_pop_on_stack_with_more_than_one_element() {
|
||||
assert(stack_popped_card == card[2]);
|
||||
|
||||
stack_free(stack);
|
||||
card_free(stack_popped_card);
|
||||
}
|
||||
|
||||
void test_stack_reverse_on_stack_empty_stack() {
|
||||
@ -220,6 +225,7 @@ void test_stack_reverse_on_stack_empty_stack() {
|
||||
assert(stacks_equal(stack_reversed_stack, old_stack));
|
||||
|
||||
stack_free(stack);
|
||||
stack_free(stack_reversed_stack);
|
||||
}
|
||||
|
||||
void test_stack_reverse_on_stack_with_one_element() {
|
||||
@ -238,6 +244,7 @@ void test_stack_reverse_on_stack_with_one_element() {
|
||||
|
||||
assert(stacks_equal(stack_reversed_stack, old_stack));
|
||||
|
||||
stack_free(stack_reversed_stack);
|
||||
stack_free(stack);
|
||||
}
|
||||
|
||||
@ -264,12 +271,14 @@ void test_stack_reverse_on_stack_with_more_than_one_element() {
|
||||
|
||||
assert(stacks_equal(unstack_reversed_stack, old_stack));
|
||||
|
||||
stack_free(unstack_reversed_stack);
|
||||
stack_free(stack_reversed_stack);
|
||||
stack_free(old_stack);
|
||||
stack_free(stack);
|
||||
}
|
||||
|
||||
void test_stack_reverse_should_not_change_stack() {
|
||||
struct stack *stack, *old_stack, *old_stack_address;
|
||||
struct stack *stack, *stack_reversed_stack_0, *stack_reversed_stack_1;
|
||||
struct card *card[3];
|
||||
|
||||
stack_malloc(&stack);
|
||||
@ -280,13 +289,14 @@ void test_stack_reverse_should_not_change_stack() {
|
||||
card_set(card[i], TWO + i, DIAMONDS + i, EXPOSED, 0, 0);
|
||||
stack_push(&stack, card[i]);
|
||||
}
|
||||
old_stack_address = stack;
|
||||
old_stack = stack_dup(stack);
|
||||
stack_reverse(stack);
|
||||
stack_reversed_stack_0 = stack_reverse(stack);
|
||||
stack_reversed_stack_1 = stack_reverse(stack_reversed_stack_0);
|
||||
|
||||
assert(stack == old_stack_address);
|
||||
assert(stacks_equal(stack, old_stack));
|
||||
assert(!stacks_equal(stack, stack_reversed_stack_0));
|
||||
assert(stacks_equal(stack, stack_reversed_stack_1));
|
||||
|
||||
stack_free(stack_reversed_stack_0);
|
||||
stack_free(stack_reversed_stack_1);
|
||||
stack_free(stack);
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,8 @@ void test_frames_equal_with_one_null() {
|
||||
frame_malloc(&frame);
|
||||
assert(!frames_equal(frame, NULL));
|
||||
assert(!frames_equal(NULL, frame));
|
||||
|
||||
frame_free(frame);
|
||||
}
|
||||
|
||||
void test_frames_equal_with_two_equivalent_frames() {
|
||||
@ -23,14 +25,20 @@ void test_frames_equal_with_two_equivalent_frames() {
|
||||
frame_set(frame_1, begin_y, begin_x);
|
||||
|
||||
assert(frames_equal(frame_0, frame_1));
|
||||
|
||||
frame_free(frame_0);
|
||||
frame_free(frame_1);
|
||||
}
|
||||
|
||||
void test_frames_equal_with_two_frame_pointers_to_the_same_address() {
|
||||
struct frame *frame;
|
||||
|
||||
frame_malloc(&frame);
|
||||
frame_init(frame);
|
||||
|
||||
assert(frames_equal(frame, frame));
|
||||
|
||||
frame_free(frame);
|
||||
}
|
||||
|
||||
void test_cards_equal_with_two_nulls() {
|
||||
@ -55,14 +63,20 @@ void test_cards_equal_with_two_equivalent_cards() {
|
||||
card_set(card_1, ACE, SPADES, EXPOSED, begin_y, begin_x);
|
||||
|
||||
assert(cards_equal(card_0, card_1));
|
||||
|
||||
card_free(card_0);
|
||||
card_free(card_1);
|
||||
}
|
||||
|
||||
void test_cards_equal_with_two_card_pointers_to_the_same_address() {
|
||||
struct card *card;
|
||||
|
||||
card_malloc(&card);
|
||||
card_init(card);
|
||||
|
||||
assert(cards_equal(card, card));
|
||||
|
||||
card_free(card);
|
||||
}
|
||||
|
||||
void test_stacks_equal_with_two_nulls() {
|
||||
@ -73,8 +87,12 @@ void test_stacks_equal_with_one_null() {
|
||||
struct stack *stack;
|
||||
|
||||
stack_malloc(&stack);
|
||||
stack_init(stack);
|
||||
|
||||
assert(!stacks_equal(stack, NULL));
|
||||
assert(!stacks_equal(NULL, stack));
|
||||
|
||||
stack_free(stack);
|
||||
}
|
||||
|
||||
void test_stacks_equal_with_two_equivalent_stacks() {
|
||||
@ -88,10 +106,15 @@ void test_stacks_equal_with_two_equivalent_stacks() {
|
||||
card_set(card_1, ACE, SPADES, EXPOSED, begin_y, begin_x);
|
||||
stack_malloc(&stack_0);
|
||||
stack_malloc(&stack_1);
|
||||
stack_init(stack_0);
|
||||
stack_init(stack_1);
|
||||
stack_push(&stack_0, card_0);
|
||||
stack_push(&stack_1, card_1);
|
||||
|
||||
assert(stacks_equal(stack_0, stack_1));
|
||||
|
||||
stack_free(stack_0);
|
||||
stack_free(stack_1);
|
||||
}
|
||||
|
||||
void test_stacks_equal_with_two_different_stacks() {
|
||||
@ -105,18 +128,26 @@ void test_stacks_equal_with_two_different_stacks() {
|
||||
card_set(card_1, KING, HEARTS, EXPOSED, begin_y, begin_x);
|
||||
stack_malloc(&stack_0);
|
||||
stack_malloc(&stack_1);
|
||||
stack_init(stack_0);
|
||||
stack_init(stack_1);
|
||||
stack_push(&stack_0, card_0);
|
||||
stack_push(&stack_1, card_1);
|
||||
|
||||
assert(!stacks_equal(stack_0, stack_1));
|
||||
|
||||
stack_free(stack_0);
|
||||
stack_free(stack_1);
|
||||
}
|
||||
|
||||
void test_stacks_equal_with_two_stack_pointers_to_the_same_address() {
|
||||
struct stack *stack;
|
||||
|
||||
stack_malloc(&stack);
|
||||
stack_init(stack);
|
||||
|
||||
assert(stacks_equal(stack, stack));
|
||||
|
||||
stack_free(stack);
|
||||
}
|
||||
|
||||
void test_test_helper() {
|
||||
|
Loading…
Reference in New Issue
Block a user