250 EXPECT_TRUE(allocator.verify()); |
250 EXPECT_TRUE(allocator.verify()); |
251 } |
251 } |
252 |
252 |
253 TEST(CxHashMap, Rehash) { |
253 TEST(CxHashMap, Rehash) { |
254 CxTestingAllocator allocator; |
254 CxTestingAllocator allocator; |
255 auto map = cxHashMapCreate(&allocator, CX_STORE_POINTERS, 8); |
255 auto map = cxHashMapCreate(&allocator, CX_STORE_POINTERS, 7); |
256 |
256 |
257 cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1"); |
257 cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1"); |
258 cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2"); |
258 cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2"); |
259 cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3"); |
259 cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3"); |
260 cxMapPut(map, cx_hash_key_str("key 4"), (void *) "val 4"); |
260 cxMapPut(map, cx_hash_key_str("foo 4"), (void *) "val 4"); |
261 cxMapPut(map, cx_hash_key_str("key 5"), (void *) "val 5"); |
261 cxMapPut(map, cx_hash_key_str("key 5"), (void *) "val 5"); |
262 cxMapPut(map, cx_hash_key_str("key 6"), (void *) "val 6"); |
262 cxMapPut(map, cx_hash_key_str("key 6"), (void *) "val 6"); |
263 cxMapPut(map, cx_hash_key_str("key 7"), (void *) "val 7"); |
263 cxMapPut(map, cx_hash_key_str("bar 7"), (void *) "val 7"); |
|
264 cxMapPut(map, cx_hash_key_str("key 8"), (void *) "val 8"); |
|
265 cxMapPut(map, cx_hash_key_str("key 9"), (void *) "val 9"); |
|
266 cxMapPut(map, cx_hash_key_str("key 10"), (void *) "val 10"); |
264 |
267 |
265 int result = cxMapRehash(map); |
268 int result = cxMapRehash(map); |
266 EXPECT_EQ(result, 0); |
269 EXPECT_EQ(result, 0); |
267 EXPECT_EQ(reinterpret_cast<struct cx_hash_map_s *>(map)->bucket_count, 17); |
270 EXPECT_EQ(reinterpret_cast<struct cx_hash_map_s *>(map)->bucket_count, 25); |
268 EXPECT_EQ(map->size, 7); |
271 EXPECT_EQ(map->size, 10); |
269 |
272 |
270 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 1")), "val 1"), 0); |
273 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 1")), "val 1"), 0); |
271 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 2")), "val 2"), 0); |
274 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 2")), "val 2"), 0); |
272 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 3")), "val 3"), 0); |
275 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 3")), "val 3"), 0); |
273 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 4")), "val 4"), 0); |
276 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("foo 4")), "val 4"), 0); |
274 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 5")), "val 5"), 0); |
277 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 5")), "val 5"), 0); |
275 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 6")), "val 6"), 0); |
278 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 6")), "val 6"), 0); |
276 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 7")), "val 7"), 0); |
279 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("bar 7")), "val 7"), 0); |
|
280 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 8")), "val 8"), 0); |
|
281 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 9")), "val 9"), 0); |
|
282 EXPECT_EQ(strcmp((char *) cxMapGet(map, cx_hash_key_str("key 10")), "val 10"), 0); |
277 |
283 |
278 cxMapDestroy(map); |
284 cxMapDestroy(map); |
279 EXPECT_TRUE(allocator.verify()); |
285 EXPECT_TRUE(allocator.verify()); |
280 } |
286 } |
281 |
287 |