diff --git a/test/test_helper.c b/test/test_helper.c index 072b9c2..8681372 100644 --- a/test/test_helper.c +++ b/test/test_helper.c @@ -60,13 +60,19 @@ struct card *duplicate_card(struct card *card) { struct stack *duplicate_stack(struct stack *stack) { struct stack *iterator = stack; - struct stack *new_stack; + struct stack *tmp_stack, *new_stack; allocate_stack(&new_stack); + allocate_stack(&tmp_stack); initialize_stack(new_stack); + initialize_stack(tmp_stack); for (iterator = stack; iterator; iterator = iterator->next) { - push(&new_stack, duplicate_card(iterator->card)); + push(&tmp_stack, duplicate_card(iterator->card)); } + while (!empty(tmp_stack)) { + push(&new_stack, (pop(&tmp_stack))->card); + } + delete_stack(tmp_stack); return(new_stack); } diff --git a/test/test_helper_test.c b/test/test_helper_test.c index 3cfc02a..085f235 100644 --- a/test/test_helper_test.c +++ b/test/test_helper_test.c @@ -175,14 +175,16 @@ void test_duplicate_card() { void test_duplicate_stack() { struct stack *stack_0, *stack_1; - struct card *card; + struct card *card[5]; const int start_y = 5, start_x = 10; - allocate_card(&card); - set_card(card, ACE, SPADES, EXPOSED, start_y, start_x); allocate_stack(&stack_0); initialize_stack(stack_0); - push(&stack_0, card); + for (int i = 0; i < 5; i++) { + allocate_card(&card[i]); + set_card(card[i], i, SPADES, EXPOSED, start_y, start_x); + push(&stack_0, card[i]); + } stack_1 = duplicate_stack(stack_0); assert(stack_0 != stack_1);