64 lines
1.4 KiB
C
64 lines
1.4 KiB
C
#include "unity.h"
|
|
#include "stack.h"
|
|
|
|
int data1 = 10;
|
|
int data2 = 20;
|
|
int data3 = 30;
|
|
|
|
StackNode *stack = NULL;
|
|
|
|
void setUp(void)
|
|
{
|
|
// set stuff up here
|
|
}
|
|
|
|
void tearDown(void)
|
|
{
|
|
clearStack(stack);
|
|
stack = NULL;
|
|
}
|
|
|
|
void test_push_and_pop(void)
|
|
{
|
|
stack = push(stack, &data1);
|
|
stack = push(stack, &data2);
|
|
stack = push(stack, &data3);
|
|
|
|
TEST_ASSERT_EQUAL_PTR(top(stack), &data3);
|
|
stack = pop(stack);
|
|
TEST_ASSERT_EQUAL_PTR(top(stack), &data2);
|
|
stack = pop(stack);
|
|
TEST_ASSERT_EQUAL_PTR(top(stack), &data1);
|
|
stack = pop(stack);
|
|
}
|
|
|
|
// pop and top should return NULL if called with NULL ptr
|
|
void test_handle_NULL(void)
|
|
{
|
|
TEST_ASSERT_NULL(pop(stack));
|
|
TEST_ASSERT_NULL(top(stack));
|
|
}
|
|
|
|
void test_top(void)
|
|
{
|
|
TEST_ASSERT_NULL(top(stack));
|
|
stack = push(stack, &data1);
|
|
TEST_ASSERT_EQUAL_PTR(top(stack), &data1);
|
|
TEST_ASSERT_EQUAL_INT(*(int *)top(stack), data1);
|
|
stack = push(stack, &data2);
|
|
TEST_ASSERT_EQUAL_PTR(top(stack), &data2);
|
|
TEST_ASSERT_EQUAL_INT(*(int *)top(stack), data2);
|
|
stack = push(stack, &data3);
|
|
TEST_ASSERT_EQUAL_PTR(top(stack), &data3);
|
|
TEST_ASSERT_EQUAL_INT(*(int *)top(stack), data3);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
printf("============================\nStack tests\n============================\n");
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_push_and_pop);
|
|
RUN_TEST(test_handle_NULL);
|
|
RUN_TEST(test_top);
|
|
return UNITY_END();
|
|
} |