-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_test.c
40 lines (36 loc) · 979 Bytes
/
list_test.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
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include "list.h"
int comparer(const void *a, const void *b) {
return (int)a - (int)b;
}
int main(int argc, char const* argv[])
{
List *l = List_new(comparer);
ListIterator *iter;
srand(393939);
printf("empty? %s\n", (List_is_empty(l) ? "yes" : "no"));
for (int i = 0; i < 10; ++i) {
List_add(l, (void *)((unsigned long)rand()));
}
printf("size: %lu\n", List_size(l));
printf("empty? %s\n", (List_is_empty(l) ? "yes" : "no"));
printf("-----\n");
iter = List_iterator(l);
while (ListIter_move_next(iter)) {
printf("%d\n", (int)ListIter_current(iter));
}
ListIter_delete(iter);
List_remove_at(l, 5);
printf("size: %lu\n", List_size(l));
printf("-----\n");
iter = List_iterator(l);
while (ListIter_move_next(iter)) {
printf("%d\n", (int)ListIter_current(iter));
}
ListIter_delete(iter);
printf("-----\n");
printf("%d\n", (int)List_get_at(l, 3));
return 0;
}