|
@@ -2,10 +2,14 @@
|
|
|
#include "core/HashMap.h"
|
|
|
#include "core/Utility.h"
|
|
|
|
|
|
-#define INT_MAP CORE_HASH_MAP(sizeof(int), sizeof(int), coreHash, coreEqual)
|
|
|
+static CoreHashMap createIntMap() {
|
|
|
+ CoreHashMap map;
|
|
|
+ coreInitHashMap(&map, sizeof(int), sizeof(int));
|
|
|
+ return map;
|
|
|
+}
|
|
|
|
|
|
static CoreHashMap getTestIntMap() {
|
|
|
- CoreHashMap map = INT_MAP;
|
|
|
+ CoreHashMap map = createIntMap();
|
|
|
coreHashMapPut(&map, int, 1, int, 3);
|
|
|
coreHashMapPut(&map, int, 2, int, 4);
|
|
|
coreHashMapPut(&map, int, 3, int, 5);
|
|
@@ -28,7 +32,7 @@ static void checkIntMap(CoreHashMap* map) {
|
|
|
}
|
|
|
|
|
|
static void testAdd() {
|
|
|
- CoreHashMap map = INT_MAP;
|
|
|
+ CoreHashMap map = createIntMap();
|
|
|
coreHashMapPut(&map, int, 5, int, 4);
|
|
|
int* value = coreHashMapSearch(&map, int, 5, int);
|
|
|
if(CORE_TEST_NOT_NULL(value)) {
|
|
@@ -58,7 +62,7 @@ static void testSearch() {
|
|
|
}
|
|
|
|
|
|
static void testSearchEmpty() {
|
|
|
- CoreHashMap map = INT_MAP;
|
|
|
+ CoreHashMap map = createIntMap();
|
|
|
CORE_TEST_NULL(coreHashMapSearch(&map, int, 6, int));
|
|
|
coreDestroyHashMap(&map);
|
|
|
}
|
|
@@ -86,7 +90,7 @@ static void testClear() {
|
|
|
}
|
|
|
|
|
|
static void testClearEmpty() {
|
|
|
- CoreHashMap map = INT_MAP;
|
|
|
+ CoreHashMap map = createIntMap();
|
|
|
coreClearHashMap(&map);
|
|
|
coreDestroyHashMap(&map);
|
|
|
}
|
|
@@ -128,19 +132,17 @@ static void testToString() {
|
|
|
}
|
|
|
|
|
|
static void testEntryForEach() {
|
|
|
- CoreHashMap map = INT_MAP;
|
|
|
+ CoreHashMap map = createIntMap();
|
|
|
coreHashMapPut(&map, int, 0, int, -1);
|
|
|
coreHashMapPut(&map, int, 5, int, 4);
|
|
|
coreHashMapPut(&map, int, 10, int, 3);
|
|
|
coreHashMapPut(&map, int, 15, int, 2);
|
|
|
|
|
|
int counter = 0;
|
|
|
- CoreHashMapIterator i = CORE_HASH_MAP_ITERATOR(&map);
|
|
|
- while(true) {
|
|
|
+ CoreHashMapIterator i;
|
|
|
+ coreInitHashMapIterator(&i, &map);
|
|
|
+ while(coreHashMapHasNext(&i)) {
|
|
|
CoreHashMapNode* n = coreHashMapNext(&i);
|
|
|
- if(n == nullptr) {
|
|
|
- break;
|
|
|
- }
|
|
|
counter += coreHashMapKey(n, int) + coreHashMapValue(n, int);
|
|
|
}
|
|
|
CORE_TEST_INT(38, counter);
|
|
@@ -149,7 +151,7 @@ static void testEntryForEach() {
|
|
|
}
|
|
|
|
|
|
static void testInvalidPut() {
|
|
|
- CoreHashMap map = INT_MAP;
|
|
|
+ CoreHashMap map = createIntMap();
|
|
|
|
|
|
char buffer[128];
|
|
|
coreToStringHashMap(&map, buffer, sizeof(buffer), coreToStringInt,
|
|
@@ -180,7 +182,7 @@ static void testAddCollisions() {
|
|
|
}
|
|
|
|
|
|
static void testRemove() {
|
|
|
- CoreHashMap map = INT_MAP;
|
|
|
+ CoreHashMap map = createIntMap();
|
|
|
coreHashMapPut(&map, int, 1, int, 3);
|
|
|
coreHashMapPut(&map, int, 2, int, 4);
|
|
|
coreHashMapPut(&map, int, 3, int, 5);
|
|
@@ -216,8 +218,8 @@ typedef struct {
|
|
|
} A;
|
|
|
|
|
|
static void testSearchStruct() {
|
|
|
- CoreHashMap map =
|
|
|
- CORE_HASH_MAP(sizeof(A), sizeof(int), coreHash, coreEqual);
|
|
|
+ CoreHashMap map;
|
|
|
+ coreInitHashMap(&map, sizeof(A), sizeof(int));
|
|
|
A a = {1, 2};
|
|
|
A b = {1, 3};
|
|
|
A c = {0, 0};
|
|
@@ -245,8 +247,8 @@ static void testSearchStruct() {
|
|
|
}
|
|
|
|
|
|
static void testSearchSize() {
|
|
|
- CoreHashMap map =
|
|
|
- CORE_HASH_MAP(sizeof(size_t), sizeof(int), coreHash, coreEqual);
|
|
|
+ CoreHashMap map;
|
|
|
+ coreInitHashMap(&map, sizeof(size_t), sizeof(int));
|
|
|
CORE_TEST_NULL(coreHashMapSearch(&map, size_t, 0, int));
|
|
|
CORE_TEST_NULL(coreHashMapSearch(&map, size_t, 1, int));
|
|
|
CORE_TEST_NULL(coreHashMapSearch(&map, size_t, 2, int));
|