test_pop überarbeitet
This commit is contained in:
parent
be37b3ff21
commit
8f4ab58000
24
test_stack.c
24
test_stack.c
@ -49,24 +49,20 @@ void test_push_and_top(void)
|
|||||||
|
|
||||||
void test_pop(void)
|
void test_pop(void)
|
||||||
{
|
{
|
||||||
StackNode *stack = NULL;
|
StackNode *stack = NULL;
|
||||||
|
|
||||||
int *x = malloc(sizeof(int)); *x = 111;
|
int x = 111;
|
||||||
int *y = malloc(sizeof(int)); *y = 222;
|
int y = 222;
|
||||||
|
|
||||||
stack = push(stack, x);
|
stack = push(stack, &x);
|
||||||
stack = push(stack, y);
|
stack = push(stack, &y);
|
||||||
|
|
||||||
void *data;
|
// pop removes y
|
||||||
|
stack = pop(stack);
|
||||||
stack = pop(stack, &data);
|
TEST_ASSERT_EQUAL_INT(111, *(int*)top(stack));
|
||||||
TEST_ASSERT_EQUAL_INT(222, *(int*)data);
|
|
||||||
free(data);
|
|
||||||
|
|
||||||
stack = pop(stack, &data);
|
|
||||||
TEST_ASSERT_EQUAL_INT(111, *(int*)data);
|
|
||||||
free(data);
|
|
||||||
|
|
||||||
|
// pop removes x
|
||||||
|
stack = pop(stack);
|
||||||
TEST_ASSERT_NULL(stack);
|
TEST_ASSERT_NULL(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user