Thu, 16 Aug 2012 12:36:23 +0200
replaced qsort with natural merge sort
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | */ |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | #include "map_tests.h" |
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
7 | UCX_TEST_IMPLEMENT(test_ucx_map_new) { |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | UcxMap *map = ucx_map_new(16); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
9 | UCX_TEST_BEGIN |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
10 | UCX_TEST_ASSERT(map->size == 16, "wrong size") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
11 | UCX_TEST_ASSERT(map->map != NULL, "failed") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
12 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
13 | UCX_TEST_END |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
14 | ucx_map_free(map); |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
15 | } |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
17 | UCX_TEST_IMPLEMENT(test_ucx_key) { |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
18 | UcxKey key = ucx_key("This is a text.", 15); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
19 | UCX_TEST_BEGIN |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
20 | UCX_TEST_ASSERT(strncmp(key.data, "This is a text.", 15) == 0, "failed") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
21 | UCX_TEST_ASSERT(key.len == 15, "failed") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
22 | UCX_TEST_ASSERT(key.hash == 1261186027, "hash failed") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
23 | |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
24 | UCX_TEST_END |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
25 | } |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
26 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
27 | UCX_TEST_IMPLEMENT(test_ucx_map_put) { |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
28 | |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
29 | UcxMap *map = ucx_map_new(4); |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
30 | |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
31 | int td[5]; |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
32 | td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000; |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
34 | UCX_TEST_BEGIN |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
35 | ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */ |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
36 | ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */ |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
37 | ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */ |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
38 | ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */ |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
39 | ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */ |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
40 | |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
41 | UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[0], "failed Key0") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
42 | UCX_TEST_ASSERT(map->map[0]->next != NULL, "no list at slot 0") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
43 | UCX_TEST_ASSERT(*((int*)map->map[0]->next->data) == td[2], "failed Key2") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
44 | UCX_TEST_ASSERT(map->map[0]->next->next != NULL, "list corrupt at slot 0") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
45 | UCX_TEST_ASSERT(*((int*)map->map[0]->next->next->data) == td[4], |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
46 | "failed Key4") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
47 | UCX_TEST_ASSERT(map->map[0]->next->next->next == NULL, |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
48 | "slot 0 not terminated") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
49 | |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
50 | UCX_TEST_ASSERT(map->map[1] == NULL, "slot 1 not terminated") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
51 | |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
52 | UCX_TEST_ASSERT(*((int*)map->map[2]->data) == td[3], "failed KeY3") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
53 | UCX_TEST_ASSERT(map->map[2]->next == NULL, "slot 2 not terminated") |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
55 | UCX_TEST_ASSERT(*((int*)map->map[3]->data) == td[1], "failed Key1") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
56 | |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
57 | ucx_map_cstr_put(map, "Key0", &td[3]); /* 0 */ |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
58 | |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
59 | UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[3], "overwrite failed") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
60 | UCX_TEST_ASSERT(*((int*)map->map[0]->next->data) == td[2], |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
61 | "overwrite failed") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
62 | UCX_TEST_ASSERT(*((int*)map->map[0]->next->next->data) == td[4], |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
63 | "overwrite failed") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
64 | UCX_TEST_ASSERT(map->map[0]->next->next->next == NULL, "overwrite failed") |
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
65 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
66 | UCX_TEST_END |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
67 | ucx_map_free(map); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
68 | } |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
69 | |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
70 | UCX_TEST_IMPLEMENT(test_ucx_map_get) { |
34 | 71 | UcxMap *map = ucx_map_new(4); |
72 | ||
73 | int td[5]; | |
74 | td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000; | |
75 | ||
76 | ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */ | |
77 | ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */ | |
78 | ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */ | |
79 | ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */ | |
80 | ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */ | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
81 | UCX_TEST_BEGIN |
34 | 82 | |
83 | td[0] = *((int*)ucx_map_cstr_get(map, "Key0")); | |
84 | td[1] = *((int*)ucx_map_cstr_get(map, "Key1")); | |
85 | td[2] = *((int*)ucx_map_cstr_get(map, "Key2")); | |
86 | td[3] = *((int*)ucx_map_cstr_get(map, "KeY3")); | |
87 | td[4] = *((int*)ucx_map_cstr_get(map, "KEY4")); | |
88 | UCX_TEST_ASSERT(td[0] == 10, "failed key 0") | |
89 | UCX_TEST_ASSERT(td[1] == 42, "failed key 1") | |
90 | UCX_TEST_ASSERT(td[2] == 70, "failed key 2") | |
91 | UCX_TEST_ASSERT(td[3] == 11200, "failed key 3") | |
92 | UCX_TEST_ASSERT(td[4] == 80000, "failed key 4") | |
93 | ||
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
94 | UCX_TEST_END |
34 | 95 | ucx_map_free(map); |
20
db7d9860dbbd
added some map functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | } |
29
bce0d7f2912b
fixed map with the help of new tests
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
97 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
98 | UCX_TEST_SUBROUTINE(test_ucx_map_itersrt, mapptr) { |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
99 | UcxMap *map = (UcxMap*) mapptr; |
31
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
100 | int v1 = 10; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
101 | int v2 = 15; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
102 | int v3 = 7; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
103 | int v4 = 9; |
32
c7af4ec56e19
consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents:
31
diff
changeset
|
104 | |
31
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
105 | ucx_map_cstr_put(map, "v1", &v1); |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
106 | ucx_map_cstr_put(map, "v2", &v2); |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
107 | ucx_map_cstr_put(map, "v3", &v3); |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
108 | ucx_map_cstr_put(map, "v4", &v4); |
32
c7af4ec56e19
consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents:
31
diff
changeset
|
109 | |
31
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
110 | UcxMapIterator i = ucx_map_iterator(map); |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
111 | int check = 0; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
112 | int hit = 0; |
32
c7af4ec56e19
consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents:
31
diff
changeset
|
113 | |
31
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
114 | UCX_MAP_FOREACH(int*, v, map, i) { |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
115 | check += *v; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
116 | hit++; |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
117 | } |
32
c7af4ec56e19
consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents:
31
diff
changeset
|
118 | |
31
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
119 | UCX_TEST_ASSERT(hit == 4, "test1: wrong number of hits"); |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
120 | UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test1: wrong result"); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
121 | } |
32
c7af4ec56e19
consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents:
31
diff
changeset
|
122 | |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
123 | UCX_TEST_IMPLEMENT(test_ucx_map_iterator) { |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
124 | UcxMap *map = ucx_map_new(16); |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
125 | UCX_TEST_BEGIN |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
126 | UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map) |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
127 | UCX_TEST_END |
31
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
128 | ucx_map_free(map); |
33
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
129 | } |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
130 | |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
131 | UCX_TEST_IMPLEMENT(test_ucx_map_iterator_chain) { |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
132 | UcxMap *map = ucx_map_new(1); |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
133 | UCX_TEST_BEGIN |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
134 | UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map) |
9c219a62070d
major refactoring of test framework
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
135 | UCX_TEST_END |
31
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
136 | ucx_map_free(map); |
91ac86557290
added map iterator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
137 | } |