| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 | 
							- #include "../../src/ErrorSimulator.hpp"
 
- #include "../Tests.hpp"
 
- #include "core/data/Components.hpp"
 
- template class Core::Components<int>;
 
- using IntComponent = Core::Components<int>;
 
- static void testAddForEach() {
 
-     IntComponent c;
 
-     int* i1 = nullptr;
 
-     int* i2 = nullptr;
 
-     int* i3 = nullptr;
 
-     CORE_TEST_ERROR(c.put(i1, 1, 10));
 
-     CORE_TEST_ERROR(c.put(i2, 5, 20));
 
-     CORE_TEST_ERROR(c.put(i3, 10, 30));
 
-     CORE_TEST_NOT_NULL(i1);
 
-     CORE_TEST_NOT_NULL(i2);
 
-     CORE_TEST_NOT_NULL(i3);
 
-     if(i1 != nullptr && i2 != nullptr && i3 != nullptr) {
 
-         CORE_TEST_EQUAL(10, *i1);
 
-         CORE_TEST_EQUAL(20, *i2);
 
-         CORE_TEST_EQUAL(30, *i3);
 
-     }
 
-     auto iter = c.entities();
 
-     auto pos = iter.begin();
 
-     auto end = iter.end();
 
-     CORE_TEST_EQUAL(1, (*pos).entity);
 
-     CORE_TEST_EQUAL(10, (*pos).component);
 
-     CORE_TEST_TRUE(pos != end);
 
-     ++pos;
 
-     CORE_TEST_EQUAL(5, (*pos).entity);
 
-     CORE_TEST_EQUAL(20, (*pos).component);
 
-     CORE_TEST_TRUE(pos != end);
 
-     ++pos;
 
-     CORE_TEST_EQUAL(10, (*pos).entity);
 
-     CORE_TEST_EQUAL(30, (*pos).component);
 
-     CORE_TEST_TRUE(pos != end);
 
-     ++pos;
 
-     CORE_TEST_FALSE(pos != end);
 
- }
 
- static void testAddConstForEach() {
 
-     IntComponent c;
 
-     int* i1 = nullptr;
 
-     int* i2 = nullptr;
 
-     int* i3 = nullptr;
 
-     CORE_TEST_ERROR(c.put(i1, 1, 10));
 
-     CORE_TEST_ERROR(c.put(i2, 5, 20));
 
-     CORE_TEST_ERROR(c.put(i3, 10, 30));
 
-     auto iter = static_cast<const IntComponent&>(c).entities();
 
-     auto pos = iter.begin();
 
-     auto end = iter.end();
 
-     CORE_TEST_EQUAL(1, (*pos).entity);
 
-     CORE_TEST_EQUAL(10, (*pos).component);
 
-     CORE_TEST_TRUE(pos != end);
 
-     ++pos;
 
-     CORE_TEST_EQUAL(5, (*pos).entity);
 
-     CORE_TEST_EQUAL(20, (*pos).component);
 
-     CORE_TEST_TRUE(pos != end);
 
-     ++pos;
 
-     CORE_TEST_EQUAL(10, (*pos).entity);
 
-     CORE_TEST_EQUAL(30, (*pos).component);
 
-     CORE_TEST_TRUE(pos != end);
 
-     ++pos;
 
-     CORE_TEST_FALSE(pos != end);
 
- }
 
