test/map_tests.c

changeset 32
c7af4ec56e19
parent 31
91ac86557290
child 33
9c219a62070d
equal deleted inserted replaced
31:91ac86557290 32:c7af4ec56e19
67 67
68 UCX_TEST_END 68 UCX_TEST_END
69 } 69 }
70 70
71 UCX_TEST_BEGIN(test_ucx_map_get) { 71 UCX_TEST_BEGIN(test_ucx_map_get) {
72 // TODO:
72 UCX_TEST_END 73 UCX_TEST_END
73 } 74 }
74 75
75 UCX_TEST_BEGIN(test_ucx_map_iterator) { 76 UCX_TEST_BEGIN(test_ucx_map_iterator) {
76 UcxMap *map = ucx_map_new(16); 77 UcxMap *map = ucx_map_new(16);
77 78
78 int v1 = 10; 79 int v1 = 10;
79 int v2 = 15; 80 int v2 = 15;
80 int v3 = 7; 81 int v3 = 7;
81 int v4 = 9; 82 int v4 = 9;
82 83
83 ucx_map_cstr_put(map, "v1", &v1); 84 ucx_map_cstr_put(map, "v1", &v1);
84 ucx_map_cstr_put(map, "v2", &v2); 85 ucx_map_cstr_put(map, "v2", &v2);
85 ucx_map_cstr_put(map, "v3", &v3); 86 ucx_map_cstr_put(map, "v3", &v3);
86 ucx_map_cstr_put(map, "v4", &v4); 87 ucx_map_cstr_put(map, "v4", &v4);
87 88
88 UcxMapIterator i = ucx_map_iterator(map); 89 UcxMapIterator i = ucx_map_iterator(map);
89 int check = 0; 90 int check = 0;
90 int hit = 0; 91 int hit = 0;
91 92
92 UCX_MAP_FOREACH(int*, v, map, i) { 93 UCX_MAP_FOREACH(int*, v, map, i) {
93 check += *v; 94 check += *v;
94 hit++; 95 hit++;
95 } 96 }
96 97
97 UCX_TEST_ASSERT(hit == 4, "test1: wrong number of hits"); 98 UCX_TEST_ASSERT(hit == 4, "test1: wrong number of hits");
98 UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test1: wrong result"); 99 UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test1: wrong result");
99 100
100 ucx_map_free(map); 101 ucx_map_free(map);
101 102
102 map = ucx_map_new(1); 103 map = ucx_map_new(1);
103 ucx_map_cstr_put(map, "v1", &v1); 104 ucx_map_cstr_put(map, "v1", &v1);
104 ucx_map_cstr_put(map, "v2", &v2); 105 ucx_map_cstr_put(map, "v2", &v2);

mercurial