test/array_tests.c

Fri, 05 Jul 2019 15:47:57 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 05 Jul 2019 15:47:57 +0200
branch
feature/array
changeset 340
8acf182f6424
parent 337
f695ae118460
child 342
8f0a3c00d1d2
permissions
-rw-r--r--

adds documentation

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));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
61
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
62 int x = 42;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
63 ucx_array_append(&array, &x);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
64 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
65
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
66 UCX_TEST_ASSERT(ucx_array_at_int(array, 0) == 42, "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
67
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
68 x = 13;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
69 ucx_array_append(&array, &x);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
70
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
71 UCX_TEST_ASSERT(array.size == 2, "incorrect size after append");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
72 UCX_TEST_ASSERT(ucx_array_at_int(array, 1) == 13, "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
73 UCX_TEST_ASSERT(ucx_array_at_int(array, 0) == 42,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
74 "append corrupted previously inserted data");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
75
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
76 ucx_array_append(&array, NULL);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
77
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
78 UCX_TEST_ASSERT(array.size == 3, "incorrect size after NULL append");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
79 UCX_TEST_ASSERT(ucx_array_at_int(array, 2) == 0, "element is not zeroed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
80 UCX_TEST_ASSERT(ucx_array_at_int(array, 0) == 42,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
81 "NULL append corrupted previously inserted data");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
82 UCX_TEST_ASSERT(ucx_array_at_int(array, 1) == 13,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
83 "NULL append corrupted previously inserted data");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
84
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
85 UCX_TEST_END
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
86
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
87 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
88 }
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
89
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
90 UCX_TEST(test_ucx_array_prepend) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
91 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
92
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
93 int x = 42;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
94 ucx_array_prepend(&array, &x);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
95 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
96
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
97 UCX_TEST_ASSERT(ucx_array_at_int(array, 0) == 42, "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
98
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
99 x = 13;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
100 ucx_array_prepend(&array, &x);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
101
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
102 UCX_TEST_ASSERT(array.size == 2, "incorrect size after prepend");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
103 UCX_TEST_ASSERT(ucx_array_at_int(array, 0) == 13, "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
104 UCX_TEST_ASSERT(ucx_array_at_int(array, 1) == 42,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
105 "prepend corrupted previously inserted data");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
106
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
107 ucx_array_prepend(&array, NULL);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
108
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
109 UCX_TEST_ASSERT(array.size == 3, "incorrect size after NULL prepend");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
110 UCX_TEST_ASSERT(ucx_array_at_int(array, 0) == 0, "element is not zeroed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
111 UCX_TEST_ASSERT(ucx_array_at_int(array, 1) == 13,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
112 "NULL prepend corrupted previously inserted data");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
113 UCX_TEST_ASSERT(ucx_array_at_int(array, 2) == 42,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
114 "NULL prepend corrupted previously inserted data");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
115
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
116 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
117
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
118 ucx_array_free(&array);
18
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
119 }
69636f81db31 added clone and equals to lists
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
120
337
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
121 UCX_TEST(test_ucx_array_set) {
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
122 UcxArray array = ucx_array_new(16, sizeof(int));
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
123
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
124 int x = 42;
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
125
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
126 UCX_TEST_BEGIN
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
127
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
128 ucx_array_set(&array, 7, &x);
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
129 UCX_TEST_ASSERT(ucx_array_at_int(array, 7) == 42, "failed");
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
130 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
131 UCX_TEST_ASSERT(array.capacity == 16, "capacity changed unnecessarily");
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
132
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
133 x = 13;
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
134 ucx_array_set(&array, 27, &x);
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_ASSERT(ucx_array_at_int(array, 27) == 13, "failed");
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
137 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
138 UCX_TEST_ASSERT(array.capacity == 28, "capacity not grown");
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
139
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
140 ucx_array_set(&array, 7, NULL);
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
141
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
142 UCX_TEST_ASSERT(ucx_array_at_int(array, 7) == 0, "not zeroed on NULL set");
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
143
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
144 UCX_TEST_END
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
145
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
146 ucx_array_free(&array);
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
147 }
f695ae118460 adds ucx_array_set()
Mike Becker <universe@uap-core.de>
parents: 336
diff changeset
148
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
149 UCX_TEST(test_ucx_array_equals) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
150 UcxArray a1 = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
151 UcxArray a2 = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
152 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
153 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
154
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
155 a1.size = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
156 ucx_array_at_int(a1, 0) = 47;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
157 ucx_array_at_int(a1, 1) = 11;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
158 ucx_array_at_int(a1, 2) = 0;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
159 ucx_array_at_int(a1, 3) = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
160 ucx_array_at_int(a1, 4) = 15;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
161 a2.size = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
162 ucx_array_at_int(a2, 0) = 47;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
163 ucx_array_at_int(a2, 1) = 11;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
164 ucx_array_at_int(a2, 2) = 0;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
165 ucx_array_at_int(a2, 3) = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
166 ucx_array_at_int(a2, 4) = 15;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
167 a3.size = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
168 ucx_array_at_longint(a3, 0) = 47;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
169 ucx_array_at_longint(a3, 1) = 11;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
170 ucx_array_at_longint(a3, 2) = 0;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
171 ucx_array_at_longint(a3, 3) = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
172 ucx_array_at_longint(a3, 4) = 15;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
173 a4.size = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
174 ucx_array_at_int(a4, 0) = 47;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
175 ucx_array_at_int(a4, 1) = 11;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
176 ucx_array_at_int(a4, 2) = -6;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
177 ucx_array_at_int(a4, 3) = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
178 ucx_array_at_int(a4, 4) = 15;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
179
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
180 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
181
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
182 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
183 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
184 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
185 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
186 "comparing arrays of different element size shall fail");
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
187 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
188 "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
189
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
190 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
191 "compare using memcmp() failed");
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
192 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
193 "compare using memcmp() failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
194
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
195 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
196 ucx_array_free(&a1);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
197 ucx_array_free(&a2);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
198 ucx_array_free(&a3);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
199 ucx_array_free(&a4);
9
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 }
013c5c4b7e44 Added dlist tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
202 UCX_TEST(test_ucx_array_concat) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
203 UcxArray a1 = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
204 UcxArray a2 = ucx_array_new(16, sizeof(int));
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
205
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
206 a1.size = 2;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
207 ucx_array_at_int(a1, 0) = 47;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
208 ucx_array_at_int(a1, 1) = 11;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
209 a2.size = 3;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
210 ucx_array_at_int(a2, 0) = 0;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
211 ucx_array_at_int(a2, 1) = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
212 ucx_array_at_int(a2, 2) = 15;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
213
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
214 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
215
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
216 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
217 UCX_TEST_ASSERT(a1.size == 5, "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
218 UCX_TEST_ASSERT(ucx_array_at_int(a1, 0) == 47, "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
219 UCX_TEST_ASSERT(ucx_array_at_int(a1, 1) == 11, "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
220 UCX_TEST_ASSERT(ucx_array_at_int(a1, 2) == 0, "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
221 UCX_TEST_ASSERT(ucx_array_at_int(a1, 3) == 8, "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
222 UCX_TEST_ASSERT(ucx_array_at_int(a1, 4) == 15, "failed");
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
223
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
224 a1.elemsize *= 2;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
225 UCX_TEST_ASSERT(ucx_array_concat(&a1, &a2),
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
226 "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
227 UCX_TEST_ASSERT(a1.size == 5,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
228 "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
229
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
230 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
231 ucx_array_free(&a1);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
232 ucx_array_free(&a2);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
233 }
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
234
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
235 UCX_TEST(test_ucx_array_at) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
236 UcxArray array = ucx_array_new(16, sizeof(int));
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
237
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
238 int x = 42;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
239 ucx_array_append(&array, &x);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
240 x = 13;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
241 ucx_array_append(&array, &x);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
242 x = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
243 ucx_array_append(&array, &x);
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
244
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
245 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
246
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
247 UCX_TEST_ASSERT(ucx_array_at_int(array, 1) == 13, "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
248 ucx_array_at_int(array, 1) = 80;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
249 UCX_TEST_ASSERT(ucx_array_at_int(array, 1) == 80, "assignment failed");
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
250
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
251
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
252 UCX_TEST_ASSERT(ucx_array_at_int(array, 0) == 42, "corrupted data");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
253 UCX_TEST_ASSERT(ucx_array_at_int(array, 2) == 5, "corrupted data");
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
254
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
255 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
256
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
257 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
258 }
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
259
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
260 UCX_TEST(test_ucx_array_find) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
261 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
262
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
263 array.size = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
264 ucx_array_at_int(array, 0) = 47;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
265 ucx_array_at_int(array, 1) = 11;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
266 ucx_array_at_int(array, 2) = 0;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
267 ucx_array_at_int(array, 3) = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
268 ucx_array_at_int(array, 4) = 15;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
269
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
270 int x = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
271 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
272
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
273 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
274
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
275 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
276 "doesn't find element");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
277 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
278 "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
279
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
280 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
281 "failed using memcmp()");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
282 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
283 "failed using memcmp()");
172
7084e8e8433c refactoring of list tests + some bug fixes
Mike Becker <universe@uap-core.de>
parents: 162
diff changeset
284
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
285 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
286 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
287 }
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
288
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
289 UCX_TEST(test_ucx_array_contains) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
290 UcxArray array = ucx_array_new(16, sizeof(int));
90
ef3163857e88 added tests for ucx_(d)list_contains
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
291
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
292 array.size = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
293 ucx_array_at_int(array, 0) = 47;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
294 ucx_array_at_int(array, 1) = 11;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
295 ucx_array_at_int(array, 2) = 0;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
296 ucx_array_at_int(array, 3) = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
297 ucx_array_at_int(array, 4) = 15;
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
298
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
299 int x = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
300 int y = 90;
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
301
123
7fb0f74517c5 changed signature of sstrncat + some documentation for UcxList + new features for UcxList
Mike Becker <universe@uap-core.de>
parents: 122
diff changeset
302 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
303
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
304 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
305 "false negative");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
306 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
307 "false positive");
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
308
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
309 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
310 "false negative using memcmp()");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
311 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
312 "false positive using memcmp()");
162
52dfe5f4ecd7 added more tests for ucx_list_remove
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
313
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
314 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
315 ucx_array_free(&array);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
316 }
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
317
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
318 UCX_TEST(test_ucx_array_remove) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
319 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
320
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
321 array.size = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
322 ucx_array_at_int(array, 0) = 47;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
323 ucx_array_at_int(array, 1) = 11;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
324 ucx_array_at_int(array, 2) = 0;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
325 ucx_array_at_int(array, 3) = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
326 ucx_array_at_int(array, 4) = 15;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
327
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
328 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
329
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
330 ucx_array_remove(&array, 2);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
331 UCX_TEST_ASSERT(
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
332 ucx_array_at_int(array, 0) == 47 &&
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
333 ucx_array_at_int(array, 1) == 11 &&
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
334 ucx_array_at_int(array, 2) == 8 &&
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
335 ucx_array_at_int(array, 3) == 15,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
336 "wrong contents after remove");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
337 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
338
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
339 ucx_array_remove_fast(&array, 1);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
340 UCX_TEST_ASSERT(
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
341 ucx_array_at_int(array, 0) == 47 &&
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
342 ucx_array_at_int(array, 1) == 15 &&
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
343 ucx_array_at_int(array, 2) == 8,
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
344 "wrong contents after fast remove");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
345 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
346
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
347 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
348 ucx_array_free(&array);
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
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
351 UCX_TEST(test_ucx_array_clone) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
352
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
353 UcxArray array = ucx_array_new(16, sizeof(int));
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
354
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
355 array.size = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
356 ucx_array_at_int(array, 0) = 47;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
357 ucx_array_at_int(array, 1) = 11;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
358 ucx_array_at_int(array, 2) = 0;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
359 ucx_array_at_int(array, 3) = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
360 ucx_array_at_int(array, 4) = 15;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
361
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
362 UcxArray copy = ucx_array_clone(array);
33
9c219a62070d major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
363 UCX_TEST_BEGIN
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
364
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
365 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
366 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
367 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
368 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
369 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
370 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
371
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
372 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
373
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
374 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
375 ucx_array_free(&copy);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
376 }
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
377
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
378 UCX_TEST(test_ucx_array_sort) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
379 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
380 array.size = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
381 ucx_array_at_int(array, 0) = 47;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
382 ucx_array_at_int(array, 1) = 11;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
383 ucx_array_at_int(array, 2) = 0;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
384 ucx_array_at_int(array, 3) = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
385 ucx_array_at_int(array, 4) = 15;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
386
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
387 UcxArray expected = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
388 expected.size = 5;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
389 ucx_array_at_int(expected, 0) = 0;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
390 ucx_array_at_int(expected, 1) = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
391 ucx_array_at_int(expected, 2) = 11;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
392 ucx_array_at_int(expected, 3) = 15;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
393 ucx_array_at_int(expected, 4) = 47;
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
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
396 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
397 void* original_ptr = array.data;
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
398 ucx_array_sort(array, ucx_cmp_int, NULL);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
399 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
400 UCX_TEST_ASSERT(array.size == 5, "size corrupted");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
401 UCX_TEST_ASSERT(array.data == original_ptr, "shall not reallocate");
336
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
402
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
403 ucx_array_reserve(&array, 32);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
404 ucx_array_reserve(&expected, 32);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
405 array.size = expected.size = 32;
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
406 for (size_t i = 0 ; i < 32 ; i++) {
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
407 ucx_array_at_int(array, i) = ((i%2==0)?-1:1) * ((int) i);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
408 ucx_array_at_int(expected, i) = (-30+2*i) - (i > 15 ? 1 : 0);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
409 }
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
410
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
411 ucx_array_sort(array, ucx_cmp_int, NULL);
6d7aa8a1a3b3 implements ucx_array_sort()
Mike Becker <universe@uap-core.de>
parents: 334
diff changeset
412 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
413 "failed for bigger arrays");
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
414 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
415
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
416 ucx_array_free(&expected);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
417 ucx_array_free(&array);
27
22644e2572bc removed old foreach + refactored list tests
Mike Becker <universe@uap-core.de>
parents: 24
diff changeset
418 }
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
419
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
420 UCX_TEST(test_ucx_array_autogrow) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
421 UcxArray array = ucx_array_new(4, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
422 array.size = 3;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
423 ucx_array_at_int(array, 0) = 47;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
424 ucx_array_at_int(array, 1) = 11;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
425 int x = 5;
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 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
428
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
429 void* oldptr = array.data;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
430
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
431 ucx_array_append(&array, &x);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
432 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
433 "array should not grow too early");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
434 ucx_array_append(&array, &x);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
435 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
436 UCX_TEST_ASSERT(array.size == 5, "incorrect size after grow");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
437 UCX_TEST_ASSERT(ucx_array_at_int(array, 3) == 5 &&
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
438 ucx_array_at_int(array, 3) == 5, "corrupt data");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
439
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
440 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
441 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
442 }
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
443
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
444 UCX_TEST(test_ucx_array_shrink) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
445 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
446 array.size = 4;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
447
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
448 UCX_TEST_BEGIN
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
449 UCX_TEST_ASSERT(!ucx_array_shrink(&array), "failed");
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
450 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
451 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
452 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
453 }
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
454
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
455 UCX_TEST(test_ucx_array_resize) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
456 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
457 array.size = 8;
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
458
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
459 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
460
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
461 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
462 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
463 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
464
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
465 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
466 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
467 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
468
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
469 UCX_TEST_END
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
470 ucx_array_free(&array);
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
471 }
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
472
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
473 UCX_TEST(test_ucx_array_reserve) {
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
474 UcxArray array = ucx_array_new(16, sizeof(int));
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
475
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
476 UCX_TEST_BEGIN
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
477
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
478 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
479 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
480
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
481 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
482 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
483
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
484 UCX_TEST_END
334
bc81faa9afda adds array interface and tests
Mike Becker <universe@uap-core.de>
parents: 323
diff changeset
485 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
486 }

mercurial