|
@@ -0,0 +1,152 @@
|
|
|
|
+#include "tests/ComponentsTests.h"
|
|
|
|
+
|
|
|
|
+#include "data/Components.h"
|
|
|
|
+#include "test/Test.h"
|
|
|
|
+
|
|
|
|
+using IntComponent = Core::Components<int>;
|
|
|
|
+
|
|
|
|
+static void testAddForEach() {
|
|
|
|
+ IntComponent c;
|
|
|
|
+ int* i1 = c.add(1, 10);
|
|
|
|
+ int* i2 = c.add(5, 20);
|
|
|
|
+ int* i3 = c.add(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 testAddComponentForEach() {
|
|
|
|
+ IntComponent c;
|
|
|
|
+ int* i1 = c.add(1, 10);
|
|
|
|
+ int* i2 = c.add(5, 20);
|
|
|
|
+ int* i3 = c.add(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_NOT_NULL(c.add(1, 10));
|
|
|
|
+ CORE_TEST_NOT_NULL(c.add(5, 20));
|
|
|
|
+ CORE_TEST_NOT_NULL(c.add(10, 30));
|
|
|
|
+
|
|
|
|
+ CORE_TEST_TRUE(c.remove(20));
|
|
|
|
+ CORE_TEST_FALSE(c.remove(5));
|
|
|
|
+ CORE_TEST_TRUE(c.remove(30));
|
|
|
|
+
|
|
|
|
+ CORE_TEST_NOT_NULL(c.add(20, 40));
|
|
|
|
+ CORE_TEST_FALSE(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_FALSE(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_FALSE(c.remove(1));
|
|
|
|
+
|
|
|
|
+ CORE_TEST_NULL(c.search(1));
|
|
|
|
+ CORE_TEST_NULL(c.search(5));
|
|
|
|
+ CORE_TEST_NULL(c.search(10));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Core::ComponentsTests::test() {
|
|
|
|
+ testAddForEach();
|
|
|
|
+ testAddComponentForEach();
|
|
|
|
+ testRemove();
|
|
|
|
+}
|