- static void testAddComponentForEach() {
 
-     IntComponent c;
 
-     int* i1 = nullptr;
 
-     int* i2 = nullptr;
 
-     int* i3 = nullptr;
 
-     CORE_TEST_ERROR(c.put(i1, 1, 10));
 
-     CORE_TEST_ERROR(c.put(i2, 5, 20));
 
-     CORE_TEST_ERROR(c.put(i3, 10, 30));
 
-     CORE_TEST_NOT_NULL(i1);
 
-     CORE_TEST_NOT_NULL(i2);
 
-     CORE_TEST_NOT_NULL(i3);
 
-     if(i1 != nullptr && i2 != nullptr && i3 != nullptr) {
 
-         CORE_TEST_EQUAL(10, *i1);
 
-         CORE_TEST_EQUAL(20, *i2);
 
-         CORE_TEST_EQUAL(30, *i3);
 
-     }
 
-     auto iter = c.begin();
 
-     CORE_TEST_EQUAL(10, *iter);
 
-     CORE_TEST_TRUE(iter != c.end());
 
-     ++iter;
 
-     CORE_TEST_EQUAL(20, *iter);
 
-     CORE_TEST_TRUE(iter != c.end());
 
-     ++iter;
 
-     CORE_TEST_EQUAL(30, *iter);
 
-     CORE_TEST_TRUE(iter != c.end());
 
-     ++iter;
 
-     CORE_TEST_FALSE(iter != c.end());
 
-     const IntComponent c2 = Core::move(c);
 
-     auto iter2 = c2.begin();
 
-     CORE_TEST_EQUAL(10, *iter2);
 
-     CORE_TEST_TRUE(iter2 != c2.end());
 
-     ++iter2;
 
-     CORE_TEST_EQUAL(20, *iter2);
 
-     CORE_TEST_TRUE(iter2 != c2.end());
 
-     ++iter2;
 
-     CORE_TEST_EQUAL(30, *iter2);
 
-     CORE_TEST_TRUE(iter2 != c2.end());
 
-     ++iter2;
 
-     CORE_TEST_FALSE(iter2 != c2.end());
 
- }
 
- static void testRemove() {
 
-     IntComponent c;
 
-     CORE_TEST_ERROR(c.add(1, 10));
 
-     CORE_TEST_ERROR(c.add(5, 20));
 
-     CORE_TEST_ERROR(c.add(10, 30));
 
-     CORE_TEST_EQUAL(Core::Error::NOT_FOUND, c.remove(20));
 
-     CORE_TEST_ERROR(c.remove(5));
 
-     CORE_TEST_EQUAL(Core::Error::NOT_FOUND, c.remove(30));
 
-     CORE_TEST_ERROR(c.add(20, 40));
 
-     CORE_TEST_ERROR(c.remove(20));
 
-     int* i1 = c.search(1);
 
-     int* i2 = c.search(5);
 
-     int* i3 = c.search(10);
 
-     CORE_TEST_NOT_NULL(i1);
 
-     CORE_TEST_NULL(i2);
 
-     CORE_TEST_NOT_NULL(i3);
 
-     if(i1 != nullptr && i3 != nullptr) {
 
-         CORE_TEST_EQUAL(10, *i1);
 
-         CORE_TEST_EQUAL(30, *i3);
 
-     }
 
-     CORE_TEST_ERROR(c.remove(10));
 
-     i1 = c.search(1);
 
-     i2 = c.search(5);
 
-     i3 = c.search(10);
 
-     CORE_TEST_NOT_NULL(i1);
 
-     CORE_TEST_NULL(i2);
 
-     CORE_TEST_NULL(i3);
 
-     if(i1 != nullptr) {
 
-         CORE_TEST_EQUAL(10, *i1);
 
-     }
 
-     CORE_TEST_ERROR(c.remove(1));
 
-     CORE_TEST_NULL(c.search(1));
 
-     CORE_TEST_NULL(c.search(5));
 
-     CORE_TEST_NULL(c.search(10));
 
- }
 
- static void testOutOfMemory() {
 
-     IntComponent c;
 
-     int* i1 = nullptr;
 
-     int memFails = 0;
 
-     for(int i = 0; i < 40; i++) {
 
-         Core::Fail::leftAllocations = 2;
 
-         Core::Error e = c.put(i1, 1, 10);
 
-         if(e == Core::Error::OUT_OF_MEMORY) {
 
-             memFails++;
 
-         }
 
-     }
 
-     Core::Fail::leftAllocations = -1;
 
-     CORE_TEST_TRUE(memFails > 0);
 
- }
 
- static void testConstSearch() {
 
-     IntComponent c;
 
-     int* i = nullptr;
 
-     CORE_TEST_ERROR(c.put(i, 1, 10));
 
-     const IntComponent& cc = c;
 
-     const int* component = cc.search(1);
 
-     if(CORE_TEST_TRUE(component != nullptr)) {
 
-         CORE_TEST_EQUAL(10, *component);
 
-     }
 
-     CORE_TEST_NULL(cc.search(2));
 
- }
 
- void Core::testComponents() {
 
-     testAddForEach();
 
-     testAddConstForEach();
 
-     testAddComponentForEach();
 
-     testRemove();
 
-     testOutOfMemory();
 
-     testConstSearch();
 
- }
 
 
  |