2018-01-14 09:47:39 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* ReactPhysics3D physics library, http://www.reactphysics3d.com *
|
|
|
|
* Copyright (c) 2010-2016 Daniel Chappuis *
|
|
|
|
*********************************************************************************
|
|
|
|
* *
|
|
|
|
* This software is provided 'as-is', without any express or implied warranty. *
|
|
|
|
* In no event will the authors be held liable for any damages arising from the *
|
|
|
|
* use of this software. *
|
|
|
|
* *
|
|
|
|
* Permission is granted to anyone to use this software for any purpose, *
|
|
|
|
* including commercial applications, and to alter it and redistribute it *
|
|
|
|
* freely, subject to the following restrictions: *
|
|
|
|
* *
|
|
|
|
* 1. The origin of this software must not be misrepresented; you must not claim *
|
|
|
|
* that you wrote the original software. If you use this software in a *
|
|
|
|
* product, an acknowledgment in the product documentation would be *
|
|
|
|
* appreciated but is not required. *
|
|
|
|
* *
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be *
|
|
|
|
* misrepresented as being the original software. *
|
|
|
|
* *
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution. *
|
|
|
|
* *
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
#ifndef TEST_MAP_H
|
|
|
|
#define TEST_MAP_H
|
|
|
|
|
|
|
|
// Libraries
|
|
|
|
#include "Test.h"
|
|
|
|
#include "containers/Map.h"
|
|
|
|
#include "memory/DefaultAllocator.h"
|
|
|
|
|
2018-01-26 16:34:26 +00:00
|
|
|
// Key to test map with always same hash values
|
|
|
|
namespace reactphysics3d {
|
|
|
|
struct TestKey {
|
|
|
|
int key;
|
|
|
|
|
|
|
|
TestKey(int k) :key(k) {}
|
|
|
|
|
|
|
|
bool operator==(const TestKey& testKey) const {
|
|
|
|
return key == testKey.key;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hash function for struct VerticesPair
|
|
|
|
namespace std {
|
|
|
|
|
|
|
|
template <> struct hash<reactphysics3d::TestKey> {
|
|
|
|
|
|
|
|
size_t operator()(const reactphysics3d::TestKey& key) const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-01-14 09:47:39 +00:00
|
|
|
/// Reactphysics3D namespace
|
|
|
|
namespace reactphysics3d {
|
|
|
|
|
|
|
|
// Class TestMap
|
|
|
|
/**
|
|
|
|
* Unit test for the Map class
|
|
|
|
*/
|
|
|
|
class TestMap : public Test {
|
|
|
|
|
|
|
|
private :
|
|
|
|
|
|
|
|
// ---------- Atributes ---------- //
|
|
|
|
|
|
|
|
DefaultAllocator mAllocator;
|
|
|
|
|
|
|
|
public :
|
|
|
|
|
|
|
|
// ---------- Methods ---------- //
|
|
|
|
|
|
|
|
/// Constructor
|
|
|
|
TestMap(const std::string& name) : Test(name) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Run the tests
|
|
|
|
void run() {
|
|
|
|
|
|
|
|
testConstructors();
|
|
|
|
testReserve();
|
|
|
|
testAddRemoveClear();
|
|
|
|
testContainsKey();
|
2018-01-19 06:55:55 +00:00
|
|
|
testFind();
|
2018-01-14 09:47:39 +00:00
|
|
|
testIndexing();
|
|
|
|
testEquality();
|
|
|
|
testAssignment();
|
2018-01-19 06:55:55 +00:00
|
|
|
testIterators();
|
2018-01-14 09:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void testConstructors() {
|
|
|
|
|
|
|
|
// ----- Constructors ----- //
|
|
|
|
|
|
|
|
Map<int, std::string> map1(mAllocator);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1.capacity() == 0);
|
|
|
|
rp3d_test(map1.size() == 0);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
Map<int, std::string> map2(mAllocator, 100);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map2.capacity() >= 100);
|
|
|
|
rp3d_test(map2.size() == 0);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
// ----- Copy Constructors ----- //
|
|
|
|
Map<int, std::string> map3(map1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map3.capacity() == map1.capacity());
|
|
|
|
rp3d_test(map3.size() == map1.size());
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
Map<int, int> map4(mAllocator);
|
2018-02-05 06:41:02 +00:00
|
|
|
map4.add(Pair<int, int>(1, 10));
|
|
|
|
map4.add(Pair<int, int>(2, 20));
|
|
|
|
map4.add(Pair<int, int>(3, 30));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map4.capacity() >= 3);
|
|
|
|
rp3d_test(map4.size() == 3);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
Map<int, int> map5(map4);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map5.capacity() == map4.capacity());
|
|
|
|
rp3d_test(map5.size() == map4.size());
|
|
|
|
rp3d_test(map5[1] == 10);
|
|
|
|
rp3d_test(map5[2] == 20);
|
|
|
|
rp3d_test(map5[3] == 30);
|
2018-01-14 09:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void testReserve() {
|
|
|
|
|
|
|
|
Map<int, std::string> map1(mAllocator);
|
|
|
|
map1.reserve(15);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1.capacity() >= 15);
|
2018-02-05 06:41:02 +00:00
|
|
|
map1.add(Pair<int, std::string>(1, "test1"));
|
|
|
|
map1.add(Pair<int, std::string>(2, "test2"));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1.capacity() >= 15);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
map1.reserve(10);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1.capacity() >= 15);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
map1.reserve(100);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1.capacity() >= 100);
|
|
|
|
rp3d_test(map1[1] == "test1");
|
|
|
|
rp3d_test(map1[2] == "test2");
|
2018-01-14 09:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void testAddRemoveClear() {
|
|
|
|
|
|
|
|
// ----- Test add() ----- //
|
|
|
|
|
|
|
|
Map<int, int> map1(mAllocator);
|
2018-02-05 06:41:02 +00:00
|
|
|
map1.add(Pair<int, int>(1, 10));
|
|
|
|
map1.add(Pair<int, int>(8, 80));
|
|
|
|
map1.add(Pair<int, int>(13, 130));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1[1] == 10);
|
|
|
|
rp3d_test(map1[8] == 80);
|
|
|
|
rp3d_test(map1[13] == 130);
|
|
|
|
rp3d_test(map1.size() == 3);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
Map<int, int> map2(mAllocator, 15);
|
|
|
|
for (int i = 0; i < 1000000; i++) {
|
2018-02-05 06:41:02 +00:00
|
|
|
map2.add(Pair<int, int>(i, i * 100));
|
2018-01-14 09:47:39 +00:00
|
|
|
}
|
|
|
|
bool isValid = true;
|
|
|
|
for (int i = 0; i < 1000000; i++) {
|
|
|
|
if (map2[i] != i * 100) isValid = false;
|
|
|
|
}
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(isValid);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
map1.remove(1);
|
2018-02-05 06:41:02 +00:00
|
|
|
map1.add(Pair<int, int>(1, 10));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1.size() == 3);
|
|
|
|
rp3d_test(map1[1] == 10);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
2018-02-05 06:41:02 +00:00
|
|
|
map1.add(Pair<int, int>(56, 34));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1[56] == 34);
|
|
|
|
rp3d_test(map1.size() == 4);
|
2018-02-05 06:41:02 +00:00
|
|
|
map1.add(Pair<int, int>(56, 13), true);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1[56] == 13);
|
|
|
|
rp3d_test(map1.size() == 4);
|
2018-01-26 16:34:26 +00:00
|
|
|
|
2018-01-14 09:47:39 +00:00
|
|
|
// ----- Test remove() ----- //
|
|
|
|
|
|
|
|
map1.remove(1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!map1.containsKey(1));
|
|
|
|
rp3d_test(map1.containsKey(8));
|
|
|
|
rp3d_test(map1.containsKey(13));
|
|
|
|
rp3d_test(map1.size() == 3);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
map1.remove(13);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1.containsKey(8));
|
|
|
|
rp3d_test(!map1.containsKey(13));
|
|
|
|
rp3d_test(map1.size() == 2);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
map1.remove(8);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!map1.containsKey(8));
|
|
|
|
rp3d_test(map1.size() == 1);
|
2018-01-26 16:34:26 +00:00
|
|
|
|
2018-02-03 19:48:08 +00:00
|
|
|
auto it = map1.remove(56);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!map1.containsKey(56));
|
|
|
|
rp3d_test(map1.size() == 0);
|
|
|
|
rp3d_test(it == map1.end());
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
isValid = true;
|
|
|
|
for (int i = 0; i < 1000000; i++) {
|
|
|
|
map2.remove(i);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 1000000; i++) {
|
|
|
|
if (map2.containsKey(i)) isValid = false;
|
|
|
|
}
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(isValid);
|
|
|
|
rp3d_test(map2.size() == 0);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
Map<int, int> map3(mAllocator);
|
|
|
|
for (int i=0; i < 1000000; i++) {
|
2018-02-05 06:41:02 +00:00
|
|
|
map3.add(Pair<int, int>(i, i * 10));
|
2018-01-14 09:47:39 +00:00
|
|
|
map3.remove(i);
|
|
|
|
}
|
|
|
|
|
2018-02-05 06:41:02 +00:00
|
|
|
map3.add(Pair<int, int>(1, 10));
|
|
|
|
map3.add(Pair<int, int>(2, 20));
|
|
|
|
map3.add(Pair<int, int>(3, 30));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map3.size() == 3);
|
2018-02-03 19:48:08 +00:00
|
|
|
it = map3.begin();
|
2018-01-26 16:34:26 +00:00
|
|
|
map3.remove(it++);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!map3.containsKey(1));
|
|
|
|
rp3d_test(map3.size() == 2);
|
|
|
|
rp3d_test(it->second == 20);
|
2018-01-26 16:34:26 +00:00
|
|
|
|
2018-02-05 06:41:02 +00:00
|
|
|
map3.add(Pair<int, int>(56, 32));
|
|
|
|
map3.add(Pair<int, int>(23, 89));
|
2018-02-03 19:48:08 +00:00
|
|
|
for (it = map3.begin(); it != map3.end();) {
|
|
|
|
it = map3.remove(it);
|
|
|
|
}
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map3.size() == 0);
|
2018-02-03 19:48:08 +00:00
|
|
|
|
2018-01-14 09:47:39 +00:00
|
|
|
// ----- Test clear() ----- //
|
|
|
|
|
|
|
|
Map<int, int> map4(mAllocator);
|
2018-02-05 06:41:02 +00:00
|
|
|
map4.add(Pair<int, int>(2, 20));
|
|
|
|
map4.add(Pair<int, int>(4, 40));
|
|
|
|
map4.add(Pair<int, int>(6, 60));
|
2018-01-14 09:47:39 +00:00
|
|
|
map4.clear();
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map4.size() == 0);
|
2018-02-05 06:41:02 +00:00
|
|
|
map4.add(Pair<int, int>(2, 20));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map4.size() == 1);
|
|
|
|
rp3d_test(map4[2] == 20);
|
2018-01-14 09:47:39 +00:00
|
|
|
map4.clear();
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map4.size() == 0);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
Map<int, int> map5(mAllocator);
|
|
|
|
map5.clear();
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map5.size() == 0);
|
2018-01-26 16:34:26 +00:00
|
|
|
|
|
|
|
// ----- Test map with always same hash value for keys ----- //
|
|
|
|
|
|
|
|
Map<TestKey, int> map6(mAllocator);
|
|
|
|
for (int i=0; i < 1000; i++) {
|
2018-02-05 06:41:02 +00:00
|
|
|
map6.add(Pair<TestKey, int>(TestKey(i), i));
|
2018-01-26 16:34:26 +00:00
|
|
|
}
|
|
|
|
bool isTestValid = true;
|
|
|
|
for (int i=0; i < 1000; i++) {
|
|
|
|
if (map6[TestKey(i)] != i) {
|
|
|
|
isTestValid = false;
|
|
|
|
}
|
|
|
|
}
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(isTestValid);
|
2018-01-26 16:34:26 +00:00
|
|
|
for (int i=0; i < 1000; i++) {
|
|
|
|
map6.remove(TestKey(i));
|
|
|
|
}
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map6.size() == 0);
|
2018-01-14 09:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void testContainsKey() {
|
|
|
|
|
|
|
|
Map<int, int> map1(mAllocator);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!map1.containsKey(2));
|
|
|
|
rp3d_test(!map1.containsKey(4));
|
|
|
|
rp3d_test(!map1.containsKey(6));
|
2018-01-14 09:47:39 +00:00
|
|
|
|
2018-02-05 06:41:02 +00:00
|
|
|
map1.add(Pair<int, int>(2, 20));
|
|
|
|
map1.add(Pair<int, int>(4, 40));
|
|
|
|
map1.add(Pair<int, int>(6, 60));
|
2018-01-14 09:47:39 +00:00
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1.containsKey(2));
|
|
|
|
rp3d_test(map1.containsKey(4));
|
|
|
|
rp3d_test(map1.containsKey(6));
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
map1.remove(4);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!map1.containsKey(4));
|
|
|
|
rp3d_test(map1.containsKey(2));
|
|
|
|
rp3d_test(map1.containsKey(6));
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
map1.clear();
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!map1.containsKey(2));
|
|
|
|
rp3d_test(!map1.containsKey(6));
|
2018-01-14 09:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void testIndexing() {
|
|
|
|
|
|
|
|
Map<int, int> map1(mAllocator);
|
2018-02-05 06:41:02 +00:00
|
|
|
map1.add(Pair<int, int>(2, 20));
|
|
|
|
map1.add(Pair<int, int>(4, 40));
|
|
|
|
map1.add(Pair<int, int>(6, 60));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1[2] == 20);
|
|
|
|
rp3d_test(map1[4] == 40);
|
|
|
|
rp3d_test(map1[6] == 60);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
map1[2] = 10;
|
|
|
|
map1[4] = 20;
|
|
|
|
map1[6] = 30;
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1[2] == 10);
|
|
|
|
rp3d_test(map1[4] == 20);
|
|
|
|
rp3d_test(map1[6] == 30);
|
2018-01-14 09:47:39 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 06:55:55 +00:00
|
|
|
void testFind() {
|
|
|
|
|
|
|
|
Map<int, int> map1(mAllocator);
|
2018-02-05 06:41:02 +00:00
|
|
|
map1.add(Pair<int, int>(2, 20));
|
|
|
|
map1.add(Pair<int, int>(4, 40));
|
|
|
|
map1.add(Pair<int, int>(6, 60));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1.find(2)->second == 20);
|
|
|
|
rp3d_test(map1.find(4)->second == 40);
|
|
|
|
rp3d_test(map1.find(6)->second == 60);
|
|
|
|
rp3d_test(map1.find(45) == map1.end());
|
2018-01-19 06:55:55 +00:00
|
|
|
|
|
|
|
map1[2] = 10;
|
|
|
|
map1[4] = 20;
|
|
|
|
map1[6] = 30;
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1.find(2)->second == 10);
|
|
|
|
rp3d_test(map1.find(4)->second == 20);
|
|
|
|
rp3d_test(map1.find(6)->second == 30);
|
2018-01-19 06:55:55 +00:00
|
|
|
}
|
|
|
|
|
2018-01-14 09:47:39 +00:00
|
|
|
void testEquality() {
|
|
|
|
|
|
|
|
Map<std::string, int> map1(mAllocator, 10);
|
|
|
|
Map<std::string, int> map2(mAllocator, 2);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1 == map2);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
2018-02-05 06:41:02 +00:00
|
|
|
map1.add(Pair<std::string, int>("a", 1));
|
|
|
|
map1.add(Pair<std::string, int>("b", 2));
|
|
|
|
map1.add(Pair<std::string, int>("c", 3));
|
2018-01-14 09:47:39 +00:00
|
|
|
|
2018-02-05 06:41:02 +00:00
|
|
|
map2.add(Pair<std::string, int>("a", 1));
|
|
|
|
map2.add(Pair<std::string, int>("b", 2));
|
|
|
|
map2.add(Pair<std::string, int>("c", 4));
|
2018-01-14 09:47:39 +00:00
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1 == map1);
|
|
|
|
rp3d_test(map2 == map2);
|
|
|
|
rp3d_test(map1 != map2);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
map2["c"] = 3;
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1 == map2);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
Map<std::string, int> map3(mAllocator);
|
2018-02-05 06:41:02 +00:00
|
|
|
map3.add(Pair<std::string, int>("a", 1));
|
2018-01-14 09:47:39 +00:00
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1 != map3);
|
|
|
|
rp3d_test(map2 != map3);
|
2018-01-14 09:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void testAssignment() {
|
|
|
|
|
|
|
|
Map<int, int> map1(mAllocator);
|
2018-02-05 06:41:02 +00:00
|
|
|
map1.add(Pair<int, int>(1, 3));
|
|
|
|
map1.add(Pair<int, int>(2, 6));
|
|
|
|
map1.add(Pair<int, int>(10, 30));
|
2018-01-19 06:55:55 +00:00
|
|
|
|
2018-01-14 09:47:39 +00:00
|
|
|
Map<int, int> map2(mAllocator);
|
|
|
|
map2 = map1;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map2.size() == map1.size());
|
|
|
|
rp3d_test(map1 == map2);
|
|
|
|
rp3d_test(map2[1] == 3);
|
|
|
|
rp3d_test(map2[2] == 6);
|
|
|
|
rp3d_test(map2[10] == 30);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
Map<int, int> map3(mAllocator, 100);
|
|
|
|
map3 = map1;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map3.size() == map1.size());
|
|
|
|
rp3d_test(map3 == map1);
|
|
|
|
rp3d_test(map3[1] == 3);
|
|
|
|
rp3d_test(map3[2] == 6);
|
|
|
|
rp3d_test(map3[10] == 30);
|
2018-01-14 09:47:39 +00:00
|
|
|
|
|
|
|
Map<int, int> map4(mAllocator);
|
|
|
|
map3 = map4;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map3.size() == 0);
|
|
|
|
rp3d_test(map3 == map4);
|
2018-01-19 06:55:55 +00:00
|
|
|
|
2018-01-14 09:47:39 +00:00
|
|
|
Map<int, int> map5(mAllocator);
|
2018-02-05 06:41:02 +00:00
|
|
|
map5.add(Pair<int, int>(7, 8));
|
|
|
|
map5.add(Pair<int, int>(19, 70));
|
2018-01-14 09:47:39 +00:00
|
|
|
map1 = map5;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map5.size() == map1.size());
|
|
|
|
rp3d_test(map5 == map1);
|
|
|
|
rp3d_test(map1[7] == 8);
|
|
|
|
rp3d_test(map1[19] == 70);
|
2018-01-14 09:47:39 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 06:55:55 +00:00
|
|
|
void testIterators() {
|
2018-01-14 09:47:39 +00:00
|
|
|
|
2018-01-19 06:55:55 +00:00
|
|
|
Map<int, int> map1(mAllocator);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1.begin() == map1.end());
|
2018-01-19 06:55:55 +00:00
|
|
|
|
2018-02-05 06:41:02 +00:00
|
|
|
map1.add(Pair<int, int>(1, 5));
|
|
|
|
map1.add(Pair<int, int>(2, 6));
|
|
|
|
map1.add(Pair<int, int>(3, 8));
|
|
|
|
map1.add(Pair<int, int>(4, -1));
|
2018-01-19 06:55:55 +00:00
|
|
|
|
|
|
|
Map<int, int>::Iterator itBegin = map1.begin();
|
|
|
|
Map<int, int>::Iterator it = map1.begin();
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(itBegin == it);
|
2018-01-19 06:55:55 +00:00
|
|
|
|
|
|
|
int size = 0;
|
|
|
|
for (auto it = map1.begin(); it != map1.end(); ++it) {
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1.containsKey(it->first));
|
2018-01-19 06:55:55 +00:00
|
|
|
size++;
|
|
|
|
}
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(map1.size() == size);
|
2018-01-14 09:47:39 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|