diff options
-rw-r--r-- | entityx/Entity.h | 4 | ||||
-rw-r--r--[-rwxr-xr-x] | entityx/Entity_test.cc | 28 |
2 files changed, 32 insertions, 0 deletions
diff --git a/entityx/Entity.h b/entityx/Entity.h index 7312e25..e30f87e 100644 --- a/entityx/Entity.h +++ b/entityx/Entity.h @@ -102,6 +102,10 @@ public: return !(other == *this); } + bool operator < (const Entity &other) const { + return other.id_ < id_; + } + /** * Is this Entity handle valid? * diff --git a/entityx/Entity_test.cc b/entityx/Entity_test.cc index ee1ccac..9140773 100755..100644 --- a/entityx/Entity_test.cc +++ b/entityx/Entity_test.cc @@ -15,6 +15,8 @@ #include <string> #include <utility> #include <vector> +#include <set> +#include <map> #include "entityx/3rdparty/catch.hpp" #include "entityx/Entity.h" @@ -23,6 +25,9 @@ using namespace entityx; using std::ostream; using std::vector; +using std::set; +using std::map; +using std::pair; using std::string; template <typename T> @@ -491,3 +496,26 @@ TEST_CASE_METHOD(EntityManagerFixture, "TestDeleteEntityWithNoComponents") { Entity b = em.create(); b.destroy(); } + +TEST_CASE_METHOD(EntityManagerFixture, "TestEntityInStdSet") { + Entity a = em.create(); + Entity b = em.create(); + Entity c = em.create(); + set<Entity> entitySet; + REQUIRE(entitySet.insert(a).second); + REQUIRE(entitySet.insert(b).second); + REQUIRE(entitySet.insert(c).second); +} + +TEST_CASE_METHOD(EntityManagerFixture, "TestEntityInStdMap") { + Entity a = em.create(); + Entity b = em.create(); + Entity c = em.create(); + map<Entity, int> entityMap; + REQUIRE(entityMap.insert(pair<Entity, int>(a, 1)).second); + REQUIRE(entityMap.insert(pair<Entity, int>(b, 2)).second); + REQUIRE(entityMap.insert(pair<Entity, int>(c, 3)).second); + REQUIRE(entityMap[a] == 1); + REQUIRE(entityMap[b] == 2); + REQUIRE(entityMap[c] == 3); +} |