fix atan2,rename {hypot,hypot3} to {norm2,norm3}
[liba.git] / test / slist.h
blob6c0d02d5ff00a3effbadcfd61eb1ef76ab816eff
1 #define MAIN(x) slist##x
2 #include "test.h"
3 #include "a/slist.h"
5 static a_size a_slist_len(a_slist const *ctx)
7 a_size count = 0;
8 a_slist_node *it;
9 A_SLIST_FOREACH(it, ctx) { ++count; }
10 return count;
13 static void test(void)
15 typedef struct
17 a_slist_node node;
18 a_cast data;
19 } data;
20 int i;
21 a_slist_node *it, *at;
22 a_slist *list1, *list2, *list3;
23 list1 = a_new(a_slist, A_NULL, 1);
24 a_slist_ctor(list1);
25 for (i = 0; i != 10; ++i)
27 data *node = a_new(data, A_NULL, 1);
28 node->data.i = i;
29 a_slist_add_tail(list1, &node->node);
31 list2 = a_new(a_slist, A_NULL, 1);
32 a_slist_ctor(list2);
33 for (i = 14; i != 9; --i)
35 data *node = a_new(data, A_NULL, 1);
36 node->data.i = i;
37 a_slist_add_head(list2, &node->node);
39 list3 = a_new(a_slist, A_NULL, 1);
40 a_slist_ctor(list3);
41 for (i = 15; i != 20; ++i)
43 data *node = a_new(data, A_NULL, 1);
44 node->data.i = i;
45 a_slist_add(list3, list3->tail, &node->node);
47 a_slist_rot(list1);
48 a_slist_mov(list2, list3, &list3->head);
49 a_slist_dtor(list2);
50 a_slist_mov(list3, list1, list1->tail);
51 a_slist_dtor(list3);
52 A_SLIST_FOREACH(it, list1)
54 data *node = a_slist_entry(it, data, node); /* NOLINT(performance-no-int-to-ptr) */
55 printf("%i ", node->data.i);
57 printf("%" A_PRIz "u", a_slist_len(list1));
58 for (i = 0; i != 10; ++i)
60 data *node = a_slist_entry_next(&list1->head, data, node); /* NOLINT(performance-no-int-to-ptr) */
61 a_slist_del_head(list1);
62 a_die(node);
64 A_SLIST_FORSAFE(it, at, list1)
66 data *node = a_slist_entry(it, data, node); /* NOLINT(performance-no-int-to-ptr) */
67 a_slist_del(list1, at);
68 a_die(node);
69 it = A_NULL;
71 if (list1->head.next == &list1->head &&
72 list2->head.next == &list2->head &&
73 list3->head.next == &list3->head)
75 printf(" ok");
77 (void)putchar('\n');
78 a_die(list3);
79 a_die(list2);
80 a_die(list1);
83 static void null(void)
85 static a_slist_node node1 = A_SLIST_NODE;
86 static a_slist_node node2 = A_SLIST_NODE;
87 static a_slist list1 = A_SLIST_INIT(list1);
88 static a_slist list2 = A_SLIST_INIT(list2);
90 a_slist_rot(&list1);
91 a_slist_rot(&list1);
92 a_slist_mov(&list2, &list1, &list1.head);
93 a_slist_mov(&list2, &list1, list1.tail);
94 a_slist_del(&list1, &list1.head);
95 a_slist_del(&list1, list1.tail);
96 a_slist_del_head(&list2);
97 a_slist_del_head(&list2);
99 a_slist_init(&list1);
100 a_slist_init(&list2);
101 a_slist_add(&list1, &list1.head, &node1);
102 a_slist_add(&list1, &list1.head, &node1);
103 a_slist_del(&list1, &node1);
104 a_slist_add(&list1, list1.tail, &node1);
105 a_slist_add(&list1, &node1, &node1);
106 a_slist_add_head(&list1, &node1);
107 a_slist_add_tail(&list2, &node2);
108 a_slist_mov(&list2, &list1, &list1.head);
109 a_slist_mov(&list2, &list1, list1.tail);
112 int main(int argc, char *argv[]) /* NOLINT(misc-definitions-in-headers) */
114 puts(A_FUNC);
115 test();
116 null();
117 (void)argc;
118 (void)argv;
119 return 0;