mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-05-17 19:41:36 +08:00
queue测试案例
This commit is contained in:
parent
96ce81bd90
commit
fd2e8b5619
@ -233,9 +233,95 @@ static void queue_test_num(void)
|
||||
queue.destory(&queue);
|
||||
}
|
||||
|
||||
|
||||
static void queue_test_char(void)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
char data[] = "abcdefghijk";
|
||||
char temp = 0;
|
||||
uint32_t len = sizeof(data) / sizeof(data[0]);
|
||||
|
||||
struct _queue queue;
|
||||
queue2_init(&queue, sizeof(char), 64);
|
||||
queue.print_obj = print_char;
|
||||
|
||||
printf("\n\n----- queue_test_char -----\n");
|
||||
|
||||
printf("----- after push-----\n");
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
queue.push(&queue, &data[i]);
|
||||
|
||||
queue.front(&queue, &temp);
|
||||
printf("front = ");
|
||||
queue.print_obj(&temp);
|
||||
|
||||
queue.back(&queue, &temp);
|
||||
printf("\tback = ");
|
||||
queue.print_obj(&temp);
|
||||
|
||||
printf("\tsize = %2d\n", queue.size(&queue));
|
||||
}
|
||||
printf("----- print -----\n");
|
||||
queue.print(&queue);
|
||||
printf("\n");
|
||||
|
||||
queue.clear(&queue);
|
||||
if (queue.empty(&queue))
|
||||
{
|
||||
printf("----- empty -----\n");
|
||||
}
|
||||
|
||||
printf("----- push -----\n");
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
queue.push(&queue, &data[i]);
|
||||
}
|
||||
|
||||
printf("----- after pop -----\n");
|
||||
for (i = 0; i < len + 1; i++)
|
||||
{
|
||||
if (true == queue.pop(&queue, &temp))
|
||||
{
|
||||
printf("pop = ");
|
||||
queue.print_obj(&temp);
|
||||
|
||||
if (true == queue.front(&queue, &temp))
|
||||
{
|
||||
printf("front = ");
|
||||
queue.print_obj(&temp);
|
||||
}
|
||||
|
||||
if (queue.back(&queue, &temp))
|
||||
{
|
||||
printf("back = ");
|
||||
queue.print_obj(&temp);
|
||||
}
|
||||
|
||||
printf("size = %2d\n", queue.size(&queue));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("pop failed! because it is empty\n");
|
||||
}
|
||||
|
||||
if (queue.empty(&queue))
|
||||
{
|
||||
printf("----- empty -----\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("----- print -----\n");
|
||||
queue.print(&queue);
|
||||
printf("\n");
|
||||
|
||||
queue.destory(&queue);
|
||||
}
|
||||
|
||||
void queue_test(void)
|
||||
{
|
||||
queue_test_num();
|
||||
// queue_test_num();
|
||||
queue_test_char();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user