forked from lc-soft/LCUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_linkedlist.c
48 lines (42 loc) · 995 Bytes
/
test_linkedlist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <LCUI_Build.h>
#include <LCUI/LCUI.h>
#include "test.h"
#include "libtest.h"
void test_linkedlist(void)
{
int arr[] = { 8, 4, 64, 16, 32, 1024 };
size_t i;
size_t n = sizeof(arr) / sizeof(int);
LinkedList list;
LinkedListNode *node;
LinkedList_Init(&list);
for (i = 0; i < n; ++i) {
LinkedList_Append(&list, arr + i);
}
it_i("LinkedList_Append() should work", (int)list.length, (int)n);
i = 0;
for (LinkedList_Each(node, &list)) {
if (node->data != arr + i) {
break;
}
++i;
}
it_b("LinkedList_Each() should work",
node == NULL && i == sizeof(arr) / sizeof(int), TRUE);
i = n - 1;
for (LinkedList_EachReverse(node, &list)) {
if (node->data != arr + i) {
break;
}
if (i == 0) {
i = n;
break;
}
--i;
}
it_i("LinkedList_EachReverse() should work", (int)i, (int)n);
LinkedList_Clear(&list, NULL);
it_b("LinkedList_ClearData() should work",
list.length == 0 && !list.head.next && !list.tail.prev, TRUE);
}