123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #include "tests/ComponentsTests.h"
- #include "data/Components.h"
- #include "tests/Test.h"
- typedef Components<int> IntComponent;
- static void testAddForEach(Test& test) {
- IntComponent c;
- c.add(1, 10);
- c.add(5, 20);
- c.add(10, 30);
- auto iter = c.entities();
- auto pos = iter.begin();
- auto end = iter.end();
- test.checkEqual(1u, (*pos).entity, "contains added entity 1");
- test.checkEqual(10, (*pos).component, "contains added component 1");
- test.checkEqual(true, pos != end, "not at end 1");
- ++pos;
- test.checkEqual(5u, (*pos).entity, "contains added entity 2");
- test.checkEqual(20, (*pos).component, "contains added component 2");
- test.checkEqual(true, pos != end, "not at end 2");
- ++pos;
- test.checkEqual(10u, (*pos).entity, "contains added entity 3");
- test.checkEqual(30, (*pos).component, "contains added component 3");
- test.checkEqual(true, pos != end, "not at end 3");
- ++pos;
- test.checkEqual(false, pos != end, "at end");
- }
- static void testRemove(Test& test) {
- IntComponent c;
- c.add(1, 10);
- c.add(5, 20);
- c.add(10, 30);
- c.remove(20);
- c.remove(5);
- c.remove(30);
- c.add(20, 40);
- c.remove(20);
- int* i1 = c.search(1);
- int* i2 = c.search(5);
- int* i3 = c.search(10);
- test.checkEqual(true, i1 != nullptr, "remove 1");
- test.checkEqual(true, i2 == nullptr, "remove 2");
- test.checkEqual(true, i3 != nullptr, "remove 3");
- test.checkEqual(10, *i1, "remove 4");
- test.checkEqual(30, *i3, "remove 5");
- c.remove(10);
- i1 = c.search(1);
- i2 = c.search(5);
- i3 = c.search(10);
- test.checkEqual(true, i1 != nullptr, "remove 6");
- test.checkEqual(true, i2 == nullptr, "remove 7");
- test.checkEqual(true, i3 == nullptr, "remove 8");
- test.checkEqual(10, *i1, "remove 9");
- c.remove(1);
- i1 = c.search(1);
- i2 = c.search(5);
- i3 = c.search(10);
- test.checkEqual(true, i1 == nullptr, "remove 10");
- test.checkEqual(true, i2 == nullptr, "remove 11");
- test.checkEqual(true, i3 == nullptr, "remove 12");
- }
- void ComponentsTests::test() {
- Test test("Components");
- testAddForEach(test);
- testRemove(test);
- test.finalize();
- }
|