test/array_tests.c

Sat, 10 Aug 2019 08:44:36 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 10 Aug 2019 08:44:36 +0200
branch
feature/array
changeset 349
05957b1d10a5
parent 344
320b962afaf9
child 350
82a88d938108
permissions
-rw-r--r--

adds a broader set of compare and distance functions

9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
103
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
3 *
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
4 * Copyright 2019 Mike Becker, Olaf Wintermann All rights reserved.
103
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
5 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
6 * Redistribution and use in source and binary forms, with or without
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
7 * modification, are permitted provided that the following conditions are met:
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
8 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
10 * notice, this list of conditions and the following disclaimer.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
11 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
14 * documentation and/or other materials provided with the distribution.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
15 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
29 #include "array_tests.h"
251
fae240d633fc changes source directory structure in preperation for autotools rollout
Mike Becker <universe@uap-core.de>
parents: 250
diff changeset
30 #include <ucx/utils.h>
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
32 UCX_TEST(test_ucx_array_free) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
33 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
34
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
35 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
36 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
37 UCX_TEST_ASSERT(array.data == NULL, "data pointer not NULL after free");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
38 UCX_TEST_ASSERT(array.size == 0, "size not zero after free");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
39 UCX_TEST_ASSERT(array.capacity == 0, "capacity not zero after free");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
40 UCX_TEST_ASSERT(array.allocator == ucx_default_allocator(),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
41 "allocator corrupted during free");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
42 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
43 }
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
44
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
45 UCX_TEST(test_ucx_array_new) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
46 UcxArray array = ucx_array_new(16, 47);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
47
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
48 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
49 UCX_TEST_ASSERT(array.data, "no memory allocated");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
50 UCX_TEST_ASSERT(array.size == 0, "size not initially zero");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
51 UCX_TEST_ASSERT(array.capacity == 16, "capacity not as requested");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
52 UCX_TEST_ASSERT(array.elemsize == 47, "element size not as requested");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
53 UCX_TEST_ASSERT(array.allocator == ucx_default_allocator(),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
54 "array not using the default allocator");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
55 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
56 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
57 }
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
58
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
59 UCX_TEST(test_ucx_array_append) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
60 UcxArray array = ucx_array_new(16, sizeof(int));
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
61 int *elements;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
62
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
63 int x = 42;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
64 ucx_array_append(&array, &x);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
65 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
66
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
67 elements = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
68 UCX_TEST_ASSERT(elements[0] == 42, "failed");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
69
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
70 x = 13;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
71 ucx_array_append(&array, &x);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
72
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
73 elements = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
74 UCX_TEST_ASSERT(array.size == 2, "incorrect size after append");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
75 UCX_TEST_ASSERT(elements[1] == 13, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
76 UCX_TEST_ASSERT(elements[0] == 42,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
77 "append corrupted previously inserted data");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
78
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
79 ucx_array_append(&array, NULL);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
80
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
81 elements = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
82 UCX_TEST_ASSERT(array.size == 3, "incorrect size after NULL append");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
83 UCX_TEST_ASSERT(elements[2] == 0, "element is not zeroed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
84 UCX_TEST_ASSERT(elements[0] == 42,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
85 "NULL append corrupted previously inserted data");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
86 UCX_TEST_ASSERT(elements[1] == 13,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
87 "NULL append corrupted previously inserted data");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
88
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
89 UCX_TEST_END
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
90
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
91 ucx_array_free(&array);
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
92 }
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
93
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
94 UCX_TEST(test_ucx_array_prepend) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
95 int *elems;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
96 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
97
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
98 int x = 42;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
99 ucx_array_prepend(&array, &x);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
100 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
101
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
102 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
103 UCX_TEST_ASSERT(elems[0] == 42, "failed");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
104
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
105 x = 13;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
106 ucx_array_prepend(&array, &x);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
107
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
108 elems = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
109 UCX_TEST_ASSERT(array.size == 2, "incorrect size after prepend");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
110 UCX_TEST_ASSERT(elems[0] == 13, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
111 UCX_TEST_ASSERT(elems[1] == 42,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
112 "prepend corrupted previously inserted data");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
113
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
114 ucx_array_prepend(&array, NULL);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
115
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
116 elems = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
117 UCX_TEST_ASSERT(array.size == 3, "incorrect size after NULL prepend");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
118 UCX_TEST_ASSERT(elems[0] == 0, "element is not zeroed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
119 UCX_TEST_ASSERT(elems[1] == 13,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
120 "NULL prepend corrupted previously inserted data");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
121 UCX_TEST_ASSERT(elems[2] == 42,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
122 "NULL prepend corrupted previously inserted data");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
123
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
124 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
125
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
126 ucx_array_free(&array);
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
127 }
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
128
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
129 UCX_TEST(test_ucx_array_set) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
130 int *elems;
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
131 UcxArray array = ucx_array_new(16, sizeof(int));
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
132
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
133
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
134 int x = 42;
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
135
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
136 UCX_TEST_BEGIN
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
137
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
138 ucx_array_set(&array, 7, &x);
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
139
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
140 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
141 UCX_TEST_ASSERT(elems[7] == 42, "failed");
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
142 UCX_TEST_ASSERT(array.size >= 8, "array not resized on set");
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
143 UCX_TEST_ASSERT(array.capacity == 16, "capacity changed unnecessarily");
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
144
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
145 x = 13;
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
146 ucx_array_set(&array, 27, &x);
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
147
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
148 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
149 UCX_TEST_ASSERT(elems[27] == 13, "failed");
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
150 UCX_TEST_ASSERT(array.size == 28, "array not resized on set");
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
151 UCX_TEST_ASSERT(array.capacity == 28, "capacity not grown");
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
152
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
153 ucx_array_set(&array, 7, NULL);
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
154
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
155 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
156 UCX_TEST_ASSERT(elems[7] == 0, "not zeroed on NULL set");
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
157
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
158 UCX_TEST_END
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
159
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
160 ucx_array_free(&array);
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
161 }
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
162
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
163 UCX_TEST(test_ucx_array_equals) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
164 UcxArray a1 = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
165 UcxArray a2 = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
166 UcxArray a3 = ucx_array_new(16, sizeof(long int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
167 UcxArray a4 = ucx_array_new(16, sizeof(int));
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
168
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
169 int *intelems;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
170 long int *longintelems;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
171
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
172 a1.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
173 intelems = a1.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
174 intelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
175 intelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
176 intelems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
177 intelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
178 intelems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
179 a2.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
180 intelems = a2.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
181 intelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
182 intelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
183 intelems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
184 intelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
185 intelems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
186 a3.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
187 longintelems = a3.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
188 longintelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
189 longintelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
190 longintelems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
191 longintelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
192 longintelems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
193 a4.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
194 intelems = a4.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
195 intelems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
196 intelems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
197 intelems[2] = -6;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
198 intelems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
199 intelems[4] = 15;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
200
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
201 UCX_TEST_BEGIN
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
202
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
203 UCX_TEST_ASSERT(ucx_array_equals(a1, a2, ucx_cmp_int, NULL), "failed");
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
204 UCX_TEST_ASSERT(!ucx_array_equals(a1, a4, ucx_cmp_int, NULL), "failed");
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
205 UCX_TEST_ASSERT(!ucx_array_equals(a4, a1, ucx_cmp_int, NULL), "failed");
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
206 UCX_TEST_ASSERT(!ucx_array_equals(a1, a3, ucx_cmp_int, NULL),
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
207 "comparing arrays of different element size shall fail");
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
208 UCX_TEST_ASSERT(!ucx_array_equals(a3, a1, ucx_cmp_int, NULL),
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
209 "comparing arrays of different element size shall fail");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
210
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
211 UCX_TEST_ASSERT(ucx_array_equals(a1, a2, NULL, NULL),
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
212 "compare using memcmp() failed");
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
213 UCX_TEST_ASSERT(!ucx_array_equals(a1, a4, NULL, NULL),
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
214 "compare using memcmp() failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
215
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
216 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
217 ucx_array_free(&a1);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
218 ucx_array_free(&a2);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
219 ucx_array_free(&a3);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
220 ucx_array_free(&a4);
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 }
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
223 UCX_TEST(test_ucx_array_concat) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
224 UcxArray a1 = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
225 UcxArray a2 = ucx_array_new(16, sizeof(int));
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
226 int *elems;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
227
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
228 a1.size = 2;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
229 elems = a1.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
230 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
231 elems[1] = 11;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
232 a2.size = 3;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
233 elems = a2.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
234 elems[0] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
235 elems[1] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
236 elems[2] = 15;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
237
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
238 UCX_TEST_BEGIN
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
239
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
240 UCX_TEST_ASSERT(!ucx_array_concat(&a1, &a2), "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
241 UCX_TEST_ASSERT(a1.size == 5, "failed");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
242 elems = a1.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
243 UCX_TEST_ASSERT(elems[0] == 47, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
244 UCX_TEST_ASSERT(elems[1] == 11, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
245 UCX_TEST_ASSERT(elems[2] == 0, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
246 UCX_TEST_ASSERT(elems[3] == 8, "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
247 UCX_TEST_ASSERT(elems[4] == 15, "failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
248
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
249 a1.elemsize *= 2;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
250 UCX_TEST_ASSERT(ucx_array_concat(&a1, &a2),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
251 "arrays of different element size must not be concatenated");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
252 UCX_TEST_ASSERT(a1.size == 5,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
253 "arrays of different element size must not be concatenated");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
254
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
255 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
256 ucx_array_free(&a1);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
257 ucx_array_free(&a2);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
258 }
24
e04822101291 changed make clean + added dlist_clone with copy test + added va_end statements to string.c
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
259
344
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
260 UCX_TEST(test_ucx_array_at) {
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
261 UcxArray array = ucx_array_new(16, sizeof(int));
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
262
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
263 int x = 42;
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
264 ucx_array_append(&array, &x);
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
265 x = 13;
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
266 ucx_array_append(&array, &x);
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
267 x = 5;
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
268 ucx_array_append(&array, &x);
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
269
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
270 UCX_TEST_BEGIN
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
271
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
272 UCX_TEST_ASSERT(*(int*)ucx_array_at(array, 1) == 13, "failed");
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
273 *(int*)ucx_array_at(array, 1) = 80;
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
274 UCX_TEST_ASSERT(*(int*)ucx_array_at(array, 1) == 80, "assignment failed");
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
275
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
276 UCX_TEST_ASSERT(*(int*)ucx_array_at(array, 0) == 42, "corrupted data");
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
277 UCX_TEST_ASSERT(*(int*)ucx_array_at(array, 2) == 5, "corrupted data");
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
278
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
279 UCX_TEST_END
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
280
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
281 ucx_array_free(&array);
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
282 }
320b962afaf9 reverts deletion of tests for ucx_array_at()
Mike Becker <universe@uap-core.de>
parents: 342
diff changeset
283
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
284 UCX_TEST(test_ucx_array_find) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
285 UcxArray array = ucx_array_new(16, sizeof(int));
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
286 int *elems;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
287
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
288 array.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
289 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
290 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
291 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
292 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
293 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
294 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
295
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
296 int x = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
297 int y = 90;
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
298
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
299 UCX_TEST_BEGIN
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
300
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
301 UCX_TEST_ASSERT(ucx_array_find(array,(void*)&x,ucx_cmp_int,NULL) == 3,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
302 "doesn't find element");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
303 UCX_TEST_ASSERT(ucx_array_find(array,(void*)&y,ucx_cmp_int,NULL) == 5,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
304 "finds non-existing element");
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
305
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
306 UCX_TEST_ASSERT(ucx_array_find(array,(void*)&x,NULL,NULL) == 3,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
307 "failed using memcmp()");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
308 UCX_TEST_ASSERT(ucx_array_find(array,(void*)&y,NULL,NULL) == 5,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
309 "failed using memcmp()");
172
7084e8e8433c refactoring of list tests + some bug fixes
Mike Becker <universe@uap-core.de>
parents: 162
diff changeset
310
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
311 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
312 ucx_array_free(&array);
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
313 }
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
314
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
315 UCX_TEST(test_ucx_array_contains) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
316 UcxArray array = ucx_array_new(16, sizeof(int));
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
317 int *elems;
90
ef3163857e88 added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
318
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
319 array.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
320 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
321 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
322 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
323 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
324 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
325 elems[4] = 15;
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
326
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
327 int x = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
328 int y = 90;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
329
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
330 UCX_TEST_BEGIN
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
331
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
332 UCX_TEST_ASSERT(ucx_array_contains(array,(void*)&x,ucx_cmp_int,NULL),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
333 "false negative");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
334 UCX_TEST_ASSERT(!ucx_array_contains(array,(void*)&y,ucx_cmp_int,NULL),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
335 "false positive");
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
336
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
337 UCX_TEST_ASSERT(ucx_array_contains(array,(void*)&x,NULL,NULL),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
338 "false negative using memcmp()");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
339 UCX_TEST_ASSERT(!ucx_array_contains(array,(void*)&y,NULL,NULL),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
340 "false positive using memcmp()");
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
341
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
342 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
343 ucx_array_free(&array);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
344 }
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
345
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
346 UCX_TEST(test_ucx_array_remove) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
347 UcxArray array = ucx_array_new(16, sizeof(int));
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
348 int *elems;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
349
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
350 array.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
351 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
352 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
353 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
354 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
355 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
356 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
357
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
358 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
359
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
360 ucx_array_remove(&array, 2);
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
361 elems = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
362 UCX_TEST_ASSERT(
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
363 elems[0] == 47 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
364 elems[1] == 11 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
365 elems[2] == 8 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
366 elems[3] == 15,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
367 "wrong contents after remove");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
368 UCX_TEST_ASSERT(array.size == 4, "wrong size after remove");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
369
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
370 ucx_array_remove_fast(&array, 1);
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
371 elems = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
372 UCX_TEST_ASSERT(
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
373 elems[0] == 47 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
374 elems[1] == 15 &&
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
375 elems[2] == 8,
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
376 "wrong contents after fast remove");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
377 UCX_TEST_ASSERT(array.size == 3, "wrong size after fast remove");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
378
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
379 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
380 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
381 }
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
382
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
383 UCX_TEST(test_ucx_array_clone) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
384 UcxArray array = ucx_array_new(16, sizeof(int));
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
385 int *elems;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
386
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
387 array.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
388 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
389 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
390 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
391 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
392 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
393 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
394
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
395 UcxArray copy = ucx_array_clone(array);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
396 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
397
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
398 UCX_TEST_ASSERT(array.data != copy.data, "no true copy");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
399 UCX_TEST_ASSERT(array.size == copy.size, "size mismatch");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
400 UCX_TEST_ASSERT(array.capacity == copy.capacity, "capacity mismatch");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
401 UCX_TEST_ASSERT(array.elemsize == copy.elemsize, "element size mismatch");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
402 UCX_TEST_ASSERT(array.allocator == copy.allocator, "allocator mismatch");
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
403 UCX_TEST_ASSERT(ucx_array_equals(array, copy, ucx_cmp_int, NULL), "failed");
211
07a284486fa1 added ucx_list_free_contents()
Mike Becker <universe@uap-core.de>
parents: 192
diff changeset
404
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
405 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
406
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
407 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
408 ucx_array_free(&copy);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
409 }
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
410
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
411 static int ucx_cmp_int_reverse(const void* x, const void* y, void* data) {
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
412 return -ucx_cmp_int(x,y,data);
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
413 }
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
414
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
415 UCX_TEST(test_ucx_array_sort) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
416 int *elems;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
417
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
418 UcxArray array = ucx_array_new(16, sizeof(int));
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
419 array.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
420 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
421 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
422 elems[1] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
423 elems[2] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
424 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
425 elems[4] = 15;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
426
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
427 UcxArray expected = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
428 expected.size = 5;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
429 elems = expected.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
430 elems[0] = 0;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
431 elems[1] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
432 elems[2] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
433 elems[3] = 15;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
434 elems[4] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
435
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
436 UcxArray expectedrev = ucx_array_new(16, sizeof(int));
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
437 expectedrev.size = 5;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
438 elems = expectedrev.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
439 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
440 elems[1] = 15;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
441 elems[2] = 11;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
442 elems[3] = 8;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
443 elems[4] = 0;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
444
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
445
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
446 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
447 void* original_ptr = array.data;
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
448 ucx_array_sort(array, ucx_cmp_int, NULL);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
449 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), "failed");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
450 UCX_TEST_ASSERT(array.size == 5, "size corrupted");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
451 UCX_TEST_ASSERT(array.data == original_ptr, "shall not reallocate");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
452
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
453 ucx_array_sort(array, ucx_cmp_int_reverse, NULL);
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
454 UCX_TEST_ASSERT(ucx_array_equals(array, expectedrev, NULL, NULL), "failed");
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
455
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
456 ucx_array_reserve(&array, 32);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
457 ucx_array_reserve(&expected, 32);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
458 array.size = expected.size = 32;
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
459 for (size_t i = 0 ; i < 32 ; i++) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
460 ((int*)array.data)[i]= ((i%2==0)?-1:1) * ((int) i);
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
461 ((int*)expected.data)[i] = (-30+2*i) - (i > 15 ? 1 : 0);
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
462 }
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
463
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
464 /* dummy third argument to trigger a possible fallback for qsort_s */
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
465 ucx_array_sort(array, ucx_cmp_int, array.data);
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
466 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL),
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
467 "failed for bigger arrays");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
468 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
469
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
470 ucx_array_free(&expected);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
471 ucx_array_free(&array);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
472 }
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
473
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
474 UCX_TEST(test_ucx_array_autogrow) {
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
475 int *elems;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
476 UcxArray array = ucx_array_new(4, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
477 array.size = 3;
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
478 elems = array.data;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
479 elems[0] = 47;
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
480 elems[1] = 11;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
481 int x = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
482
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
483 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
484
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
485 void* oldptr = array.data;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
486
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
487 ucx_array_append(&array, &x);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
488 UCX_TEST_ASSERT(array.capacity == 4 && array.data == oldptr,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
489 "array should not grow too early");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
490 ucx_array_append(&array, &x);
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
491 elems = array.data;
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
492 UCX_TEST_ASSERT(array.capacity == 8, "array did not grow");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
493 UCX_TEST_ASSERT(array.size == 5, "incorrect size after grow");
342
8f0a3c00d1d2 removes cumbersome array accessor macros
Mike Becker <universe@uap-core.de>
parents: 337
diff changeset
494 UCX_TEST_ASSERT(elems[3] == 5 && elems[4] == 5, "corrupt data");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
495
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
496 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
497 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
498 }
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
499
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
500 UCX_TEST(test_ucx_array_shrink) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
501 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
502 array.size = 4;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
503
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
504 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
505 UCX_TEST_ASSERT(!ucx_array_shrink(&array), "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
506 UCX_TEST_ASSERT(array.capacity == 4, "incorrect capacity after shrink");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
507 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
508 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
509 }
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
510
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
511 UCX_TEST(test_ucx_array_resize) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
512 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
513 array.size = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
514
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
515 UCX_TEST_BEGIN
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
516
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
517 UCX_TEST_ASSERT(!ucx_array_resize(&array, 32), "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
518 UCX_TEST_ASSERT(array.capacity == 32, "incorrect capacity after resize");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
519 UCX_TEST_ASSERT(array.size == 8, "incorrect size after resize");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
520
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
521 UCX_TEST_ASSERT(!ucx_array_resize(&array, 4), "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
522 UCX_TEST_ASSERT(array.capacity == 4, "incorrect capacity after resize");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
523 UCX_TEST_ASSERT(array.size == 4, "incorrect size after resize");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
524
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
525 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
526 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
527 }
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
528
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
529 UCX_TEST(test_ucx_array_reserve) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
530 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
531
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
532 UCX_TEST_BEGIN
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
533
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
534 UCX_TEST_ASSERT(!ucx_array_reserve(&array, 4), "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
535 UCX_TEST_ASSERT(array.capacity == 16, "reserve shall not shrink");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
536
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
537 UCX_TEST_ASSERT(!ucx_array_resize(&array, 32), "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
538 UCX_TEST_ASSERT(array.capacity == 32, "incorrect capacity after reserve");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
539
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
540 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
541 ucx_array_free(&array);
35
fdabd1240b69 added mkdir for build directory to makefile + added qsort for list and dlist
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
542 }

mercurial