Sat, 09 Oct 2021 11:12:48 +0200
remove cxListLast (can be realized via cxListAt and index=size-1)
390 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
29 | #include "cx/linked_list.h" |
411
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
30 | #include "test_config.h" |
422
afd87df80b13
add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
413
diff
changeset
|
31 | #include "util_allocator.h" |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
32 | |
412
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
33 | int cmp_int(int const *l, int const *r) { |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
34 | int left = *l, right = *r; |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
35 | return left == right ? 0 : (left < right ? -1 : 1); |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
36 | } |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
37 | |
438
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
38 | void test_linked_list_at(void) { |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
39 | struct node { |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
40 | void *next; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
41 | void *prev; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
42 | }; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
43 | const ptrdiff_t loc_prev = offsetof(struct node, prev); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
44 | const ptrdiff_t loc_next = offsetof(struct node, next); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
45 | |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
46 | struct node a, b, c, d; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
47 | a.prev = NULL; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
48 | a.next = &b; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
49 | b.prev = &a; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
50 | b.next = &c; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
51 | c.prev = &b; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
52 | c.next = &d; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
53 | d.prev = &c; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
54 | d.next = NULL; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
55 | |
449 | 56 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 0), &a) |
57 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 1), &b) | |
58 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 2), &c) | |
59 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 3), &d) | |
60 | CU_ASSERT_PTR_NULL(cx_linked_list_at(&a, 0, loc_next, 4)) | |
438
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
61 | |
449 | 62 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_prev, 0), &a) |
63 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 1), &b) | |
64 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 2), &c) | |
65 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 3), &d) | |
66 | CU_ASSERT_PTR_NULL(cx_linked_list_at(&b, 1, loc_next, 4)) | |
438
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
67 | |
449 | 68 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 0), &a) |
69 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 1), &b) | |
438
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
70 | } |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
71 | |
444
cb944fa1852a
rename test_cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
72 | void test_linked_list_add(void) { |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
73 | struct node { |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
74 | void *prev; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
75 | void *next; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
76 | }; |
449 | 77 | |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
78 | struct node nodes[4]; |
449 | 79 | |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
80 | // test with begin, end / prev, next |
449 | 81 | memset(nodes, 0, 4 * sizeof(struct node)); |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
82 | void *begin = NULL; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
83 | void *end = NULL; |
449 | 84 | |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
85 | ptrdiff_t loc_prev = offsetof(struct node, prev); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
86 | ptrdiff_t loc_next = offsetof(struct node, next); |
449 | 87 | |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
88 | cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[0]); |
449 | 89 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
90 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]) | |
91 | CU_ASSERT_PTR_EQUAL(nodes[0].prev, NULL) | |
92 | CU_ASSERT_PTR_EQUAL(nodes[0].next, NULL) | |
93 | ||
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
94 | cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[1]); |
449 | 95 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
96 | CU_ASSERT_PTR_EQUAL(end, &nodes[1]) | |
97 | CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) | |
98 | CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]) | |
99 | ||
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
100 | // test with begin only / prev, next |
449 | 101 | memset(nodes, 0, 4 * sizeof(struct node)); |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
102 | begin = NULL; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
103 | end = NULL; |
449 | 104 | |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
105 | cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[0]); |
449 | 106 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
107 | cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[1]); |
449 | 108 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
109 | CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) | |
110 | CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]) | |
111 | ||
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
112 | cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[2]); |
449 | 113 | CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2]) |
114 | CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1]) | |
115 | ||
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
116 | // test with begin, end / next |
449 | 117 | memset(nodes, 0, 4 * sizeof(struct node)); |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
118 | begin = NULL; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
119 | end = NULL; |
449 | 120 | |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
121 | cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[0]); |
449 | 122 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
123 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]) | |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
124 | cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[1]); |
449 | 125 | CU_ASSERT_PTR_EQUAL(end, &nodes[1]) |
126 | CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) | |
127 | CU_ASSERT_PTR_NULL(nodes[1].prev) | |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
128 | } |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
129 | |
456
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
130 | void test_linked_list_last(void) { |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
131 | CU_ASSERT_PTR_NULL(cx_linked_list_last(NULL, 0)) |
455 | 132 | |
456
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
133 | struct node { |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
134 | int data; |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
135 | void *next; |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
136 | }; |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
137 | ptrdiff_t loc = offsetof(struct node, next); |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
138 | |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
139 | struct node third = {3, NULL}; |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
140 | struct node second = {2, &third}; |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
141 | struct node first = {1, &second}; |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
142 | |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
143 | CU_ASSERT_PTR_EQUAL(cx_linked_list_last(&first, loc), &third) |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
144 | CU_ASSERT_PTR_EQUAL(cx_linked_list_last(&second, loc), &third) |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
145 | CU_ASSERT_PTR_EQUAL(cx_linked_list_last(&third, loc), &third) |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
146 | } |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
147 | |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
148 | void test_linked_list_prev(void) { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
149 | struct node { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
150 | void *next; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
151 | }; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
152 | ptrdiff_t loc = offsetof(struct node, next); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
153 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
154 | struct node third = {NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
155 | struct node second = {&third}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
156 | struct node first = {&second}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
157 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
158 | CU_ASSERT_PTR_NULL(cx_linked_list_prev(&first, loc, &first)) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
159 | CU_ASSERT_PTR_EQUAL(cx_linked_list_prev(&first, loc, &second), &first) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
160 | CU_ASSERT_PTR_EQUAL(cx_linked_list_prev(&first, loc, &third), &second) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
161 | } |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
162 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
163 | void test_linked_list_remove(void) { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
164 | struct node { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
165 | void *next; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
166 | }; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
167 | struct dnode { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
168 | void *next; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
169 | void *prev; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
170 | }; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
171 | ptrdiff_t loc = offsetof(struct node, next); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
172 | ptrdiff_t ploc = offsetof(struct dnode, prev); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
173 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
174 | void *begin; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
175 | void *end; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
176 | void *result; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
177 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
178 | // single linked list |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
179 | struct node third = {NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
180 | struct node second = {&third}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
181 | struct node first = {&second}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
182 | begin = &first; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
183 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
184 | result = cx_linked_list_remove(&begin, NULL, -1, loc, &second); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
185 | CU_ASSERT_PTR_EQUAL(result, &first) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
186 | CU_ASSERT_PTR_EQUAL(begin, &first) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
187 | CU_ASSERT_PTR_EQUAL(first.next, &third) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
188 | CU_ASSERT_PTR_NULL(second.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
189 | CU_ASSERT_PTR_NULL(third.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
190 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
191 | result = cx_linked_list_remove(&begin, NULL, -1, loc, &first); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
192 | CU_ASSERT_PTR_EQUAL(result, &third) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
193 | CU_ASSERT_PTR_EQUAL(begin, &third) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
194 | CU_ASSERT_PTR_NULL(first.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
195 | CU_ASSERT_PTR_NULL(third.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
196 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
197 | result = cx_linked_list_remove(&begin, NULL, -1, loc, &third); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
198 | CU_ASSERT_PTR_NULL(result) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
199 | CU_ASSERT_PTR_NULL(begin) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
200 | CU_ASSERT_PTR_NULL(third.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
201 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
202 | // doubly linked list |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
203 | struct dnode dthird = {NULL , NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
204 | struct dnode dsecond = {&dthird, NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
205 | struct dnode dfirst = {&dsecond, NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
206 | dthird.prev = &dsecond; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
207 | dsecond.prev = &dfirst; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
208 | begin = &dfirst; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
209 | end = &dthird; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
210 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
211 | result = cx_linked_list_remove(&begin, &end, ploc, loc, &dsecond); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
212 | CU_ASSERT_PTR_EQUAL(result, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
213 | CU_ASSERT_PTR_EQUAL(begin, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
214 | CU_ASSERT_PTR_EQUAL(end, &dthird) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
215 | CU_ASSERT_PTR_NULL(dfirst.prev) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
216 | CU_ASSERT_PTR_EQUAL(dfirst.next, &dthird) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
217 | CU_ASSERT_PTR_NULL(dsecond.prev) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
218 | CU_ASSERT_PTR_NULL(dsecond.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
219 | CU_ASSERT_PTR_EQUAL(dthird.prev, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
220 | CU_ASSERT_PTR_NULL(dthird.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
221 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
222 | result = cx_linked_list_remove(&begin, &end, ploc, loc, &dthird); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
223 | CU_ASSERT_PTR_EQUAL(result, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
224 | CU_ASSERT_PTR_EQUAL(begin, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
225 | CU_ASSERT_PTR_EQUAL(end, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
226 | CU_ASSERT_PTR_NULL(dfirst.prev) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
227 | CU_ASSERT_PTR_NULL(dfirst.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
228 | CU_ASSERT_PTR_NULL(dthird.prev) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
229 | CU_ASSERT_PTR_NULL(dthird.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
230 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
231 | result = cx_linked_list_remove(&begin, &end, ploc, loc, &dfirst); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
232 | CU_ASSERT_PTR_NULL(result) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
233 | CU_ASSERT_PTR_NULL(begin) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
234 | CU_ASSERT_PTR_NULL(end) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
235 | CU_ASSERT_PTR_NULL(dfirst.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
236 | CU_ASSERT_PTR_NULL(dfirst.prev) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
237 | } |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
238 | |
468
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
239 | void test_linked_list_size(void) { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
240 | struct node { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
241 | void *next; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
242 | }; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
243 | ptrdiff_t loc = offsetof(struct node, next); |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
244 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
245 | struct node first = {NULL}; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
246 | struct node second = {NULL}; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
247 | struct node third = {NULL}; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
248 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
249 | CU_ASSERT_PTR_EQUAL(cx_linked_list_size(NULL, loc), 0) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
250 | CU_ASSERT_PTR_EQUAL(cx_linked_list_size(&first, loc), 1) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
251 | first.next = &second; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
252 | CU_ASSERT_PTR_EQUAL(cx_linked_list_size(&first, loc), 2) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
253 | second.next = &third; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
254 | CU_ASSERT_PTR_EQUAL(cx_linked_list_size(&first, loc), 3) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
255 | CU_ASSERT_PTR_EQUAL(cx_linked_list_size(&second, loc), 2) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
256 | } |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
257 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
258 | void test_linked_list_sort(void) { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
259 | struct node { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
260 | void *prev; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
261 | void *next; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
262 | int data; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
263 | }; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
264 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
265 | int expected[] = { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
266 | 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
267 | 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
268 | 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
269 | 2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
270 | 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
271 | 4785, 4791, 4801, 4859, 4903, 4973 |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
272 | }; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
273 | int scrambled[] = { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
274 | 759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
275 | 2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
276 | 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
277 | 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
278 | 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
279 | 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681 |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
280 | }; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
281 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
282 | struct node *nodes = calloc(100, sizeof(struct node)); |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
283 | for (int i = 0; i < 100; i++) { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
284 | nodes[i].prev = i == 0 ? NULL : &nodes[i - 1]; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
285 | nodes[i].next = i == 99 ? NULL : &nodes[i + 1]; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
286 | nodes[i].data = scrambled[i]; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
287 | } |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
288 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
289 | struct node *begin = &nodes[0]; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
290 | struct node *end = &nodes[99]; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
291 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
292 | cx_linked_list_sort((void **) &begin, (void **) &end, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
293 | offsetof(struct node, prev), |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
294 | offsetof(struct node, next), |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
295 | offsetof(struct node, data), |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
296 | 0, (CxListComparator) cmp_int); |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
297 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
298 | CU_ASSERT_PTR_NULL(begin->prev) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
299 | CU_ASSERT_EQUAL(begin->data, expected[0]) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
300 | struct node *check = begin; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
301 | struct node *check_last = NULL; |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
302 | for (int i = 0; i < 100; i++) { |
468
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
303 | CU_ASSERT_EQUAL(check->data, expected[i]) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
304 | CU_ASSERT_PTR_EQUAL(check->prev, check_last) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
305 | if (i < 99) { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
306 | CU_ASSERT_PTR_NOT_NULL(check->next) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
307 | } |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
308 | check_last = check; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
309 | check = check->next; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
310 | } |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
311 | CU_ASSERT_PTR_NULL(check) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
312 | CU_ASSERT_EQUAL(end->data, expected[99]) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
313 | } |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
314 | |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
315 | void test_linked_list_reverse(void) { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
316 | struct node { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
317 | void *next; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
318 | }; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
319 | struct dnode { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
320 | void *next; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
321 | void *prev; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
322 | }; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
323 | ptrdiff_t loc = offsetof(struct node, next); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
324 | ptrdiff_t ploc = offsetof(struct dnode, prev); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
325 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
326 | void *begin; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
327 | void *end; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
328 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
329 | // single linked list |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
330 | struct node third = {NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
331 | struct node second = {&third}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
332 | struct node first = {&second}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
333 | begin = &first; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
334 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
335 | cx_linked_list_reverse(&begin, NULL, -1, loc); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
336 | CU_ASSERT_PTR_EQUAL(begin, &third) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
337 | CU_ASSERT_PTR_EQUAL(third.next, &second) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
338 | CU_ASSERT_PTR_EQUAL(second.next, &first) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
339 | CU_ASSERT_PTR_NULL(first.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
340 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
341 | // doubly linked list |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
342 | struct dnode dthird = {NULL , NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
343 | struct dnode dsecond = {&dthird, NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
344 | struct dnode dfirst = {&dsecond, NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
345 | dthird.prev = &dsecond; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
346 | dsecond.prev = &dfirst; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
347 | begin = &dfirst; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
348 | end = &dthird; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
349 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
350 | cx_linked_list_reverse(&begin, &end, ploc, loc); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
351 | CU_ASSERT_PTR_EQUAL(begin, &dthird) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
352 | CU_ASSERT_PTR_EQUAL(end, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
353 | CU_ASSERT_PTR_EQUAL(dthird.next, &dsecond) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
354 | CU_ASSERT_PTR_EQUAL(dsecond.next, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
355 | CU_ASSERT_PTR_NULL(dfirst.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
356 | CU_ASSERT_PTR_NULL(dthird.prev) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
357 | CU_ASSERT_PTR_EQUAL(dsecond.prev, &dthird) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
358 | CU_ASSERT_PTR_EQUAL(dfirst.prev, &dsecond) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
359 | } |
456
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
360 | |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
361 | void test_hl_linked_list_create(void) { |
455 | 362 | cxTestingAllocatorReset(); |
363 | ||
364 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); | |
365 | ||
366 | CU_ASSERT_EQUAL(list->size, 0) | |
367 | CU_ASSERT_EQUAL(list->capacity, (size_t) -1) | |
368 | CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator) | |
369 | CU_ASSERT_EQUAL(list->itemsize, sizeof(int)) | |
370 | CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int) | |
371 | ||
372 | cxLinkedListDestroy(list); | |
373 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) | |
374 | } | |
375 | ||
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
376 | void test_hl_linked_list_add(void) { |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
377 | cxTestingAllocatorReset(); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
378 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
379 | int data; |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
380 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
381 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
382 | data = 5; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
383 | CU_ASSERT_EQUAL(cxListAdd(list, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
384 | data = 47; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
385 | CU_ASSERT_EQUAL(cxListAdd(list, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
386 | data = 13; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
387 | CU_ASSERT_EQUAL(cxListAdd(list, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
388 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
389 | CU_ASSERT_EQUAL(list->size, 3) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
390 | CU_ASSERT_TRUE(list->capacity >= list->size) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
391 | |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
392 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
393 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
394 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
395 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
396 | cxLinkedListDestroy(list); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
397 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
398 | } |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
399 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
400 | void test_hl_linked_list_insert(void) { |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
401 | cxTestingAllocatorReset(); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
402 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
403 | int data; |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
404 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
405 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
406 | data = 5; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
407 | CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
408 | CU_ASSERT_EQUAL(list->size, 0) |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
409 | CU_ASSERT_EQUAL(cxListInsert(list, 0, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
410 | CU_ASSERT_EQUAL(list->size, 1) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
411 | data = 47; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
412 | CU_ASSERT_EQUAL(cxListInsert(list, 0, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
413 | CU_ASSERT_EQUAL(list->size, 2) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
414 | data = 13; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
415 | CU_ASSERT_EQUAL(cxListInsert(list, 1, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
416 | CU_ASSERT_EQUAL(list->size, 3) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
417 | data = 42; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
418 | CU_ASSERT_EQUAL(cxListInsert(list, 3, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
419 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
420 | CU_ASSERT_EQUAL(list->size, 4) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
421 | CU_ASSERT_TRUE(list->capacity >= list->size) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
422 | |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
423 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
424 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
425 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 5) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
426 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 42) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
427 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
428 | cxLinkedListDestroy(list); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
429 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
430 | } |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
431 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
432 | void test_hl_linked_list_remove(void) { |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
433 | cxTestingAllocatorReset(); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
434 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
435 | int data; |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
436 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
437 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
438 | data = 5; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
439 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
440 | data = 47; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
441 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
442 | data = 42; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
443 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
444 | data = 13; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
445 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
446 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
447 | CU_ASSERT_EQUAL(list->size, 4) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
448 | CU_ASSERT_TRUE(list->capacity >= list->size) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
449 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
450 | CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
451 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
452 | CU_ASSERT_EQUAL(cxListRemove(list, 2), 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
453 | CU_ASSERT_EQUAL(list->size, 3) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
454 | CU_ASSERT_TRUE(list->capacity >= list->size) |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
455 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
456 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
457 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
458 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
459 | CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
460 | CU_ASSERT_EQUAL(list->size, 2) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
461 | CU_ASSERT_TRUE(list->capacity >= list->size) |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
462 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
463 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
464 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
465 | CU_ASSERT_EQUAL(cxListRemove(list, 1), 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
466 | CU_ASSERT_EQUAL(list->size, 1) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
467 | CU_ASSERT_TRUE(list->capacity >= list->size) |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
468 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
469 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
470 | CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
471 | CU_ASSERT_EQUAL(list->size, 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
472 | CU_ASSERT_TRUE(list->capacity >= list->size) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
473 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
474 | CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
475 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
476 | cxLinkedListDestroy(list); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
477 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
478 | } |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
479 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
480 | void test_hl_linked_list_find(void) { |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
481 | cxTestingAllocatorReset(); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
482 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
483 | int data, criteria; |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
484 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
485 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
486 | data = 5; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
487 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
488 | data = 47; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
489 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
490 | data = 13; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
491 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
492 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
493 | CU_ASSERT_EQUAL(list->size, 3) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
494 | CU_ASSERT_TRUE(list->capacity >= list->size) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
495 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
496 | criteria = 5; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
497 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
498 | criteria = 47; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
499 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
500 | criteria = 13; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
501 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
502 | criteria = 9000; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
503 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
504 | criteria = -5; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
505 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
506 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
507 | cxLinkedListDestroy(list); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
508 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
509 | } |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
510 | |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
511 | void test_hl_linked_list_sort(void) { |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
512 | int expected[] = { |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
513 | 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
514 | 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
515 | 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
516 | 2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
517 | 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
518 | 4785, 4791, 4801, 4859, 4903, 4973 |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
519 | }; |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
520 | int scrambled[] = { |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
521 | 759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
522 | 2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
523 | 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
524 | 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
525 | 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
526 | 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681 |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
527 | }; |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
528 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
529 | cxTestingAllocatorReset(); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
530 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
531 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
532 | |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
533 | for (int i = 0; i < 100; i++) { |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
534 | cxListAdd(list, &scrambled[i]); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
535 | } |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
536 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
537 | cxListSort(list); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
538 | |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
539 | for (int i = 0; i < 100; i++) { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
540 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, i), expected[i]) |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
541 | } |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
542 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
543 | cxLinkedListDestroy(list); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
544 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
545 | } |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
546 | |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
547 | void test_hl_ptr_linked_list_create(void) { |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
548 | cxTestingAllocatorReset(); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
549 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
550 | CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
551 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
552 | CU_ASSERT_EQUAL(list->size, 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
553 | CU_ASSERT_EQUAL(list->capacity, (size_t) -1) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
554 | CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
555 | CU_ASSERT_EQUAL(list->itemsize, sizeof(void *)) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
556 | CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
557 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
558 | cxLinkedListDestroy(list); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
559 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
560 | } |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
561 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
562 | void test_hl_ptr_linked_list_add(void) { |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
563 | cxTestingAllocatorReset(); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
564 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
565 | CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
566 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
567 | int a = 5, b = 47, c = 13; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
568 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
569 | CU_ASSERT_EQUAL(cxListAdd(list, &a), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
570 | CU_ASSERT_EQUAL(cxListAdd(list, &b), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
571 | CU_ASSERT_EQUAL(cxListAdd(list, &c), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
572 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
573 | CU_ASSERT_EQUAL(list->size, 3) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
574 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
575 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
576 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
577 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
578 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
579 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
580 | a = 9; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
581 | b = 10; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
582 | c = 11; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
583 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
584 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 9) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
585 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 10) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
586 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 11) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
587 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
588 | cxLinkedListDestroy(list); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
589 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
590 | } |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
591 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
592 | void test_hl_ptr_linked_list_insert(void) { |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
593 | cxTestingAllocatorReset(); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
594 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
595 | CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
596 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
597 | int a = 5, b = 47, c = 13, d = 42; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
598 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
599 | CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &a), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
600 | CU_ASSERT_EQUAL(list->size, 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
601 | CU_ASSERT_EQUAL(cxListInsert(list, 0, &a), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
602 | CU_ASSERT_EQUAL(list->size, 1) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
603 | CU_ASSERT_EQUAL(cxListInsert(list, 0, &b), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
604 | CU_ASSERT_EQUAL(list->size, 2) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
605 | CU_ASSERT_EQUAL(cxListInsert(list, 1, &c), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
606 | CU_ASSERT_EQUAL(list->size, 3) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
607 | CU_ASSERT_EQUAL(cxListInsert(list, 3, &d), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
608 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
609 | CU_ASSERT_EQUAL(list->size, 4) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
610 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
611 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
612 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
613 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
614 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 5) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
615 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 42) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
616 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
617 | cxLinkedListDestroy(list); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
618 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
619 | } |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
620 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
621 | void test_hl_ptr_linked_list_remove(void) { |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
622 | cxTestingAllocatorReset(); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
623 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
624 | int a = 5, b = 47, c = 42, d = 13; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
625 | CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
626 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
627 | cxListAdd(list, &a); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
628 | cxListAdd(list, &b); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
629 | cxListAdd(list, &c); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
630 | cxListAdd(list, &d); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
631 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
632 | CU_ASSERT_EQUAL(list->size, 4) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
633 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
634 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
635 | CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
636 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
637 | CU_ASSERT_EQUAL(cxListRemove(list, 2), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
638 | CU_ASSERT_EQUAL(list->size, 3) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
639 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
640 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
641 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
642 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
643 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
644 | CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
645 | CU_ASSERT_EQUAL(list->size, 2) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
646 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
647 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
648 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
649 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
650 | CU_ASSERT_EQUAL(cxListRemove(list, 1), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
651 | CU_ASSERT_EQUAL(list->size, 1) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
652 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
653 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
654 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
655 | CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
656 | CU_ASSERT_EQUAL(list->size, 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
657 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
658 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
659 | CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
660 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
661 | cxLinkedListDestroy(list); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
662 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
663 | } |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
664 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
665 | void test_hl_ptr_linked_list_find(void) { |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
666 | cxTestingAllocatorReset(); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
667 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
668 | int a = 5, b = 47, c = 13, criteria; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
669 | CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
670 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
671 | cxListAdd(list, &a); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
672 | cxListAdd(list, &b); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
673 | cxListAdd(list, &c); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
674 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
675 | CU_ASSERT_EQUAL(list->size, 3) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
676 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
677 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
678 | criteria = 5; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
679 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
680 | criteria = 47; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
681 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
682 | criteria = 13; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
683 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
684 | criteria = 9000; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
685 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
686 | criteria = -5; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
687 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
688 | b = -5; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
689 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
690 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
691 | cxLinkedListDestroy(list); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
692 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
693 | } |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
694 | |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
695 | void test_hl_ptr_linked_list_sort(void) { |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
696 | int expected[] = { |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
697 | 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
698 | 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
699 | 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
700 | 2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
701 | 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
702 | 4785, 4791, 4801, 4859, 4903, 4973 |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
703 | }; |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
704 | int scrambled[] = { |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
705 | 759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
706 | 2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
707 | 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
708 | 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
709 | 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
710 | 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681 |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
711 | }; |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
712 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
713 | cxTestingAllocatorReset(); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
714 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
715 | CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
716 | |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
717 | for (int i = 0; i < 100; i++) { |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
718 | cxListAdd(list, &scrambled[i]); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
719 | } |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
720 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
721 | cxListSort(list); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
722 | |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
723 | for (int i = 0; i < 100; i++) { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
724 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, i), expected[i]) |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
725 | } |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
726 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
727 | cxLinkedListDestroy(list); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
728 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
729 | } |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
730 | |
390 | 731 | int main() { |
411
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
732 | CU_pSuite suite = NULL; |
449 | 733 | |
411
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
734 | if (CUE_SUCCESS != CU_initialize_registry()) { |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
735 | return CU_get_error(); |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
736 | } |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
737 | |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
738 | suite = CU_add_suite("low level linked list", NULL, NULL); |
449 | 739 | |
455 | 740 | cu_add_test(suite, test_linked_list_at); |
741 | cu_add_test(suite, test_linked_list_add); | |
456
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
742 | cu_add_test(suite, test_linked_list_last); |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
743 | cu_add_test(suite, test_linked_list_prev); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
744 | cu_add_test(suite, test_linked_list_remove); |
468
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
745 | cu_add_test(suite, test_linked_list_size); |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
746 | cu_add_test(suite, test_linked_list_sort); |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
747 | cu_add_test(suite, test_linked_list_reverse); |
455 | 748 | |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
749 | suite = CU_add_suite("high level linked list", NULL, NULL); |
455 | 750 | |
456
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
751 | cu_add_test(suite, test_hl_linked_list_create); |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
752 | cu_add_test(suite, test_hl_linked_list_add); |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
753 | cu_add_test(suite, test_hl_linked_list_insert); |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
754 | cu_add_test(suite, test_hl_linked_list_remove); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
755 | cu_add_test(suite, test_hl_linked_list_find); |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
756 | cu_add_test(suite, test_hl_linked_list_sort); |
413
0f4aa9fc75d9
perform array and list tests in the same test binary (use the same assertions, later)
Mike Becker <universe@uap-core.de>
parents:
412
diff
changeset
|
757 | |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
758 | suite = CU_add_suite("high level pointer linked list", NULL, NULL); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
759 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
760 | cu_add_test(suite, test_hl_ptr_linked_list_create); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
761 | cu_add_test(suite, test_hl_ptr_linked_list_add); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
762 | cu_add_test(suite, test_hl_ptr_linked_list_insert); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
763 | cu_add_test(suite, test_hl_ptr_linked_list_remove); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
764 | cu_add_test(suite, test_hl_ptr_linked_list_find); |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
765 | cu_add_test(suite, test_hl_ptr_linked_list_sort); |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
766 | |
411
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
767 | CU_basic_set_mode(UCX_CU_BRM); |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
768 | |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
769 | int exitcode; |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
770 | if (CU_basic_run_tests()) { |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
771 | exitcode = CU_get_error(); |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
772 | } else { |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
773 | exitcode = CU_get_number_of_failures() == 0 ? 0 : 1; |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
774 | } |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
775 | CU_cleanup_registry(); |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
776 | return exitcode; |
390 | 777 | } |