test/map_tests.c

changeset 80
0125e4089f88
parent 76
655020a30e77
child 88
18823857ce79
equal deleted inserted replaced
79:cf3757c60c8f 80:0125e4089f88
31 31
32 int td[5]; 32 int td[5];
33 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000; 33 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
34 34
35 UCX_TEST_BEGIN 35 UCX_TEST_BEGIN
36 ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */ 36 ucx_map_cstr_put(map, "Key2", &td[2]); /* 3.2 */
37 ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */ 37 ucx_map_cstr_put(map, "Key0", &td[0]); /* 0.0 */
38 ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */ 38 ucx_map_cstr_put(map, "Key1", &td[1]); /* 3.0 */
39 ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */ 39 ucx_map_cstr_put(map, "KeY3", &td[3]); /* 3.1 */
40 ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */ 40 ucx_map_cstr_put(map, "KEY4", &td[4]); /* 1.0 */
41 41
42 UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[0], "failed Key0"); 42 UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[0], "failed Key0");
43 UCX_TEST_ASSERT(map->map[0]->next != NULL, "no list at slot 0"); 43 UCX_TEST_ASSERT(*((int*)map->map[1]->data) == td[4], "failed KEY4");
44 UCX_TEST_ASSERT(*((int*)map->map[0]->next->data) == td[2], "failed Key2");
45 UCX_TEST_ASSERT(map->map[0]->next->next != NULL, "list corrupt at slot 0");
46 UCX_TEST_ASSERT(*((int*)map->map[0]->next->next->data) == td[4],
47 "failed Key4")
48 UCX_TEST_ASSERT(map->map[0]->next->next->next == NULL,
49 "slot 0 not terminated")
50
51 UCX_TEST_ASSERT(map->map[1] == NULL, "slot 1 not terminated");
52
53 UCX_TEST_ASSERT(*((int*)map->map[2]->data) == td[3], "failed KeY3");
54 UCX_TEST_ASSERT(map->map[2]->next == NULL, "slot 2 not terminated");
55
56 UCX_TEST_ASSERT(*((int*)map->map[3]->data) == td[1], "failed Key1"); 44 UCX_TEST_ASSERT(*((int*)map->map[3]->data) == td[1], "failed Key1");
57 45
58 ucx_map_cstr_put(map, "Key0", &td[3]); /* 0 */ 46 UCX_TEST_ASSERT(map->map[3]->next != NULL, "no list at slot 3");
59 47 UCX_TEST_ASSERT(map->map[3]->next->next != NULL, "list corrupt at slot 3");
60 UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[3], "overwrite failed"); 48 UCX_TEST_ASSERT(*((int*)map->map[3]->next->data) == td[3],
61 UCX_TEST_ASSERT(*((int*)map->map[0]->next->data) == td[2], 49 "failed KeY3")
50 UCX_TEST_ASSERT(*((int*)map->map[3]->next->next->data) == td[2],
51 "failed KeY2");
52
53 UCX_TEST_ASSERT(map->map[0]->next == NULL, "slot 0 not terminated");
54 UCX_TEST_ASSERT(map->map[1]->next == NULL, "slot 1 not terminated");
55 UCX_TEST_ASSERT(map->map[2] == NULL, "slot 2 not empty");
56 UCX_TEST_ASSERT(map->map[3]->next->next->next == NULL,
57 "slot 3 not terminated")
58
59 ucx_map_cstr_put(map, "KeY3", &td[4]); /* replace 3.1 */
60
61 UCX_TEST_ASSERT(*((int*)map->map[3]->data) == td[1],
62 "overwrite failed") 62 "overwrite failed")
63 UCX_TEST_ASSERT(*((int*)map->map[0]->next->next->data) == td[4], 63 UCX_TEST_ASSERT(*((int*)map->map[3]->next->data) == td[4],
64 "overwrite failed");
65 UCX_TEST_ASSERT(*((int*)map->map[3]->next->next->data) == td[2],
64 "overwrite failed") 66 "overwrite failed")
65 UCX_TEST_ASSERT(map->map[0]->next->next->next == NULL, "overwrite failed"); 67 UCX_TEST_ASSERT(map->map[3]->next->next->next == NULL, "overwrite failed");
66 68
67 UCX_TEST_END 69 UCX_TEST_END
68 ucx_map_free(map); 70 ucx_map_free(map);
69 } 71 }
70 72
72 UcxMap *map = ucx_map_new(4); 74 UcxMap *map = ucx_map_new(4);
73 75
74 int td[5]; 76 int td[5];
75 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000; 77 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
76 78
77 ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */ 79 ucx_map_cstr_put(map, "Key2", &td[2]);
78 ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */ 80 ucx_map_cstr_put(map, "Key0", &td[0]);
79 ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */ 81 ucx_map_cstr_put(map, "Key1", &td[1]);
80 ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */ 82 ucx_map_cstr_put(map, "KeY3", &td[3]);
81 ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */ 83 ucx_map_cstr_put(map, "KEY4", &td[4]);
82 UCX_TEST_BEGIN 84 UCX_TEST_BEGIN
83 85
84 td[0] = *((int*)ucx_map_cstr_get(map, "Key0")); 86 td[0] = *((int*)ucx_map_cstr_get(map, "Key0"));
85 td[1] = *((int*)ucx_map_cstr_get(map, "Key1")); 87 td[1] = *((int*)ucx_map_cstr_get(map, "Key1"));
86 td[2] = *((int*)ucx_map_cstr_get(map, "Key2")); 88 td[2] = *((int*)ucx_map_cstr_get(map, "Key2"));

mercurial