Skip to content

Instantly share code, notes, and snippets.

@ArnCarveris
Created February 26, 2018 01:52
Show Gist options
  • Save ArnCarveris/ef4957f3a7d35522500ab4864c9dba0a to your computer and use it in GitHub Desktop.
Save ArnCarveris/ef4957f3a7d35522500ab4864c9dba0a to your computer and use it in GitHub Desktop.
RuntimeFamily Test
#include <gtest/gtest.h>
#include <entt/core/family.hpp>
#include <deque>
#include <vector>
namespace entt {
class RuntimeFamily {
std::size_t value = 0;
std::vector<std::size_t> values;
std::size_t identifier() noexcept {
return value++;
}
template<typename...>
std::size_t family() noexcept {
static const std::size_t value = identifier();
std::size_t i = 0;
auto it = std::find(values.begin(), values.end(), value);
if (it == values.end())
{
values.emplace_back(value);
return values.size() - 1;
}
else
{
return it - values.begin();
}
}
public:
using family_type = std::size_t;
template<typename... Type>
family_type type() noexcept {
return family<std::decay_t<Type>...>();
}
};
}
TEST(RuntimeFamily, Functionalities) {
auto my_family = entt::RuntimeFamily();
auto your_family = entt::RuntimeFamily();
auto myFamilyType = my_family.type<struct MyFamilyType>();
auto mySameFamilyType = my_family.type<struct MyFamilyType>();
auto myOtherFamilyType = my_family.type<struct MyOtherFamilyType>();
auto myOtherFamilyType2 = my_family.type<struct MyOtherFamilyType2>();
auto yourFamilyType = your_family.type<struct YourFamilyType>();
auto yourOtherFamilyType = your_family.type<struct MyOtherFamilyType2>();
auto yourOtherFamilyType2 = your_family.type<struct MyOtherFamilyType>();
ASSERT_EQ(myFamilyType, mySameFamilyType);
ASSERT_NE(myFamilyType, myOtherFamilyType);
ASSERT_EQ(myFamilyType, yourFamilyType);
}
TEST(RuntimeFamily, Uniqueness) {
auto my_family = entt::RuntimeFamily();
ASSERT_EQ(my_family.type<int>(), my_family.type<int &>());
ASSERT_EQ(my_family.type<int>(), my_family.type<int &&>());
ASSERT_EQ(my_family.type<int>(), my_family.type<const int &>());
}
using my_family = entt::Family<struct MyFamily>;
using your_family = entt::Family<struct YourFamily>;
TEST(Family, Functionalities) {
auto myFamilyType = my_family::type<struct MyFamilyType>();
auto mySameFamilyType = my_family::type<struct MyFamilyType>();
auto myOtherFamilyType = my_family::type<struct MyOtherFamilyType>();
auto myOtherFamilyType2 = my_family::type<struct MyOtherFamilyType2>();
auto yourFamilyType = your_family::type<struct YourFamilyType>();
auto yourOtherFamilyType = your_family::type<struct MyOtherFamilyType2>();
auto yourOtherFamilyType2 = your_family::type<struct MyOtherFamilyType>();
ASSERT_EQ(myFamilyType, mySameFamilyType);
ASSERT_NE(myFamilyType, myOtherFamilyType);
ASSERT_EQ(myFamilyType, yourFamilyType);
}
TEST(Family, Uniqueness) {
ASSERT_EQ(my_family::type<int>(), my_family::type<int &>());
ASSERT_EQ(my_family::type<int>(), my_family::type<int &&>());
ASSERT_EQ(my_family::type<int>(), my_family::type<const int &>());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment