common:list: add test program
[avr_work.git] / common / test_list.c
blob9f9d0125c139b3c5eec20166b1ba7aee2c062a59
1 /*
2 Used to test the list implimention.
3 compile with:
4 gcc --std=gnu99 list.c test_list.c -o test_list
5 */
7 #include <stdio.h>
8 #include "list.h"
10 uint8_t buff[10];
11 list_t L = LIST_INITIALIZER(buff);
13 #define ITER(x) for(int i = 0; i < x->sz; i++)
15 void list_print(list_t *l) {
16 printf("\n{-\n\t");
17 ITER(l) {
18 printf("%d\t",i);
20 printf("\n\t");
22 ITER(l) {
23 printf("%d\t", l->buffer[i]);
25 printf("\n\t");
28 int list_i = 0;
29 int buff_i = l->first;
30 for( ; list_i < l-> ct; (list_i++, buff_i++) ) {
31 if (buff_i >= l->sz)
32 buff_i = 0;
33 printf("^\t");
35 printf("\n\t");
38 ITER(l) {
39 bool fst = i==l->first;
40 bool end = i==l->end;
41 if (fst && end)
42 printf("fe");
43 else if (fst)
44 printf("f");
45 else if (end)
46 printf("e");
47 else
48 printf(" ");
49 printf(" \t");
51 printf("\n");
54 printf("\n");
55 printf("\tpeek_front : %d\n", list_peek_front(&L));
56 printf("\tpeek_back : %d\n", list_peek_back(&L));
58 printf("-}\n\n");
62 int main ( int argc, char **argv ) {
63 for (int i = 0; i < 10; i++ )
64 list_push_front(&L,i);
65 list_print(&L);
66 printf(" poping: ");
67 for (int i = 0; i < 9; i++)
68 printf("%d\t",list_pop_back(&L));
69 printf("\n");
70 list_print(&L);
72 return 0;