test/map_tests.c

Tue, 21 Feb 2012 01:13:17 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 21 Feb 2012 01:13:17 +0100
changeset 29
bce0d7f2912b
parent 20
db7d9860dbbd
child 31
91ac86557290
permissions
-rw-r--r--

fixed map with the help of new tests

     1 /*
     2  *
     3  */
     5 #include "map_tests.h"
     7 UCX_TEST_BEGIN(test_ucx_map_new) {
     8     UcxMap *map = ucx_map_new(16);
    10     UCX_TEST_ASSERT(map->size == 16, "wrong size")
    11     UCX_TEST_ASSERT(map->map != NULL, "failed")
    13     ucx_map_free(map);
    15     UCX_TEST_END
    16 }
    18 UCX_TEST_BEGIN(test_ucx_key) {
    20     UcxKey key = ucx_key("This is a text.", 15);
    21     UCX_TEST_ASSERT(strncmp(key.data, "This is a text.", 15) == 0, "failed")
    22     UCX_TEST_ASSERT(key.len == 15, "failed")
    23     UCX_TEST_ASSERT(key.hash == 1261186027, "hash failed")
    25     UCX_TEST_END
    26 }
    28 UCX_TEST_BEGIN(test_ucx_map_put) {
    30     UcxMap *map = ucx_map_new(4);
    32     int td[5];
    33     td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
    35     ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */
    36     ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */
    37     ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */
    38     ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */
    39     ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */
    41     UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[0], "failed Key0")
    42     UCX_TEST_ASSERT(map->map[0]->next != NULL, "no list at slot 0")
    43     UCX_TEST_ASSERT(*((int*)map->map[0]->next->data) == td[2], "failed Key2")
    44     UCX_TEST_ASSERT(map->map[0]->next->next != NULL, "list corrupt at slot 0")
    45     UCX_TEST_ASSERT(*((int*)map->map[0]->next->next->data) == td[4],
    46             "failed Key4")
    47     UCX_TEST_ASSERT(map->map[0]->next->next->next == NULL,
    48             "slot 0 not terminated")
    50     UCX_TEST_ASSERT(map->map[1] == NULL, "slot 1 not terminated")
    52     UCX_TEST_ASSERT(*((int*)map->map[2]->data) == td[3], "failed KeY3")
    53     UCX_TEST_ASSERT(map->map[2]->next == NULL, "slot 2 not terminated")
    55     UCX_TEST_ASSERT(*((int*)map->map[3]->data) == td[1], "failed Key1")
    57     ucx_map_cstr_put(map, "Key0", &td[3]); /* 0 */
    59     UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[3], "overwrite failed")
    60     UCX_TEST_ASSERT(*((int*)map->map[0]->next->data) == td[2],
    61             "overwrite failed")
    62     UCX_TEST_ASSERT(*((int*)map->map[0]->next->next->data) == td[4], 
    63             "overwrite failed")
    64     UCX_TEST_ASSERT(map->map[0]->next->next->next == NULL, "overwrite failed")
    66     ucx_map_free(map);
    68     UCX_TEST_END
    69 }
    71 UCX_TEST_BEGIN(test_ucx_map_get) {
    72     UCX_TEST_END
    73 }

mercurial