Looks like no polymorphic map yet

This commit is contained in:
Dynamitos
2021-11-05 00:01:12 +01:00
parent 1b7ab9b1f1
commit dd8a835a4d
14 changed files with 188 additions and 109 deletions
-1
View File
@@ -3,7 +3,6 @@
#include "MinimalEngine.h"
#include <time.h>
#include <chrono>
#define BOOST_TEST_MODULE SeeleEngine
#include <boost/test/unit_test.hpp>
using namespace Seele;
+62 -48
View File
@@ -8,71 +8,85 @@ BOOST_AUTO_TEST_SUITE(CachedMap)
BOOST_AUTO_TEST_CASE(insert_find_basic)
{
Map<int, int> map;
map[2] = 3;
map[1] = 5;
map[6] = 4;
map[4] = 7;
BOOST_REQUIRE_EQUAL(map[2], 3);
BOOST_REQUIRE_EQUAL(map[1], 5);
BOOST_REQUIRE_EQUAL(map[6], 4);
BOOST_REQUIRE_EQUAL(map[4], 7);
map[2] = 5;
map[4] = 4;
BOOST_REQUIRE_EQUAL(map[2], 5);
BOOST_REQUIRE_EQUAL(map[4], 4);
Map<int, int> map;
map[2] = 3;
map[1] = 5;
map[6] = 4;
map[4] = 7;
BOOST_REQUIRE_EQUAL(map[2], 3);
BOOST_REQUIRE_EQUAL(map[1], 5);
BOOST_REQUIRE_EQUAL(map[6], 4);
BOOST_REQUIRE_EQUAL(map[4], 7);
map[2] = 5;
map[4] = 4;
BOOST_REQUIRE_EQUAL(map[2], 5);
BOOST_REQUIRE_EQUAL(map[4], 4);
}
BOOST_AUTO_TEST_CASE(for_each)
{
Map<int, int> map;
map[2] = 3;
map[1] = 5;
map[6] = 4;
map[4] = 7;
int count = 0;
for(auto it : map)
{
count++;
}
BOOST_REQUIRE_EQUAL(count, 4);
Map<int, int> map;
map[2] = 3;
map[1] = 5;
map[6] = 4;
map[4] = 7;
int count = 0;
for(auto it : map)
{
count++;
}
BOOST_REQUIRE_EQUAL(count, 4);
}
BOOST_AUTO_TEST_CASE(remove_entry)
{
Map<int, int> map;
map[1] = 5;
map[4] = 1;
map[2] = 6;
map[3] = 4;
map.erase(2);
BOOST_REQUIRE_EQUAL(map.size(), 3);
BOOST_REQUIRE_EQUAL(map[1], 5);
BOOST_REQUIRE_EQUAL(map[4], 1);
BOOST_REQUIRE_EQUAL(map[3], 4);
}
BOOST_AUTO_TEST_CASE(key_exists)
{
Map<int, int> map;
map[2] = 3;
BOOST_REQUIRE_EQUAL(map.exists(2), true);
BOOST_REQUIRE_EQUAL(map.exists(4), false);
map.erase(2);
BOOST_REQUIRE_EQUAL(map.exists(2), false);
Map<int, int> map;
map[2] = 3;
BOOST_REQUIRE_EQUAL(map.exists(2), true);
BOOST_REQUIRE_EQUAL(map.exists(4), false);
map.erase(2);
BOOST_REQUIRE_EQUAL(map.exists(2), false);
}
BOOST_AUTO_TEST_CASE(custom_key)
{
struct Key
{
int id;
bool operator<(const Key& other) const
{
return id < other.id;
}
};
Map<Key, int> map;
map[Key{ 2 }] = 3;
map[Key{ 3 }] = 4;
BOOST_REQUIRE_EQUAL(map[Key{ 2 }], 3);
BOOST_REQUIRE_EQUAL(map[Key{ 3 }], 4);
struct Key
{
int id;
bool operator<(const Key& other) const
{
return id < other.id;
}
};
Map<Key, int> map;
map[Key{ 2 }] = 3;
map[Key{ 3 }] = 4;
BOOST_REQUIRE_EQUAL(map[Key{ 2 }], 3);
BOOST_REQUIRE_EQUAL(map[Key{ 3 }], 4);
}
BOOST_AUTO_TEST_CASE(string_key)
{
std::map<std::string, int> map;
map["Test"] = 2;
map["Test2"] = 3;
BOOST_REQUIRE_EQUAL(map["Test"], 2);
BOOST_REQUIRE_EQUAL(map["Test2"], 3);
std::map<std::string, int> map;
map["Test"] = 2;
map["Test2"] = 3;
BOOST_REQUIRE_EQUAL(map["Test"], 2);
BOOST_REQUIRE_EQUAL(map["Test2"], 3);
}
BOOST_AUTO_TEST_SUITE_END()
+13
View File
@@ -1,5 +1,7 @@
#include "EngineTest.h"
#include "MinimalEngine.h"
#define BOOST_TEST_MODULE SeeleEngine
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
using namespace Seele;
@@ -18,6 +20,8 @@ struct TestStruct
}
uint32 data;
};
struct DeclStruct;
BOOST_AUTO_TEST_CASE(basic_refcount)
{
{
@@ -30,7 +34,16 @@ BOOST_AUTO_TEST_CASE(basic_refcount)
}
BOOST_REQUIRE_EQUAL(ptr->data, 10);
}
std::shared_ptr<DeclStruct> test;
}
struct DeclStruct
{
~DeclStruct()
{
data = 10;
}
uint32 data = 20;
};
struct DerivedStruct : public TestStruct
{