|
@@ -8,7 +8,7 @@ using IntMap = Core::ProbingHashMap<int, int>;
|
|
|
|
|
|
static void testAdd() {
|
|
|
IntMap map;
|
|
|
- CORE_TEST_ERROR(map.add(5, 4));
|
|
|
+ map.add(5, 4);
|
|
|
int* value = map.search(5);
|
|
|
CORE_TEST_NOT_NULL(value);
|
|
|
if(value != nullptr) {
|
|
@@ -18,9 +18,7 @@ static void testAdd() {
|
|
|
|
|
|
static void testMultipleAdd() {
|
|
|
IntMap map;
|
|
|
- CORE_TEST_ERROR(map.add(5, 4));
|
|
|
- CORE_TEST_ERROR(map.add(10, 3));
|
|
|
- CORE_TEST_ERROR(map.add(15, 2));
|
|
|
+ map.add(5, 4).add(10, 3).add(15, 2);
|
|
|
CORE_TEST_TRUE(map.contains(5));
|
|
|
CORE_TEST_TRUE(map.contains(10));
|
|
|
CORE_TEST_TRUE(map.contains(15));
|
|
@@ -40,16 +38,13 @@ static void testMultipleAdd() {
|
|
|
static void testSearch() {
|
|
|
IntMap map;
|
|
|
CORE_TEST_NULL(map.search(6));
|
|
|
- CORE_TEST_ERROR(map.add(5, 4));
|
|
|
- CORE_TEST_ERROR(map.add(10, 3));
|
|
|
- CORE_TEST_ERROR(map.add(15, 2));
|
|
|
+ map.add(5, 4).add(10, 3).add(15, 2);
|
|
|
CORE_TEST_NULL(map.search(6));
|
|
|
}
|
|
|
|
|
|
static void testAddReplace() {
|
|
|
IntMap map;
|
|
|
- CORE_TEST_ERROR(map.add(5, 4));
|
|
|
- CORE_TEST_ERROR(map.add(5, 10));
|
|
|
+ map.add(5, 4).add(5, 10);
|
|
|
CORE_TEST_TRUE(map.contains(5));
|
|
|
int* a = map.search(5);
|
|
|
CORE_TEST_NOT_NULL(a);
|
|
@@ -60,8 +55,7 @@ static void testAddReplace() {
|
|
|
|
|
|
static void testClear() {
|
|
|
IntMap map;
|
|
|
- CORE_TEST_ERROR(map.add(5, 4));
|
|
|
- CORE_TEST_ERROR(map.add(4, 10));
|
|
|
+ map.add(5, 4).add(4, 10);
|
|
|
map.clear();
|
|
|
CORE_TEST_FALSE(map.contains(5));
|
|
|
CORE_TEST_FALSE(map.contains(4));
|
|
@@ -71,7 +65,7 @@ static void testOverflow(bool light) {
|
|
|
int limit = light ? 10000 : 100000;
|
|
|
IntMap map;
|
|
|
for(int i = 0; i < limit; i++) {
|
|
|
- CORE_TEST_ERROR(map.add(i, i));
|
|
|
+ map.add(i, i);
|
|
|
}
|
|
|
for(int i = 0; i < limit; i++) {
|
|
|
CORE_TEST_TRUE(map.contains(i));
|
|
@@ -125,13 +119,11 @@ static void testEmplace() {
|
|
|
Core::ProbingHashMap<int, ProbingHashMapTestStruct> map;
|
|
|
|
|
|
ProbingHashMapTestStruct* ar = nullptr;
|
|
|
- CORE_TEST_ERROR(map.tryEmplace(ar, 0, 3, 4));
|
|
|
- CORE_TEST_ERROR(map.tryEmplace(ar, 3, 4, 5));
|
|
|
- CORE_TEST_ERROR(map.tryEmplace(ar, 20, 5, 6));
|
|
|
- CORE_TEST_EQUAL(Core::ErrorCode::EXISTING_KEY,
|
|
|
- map.tryEmplace(ar, 3, 6, 7));
|
|
|
- CORE_TEST_EQUAL(Core::ErrorCode::EXISTING_KEY,
|
|
|
- map.tryEmplace(ar, 20, 7, 8));
|
|
|
+ CORE_TEST_TRUE(map.tryEmplace(ar, 0, 3, 4));
|
|
|
+ CORE_TEST_TRUE(map.tryEmplace(ar, 3, 4, 5));
|
|
|
+ CORE_TEST_TRUE(map.tryEmplace(ar, 20, 5, 6));
|
|
|
+ CORE_TEST_FALSE(map.tryEmplace(ar, 3, 6, 7));
|
|
|
+ CORE_TEST_FALSE(map.tryEmplace(ar, 20, 7, 8));
|
|
|
|
|
|
ProbingHashMapTestStruct* a = map.search(0);
|
|
|
ProbingHashMapTestStruct* b = map.search(3);
|
|
@@ -152,15 +144,13 @@ static void testEmplace() {
|
|
|
|
|
|
static void testToString1() {
|
|
|
IntMap map;
|
|
|
- CORE_TEST_ERROR(map.add(1, 3));
|
|
|
- CORE_TEST_ERROR(map.add(2, 4));
|
|
|
- CORE_TEST_ERROR(map.add(3, 5));
|
|
|
+ map.add(1, 3).add(2, 4).add(3, 5);
|
|
|
CORE_TEST_STRING("[2 = 4, 1 = 3, 3 = 5]", map);
|
|
|
}
|
|
|
|
|
|
static void testToString2() {
|
|
|
IntMap map;
|
|
|
- CORE_TEST_ERROR(map.add(1, 3));
|
|
|
+ map.add(1, 3);
|
|
|
CORE_TEST_STRING("[1 = 3]", map);
|
|
|
}
|
|
|
|
|
@@ -171,11 +161,8 @@ static void testToString3() {
|
|
|
|
|
|
static void testCopy() {
|
|
|
IntMap map;
|
|
|
- CORE_TEST_ERROR(map.add(1, 3));
|
|
|
- CORE_TEST_ERROR(map.add(2, 4));
|
|
|
- CORE_TEST_ERROR(map.add(3, 5));
|
|
|
- IntMap copy;
|
|
|
- CORE_TEST_ERROR(copy.copyFrom(map));
|
|
|
+ map.add(1, 3).add(2, 4).add(3, 5);
|
|
|
+ IntMap copy = map;
|
|
|
|
|
|
int* a[6] = {map.search(1), map.search(2), map.search(3),
|
|
|
copy.search(1), copy.search(2), copy.search(3)};
|
|
@@ -190,9 +177,7 @@ static void testCopy() {
|
|
|
|
|
|
static void testMove() {
|
|
|
IntMap map;
|
|
|
- CORE_TEST_ERROR(map.add(1, 3));
|
|
|
- CORE_TEST_ERROR(map.add(2, 4));
|
|
|
- CORE_TEST_ERROR(map.add(3, 5));
|
|
|
+ map.add(1, 3).add(2, 4).add(3, 5);
|
|
|
IntMap move(Core::move(map));
|
|
|
|
|
|
int* a = move.search(1);
|
|
@@ -212,9 +197,7 @@ static void testMove() {
|
|
|
|
|
|
static void testMoveAssignment() {
|
|
|
IntMap map;
|
|
|
- CORE_TEST_ERROR(map.add(1, 3));
|
|
|
- CORE_TEST_ERROR(map.add(2, 4));
|
|
|
- CORE_TEST_ERROR(map.add(3, 5));
|
|
|
+ map.add(1, 3).add(2, 4).add(3, 5);
|
|
|
|
|
|
IntMap move;
|
|
|
move = Core::move(map);
|
|
@@ -236,9 +219,7 @@ static void testMoveAssignment() {
|
|
|
|
|
|
static void testEntryForEach() {
|
|
|
IntMap map;
|
|
|
- CORE_TEST_ERROR(map.add(5, 4));
|
|
|
- CORE_TEST_ERROR(map.add(10, 3));
|
|
|
- CORE_TEST_ERROR(map.add(15, 2));
|
|
|
+ map.add(5, 4).add(10, 3).add(15, 2);
|
|
|
|
|
|
int counter = 0;
|
|
|
for(auto entry : map) {
|
|
@@ -256,9 +237,7 @@ static void testEntryForEach() {
|
|
|
|
|
|
static void testKeyForEach() {
|
|
|
IntMap map;
|
|
|
- CORE_TEST_ERROR(map.add(5, 4));
|
|
|
- CORE_TEST_ERROR(map.add(10, 3));
|
|
|
- CORE_TEST_ERROR(map.add(15, 2));
|
|
|
+ map.add(5, 4).add(10, 3).add(15, 2);
|
|
|
|
|
|
int counter = 0;
|
|
|
for(const int& key : map.getKeys()) {
|
|
@@ -276,9 +255,7 @@ static void testKeyForEach() {
|
|
|
|
|
|
static void testValueForEach() {
|
|
|
IntMap map;
|
|
|
- CORE_TEST_ERROR(map.add(5, 4));
|
|
|
- CORE_TEST_ERROR(map.add(10, 3));
|
|
|
- CORE_TEST_ERROR(map.add(15, 2));
|
|
|
+ map.add(5, 4).add(10, 3).add(15, 2);
|
|
|
|
|
|
int counter = 0;
|
|
|
for(int& value : map.getValues()) {
|
|
@@ -297,7 +274,7 @@ static void testValueForEach() {
|
|
|
template<typename T>
|
|
|
static void testType() {
|
|
|
Core::ProbingHashMap<T, int> m;
|
|
|
- CORE_TEST_ERROR(m.add(T(), 3));
|
|
|
+ m.add(T(), 3);
|
|
|
}
|
|
|
|
|
|
static void testTypes() {
|
|
@@ -314,49 +291,21 @@ static void testTypes() {
|
|
|
testType<unsigned long long>();
|
|
|
}
|
|
|
|
|
|
-static void testOutOfMemory() {
|
|
|
-#ifdef ERROR_SIMULATOR
|
|
|
- IntMap map;
|
|
|
- int memFails = 0;
|
|
|
- for(int i = 0; i < 40; i++) {
|
|
|
- Core::Fail::leftAllocations = i;
|
|
|
- int* v = nullptr;
|
|
|
- Core::Error e = map.put(v, 1, 1);
|
|
|
- if(e == Core::ErrorCode::OUT_OF_MEMORY) {
|
|
|
- memFails++;
|
|
|
- }
|
|
|
- }
|
|
|
- int* found = map.search(1);
|
|
|
- if(CORE_TEST_NOT_NULL(found)) {
|
|
|
- CORE_TEST_EQUAL(1, *found);
|
|
|
- }
|
|
|
- Core::Fail::leftAllocations = -1;
|
|
|
- CORE_TEST_TRUE(memFails != 0);
|
|
|
-#endif
|
|
|
-}
|
|
|
-
|
|
|
static void testInsertInvalid() {
|
|
|
IntMap map;
|
|
|
int* v;
|
|
|
- CORE_TEST_EQUAL(Core::ErrorCode::INVALID_ARGUMENT,
|
|
|
- map.tryEmplace(v, Core::emptyValue<int>(), 2));
|
|
|
- CORE_TEST_EQUAL(Core::ErrorCode::INVALID_ARGUMENT,
|
|
|
- map.put(v, Core::emptyValue<int>(), 2));
|
|
|
+ CORE_TEST_TRUE(map.tryEmplace(v, Core::emptyValue<int>(), 2));
|
|
|
+ CORE_TEST_EQUAL(3, map.put(Core::emptyValue<int>(), 3));
|
|
|
}
|
|
|
|
|
|
static void testAddCollisions() {
|
|
|
IntMap map;
|
|
|
for(int i = 0; i < 8; i++) {
|
|
|
- CORE_TEST_ERROR(map.add(i * 16, i));
|
|
|
+ map.add(i * 16, i);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static void testLargeRehash() {
|
|
|
- IntMap map;
|
|
|
- CORE_TEST_EQUAL(Core::ErrorCode::CAPACITY_REACHED, map.rehash(1llu << 50));
|
|
|
-}
|
|
|
-
|
|
|
-void Core::testProbingHashMap(bool light, bool outOfMemoryTest) {
|
|
|
+void Core::testProbingHashMap(bool light) {
|
|
|
testAdd();
|
|
|
testMultipleAdd();
|
|
|
testSearch();
|
|
@@ -374,10 +323,6 @@ void Core::testProbingHashMap(bool light, bool outOfMemoryTest) {
|
|
|
testKeyForEach();
|
|
|
testValueForEach();
|
|
|
testTypes();
|
|
|
- if(outOfMemoryTest) {
|
|
|
- testOutOfMemory();
|
|
|
- }
|
|
|
testInsertInvalid();
|
|
|
testAddCollisions();
|
|
|
- testLargeRehash();
|
|
|
}
|