123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #include "../Tests.hpp"
- #include "core/data/ArrayList.hpp"
- template class Core::ArrayList<size_t, 20>;
- using IntList = Core::ArrayList<size_t, 20>;
- static void testAdd() {
- IntList list;
- list.add(5u);
- CORE_TEST_EQUAL(5, list[0]);
- CORE_TEST_EQUAL(1, list.getLength());
- }
- static void testMultipleAdd() {
- IntList list;
- list.add(4u).add(3u).add(2u);
- CORE_TEST_EQUAL(4, list[0]);
- CORE_TEST_EQUAL(3, list[1]);
- CORE_TEST_EQUAL(2, list[2]);
- CORE_TEST_EQUAL(3, list.getLength());
- }
- static void testAddReplace() {
- IntList list;
- list.add(5u);
- list[0] = 3;
- CORE_TEST_EQUAL(3, list[0]);
- }
- static void testClear() {
- IntList list;
- list.add(5u).add(4u);
- list.clear();
- CORE_TEST_EQUAL(0, list.getLength());
- }
- static void testOverflow(bool light) {
- IntList list;
- for(size_t i = 0; i < 20; i++) {
- list.add(i);
- }
- size_t limit = light ? 1000 : 100000;
- for(size_t i = 0; i < limit; i++) {
- list.add(i);
- }
- for(size_t i = 0; i < list.getLength(); i++) {
- CORE_TEST_EQUAL(i, list[i]);
- }
- }
- static void testCopy() {
- IntList list;
- list.add(1u).add(2u).add(3u);
- IntList copy(list);
- CORE_TEST_EQUAL(list.getLength(), copy.getLength());
- for(size_t i = 0; i < copy.getLength() && i < list.getLength(); i++) {
- CORE_TEST_EQUAL(list[i], copy[i]);
- }
- }
- static void testCopyAssignment() {
- IntList list;
- list.add(1u).add(2u).add(3u);
- IntList copy;
- copy = list;
- CORE_TEST_EQUAL(list.getLength(), copy.getLength());
- for(size_t i = 0; i < copy.getLength() && i < list.getLength(); i++) {
- CORE_TEST_EQUAL(list[i], copy[i]);
- }
- }
- static void testMove() {
- IntList list;
- list.add(1u).add(2u).add(3u);
- IntList move(Core::move(list));
- CORE_TEST_EQUAL(0, list.getLength());
- CORE_TEST_EQUAL(3, move.getLength());
- CORE_TEST_EQUAL(1, move[0]);
- CORE_TEST_EQUAL(2, move[1]);
- CORE_TEST_EQUAL(3, move[2]);
- }
- static void testMoveAssignment() {
- IntList list;
- list.add(1u).add(2u).add(3u);
- IntList move;
- move = Core::move(list);
- CORE_TEST_EQUAL(0, list.getLength());
- CORE_TEST_EQUAL(3, move.getLength());
- CORE_TEST_EQUAL(1, move[0]);
- CORE_TEST_EQUAL(2, move[1]);
- CORE_TEST_EQUAL(3, move[2]);
- }
- static void testToString() {
- IntList list;
- list.add(1u).add(243u).add(423u);
- CORE_TEST_STRING("[1, 243, 423]", list);
- CORE_TEST_STRING("[1]", IntList().add(1u));
- CORE_TEST_STRING("[]", IntList());
- }
- static void testRemove() {
- IntList list;
- list.add(4u).add(3u).add(2u);
- list.removeBySwap(0);
- CORE_TEST_EQUAL(2, list[0]);
- CORE_TEST_EQUAL(3, list[1]);
- CORE_TEST_EQUAL(2, list.getLength());
- list.removeBySwap(1);
- CORE_TEST_EQUAL(2, list[0]);
- CORE_TEST_EQUAL(1, list.getLength());
- list.removeBySwap(0);
- CORE_TEST_EQUAL(0, list.getLength());
- }
- static void testForRange() {
- IntList list;
- list.add(1u).add(2u).add(3u);
- for(size_t& i : list) {
- i++;
- }
- for(size_t i = 0; i < list.getLength(); i++) {
- CORE_TEST_EQUAL(i + 2, list[i]);
- }
- }
- void Core::testArrayList(bool light) {
- testAdd();
- testMultipleAdd();
- testAddReplace();
- testClear();
- testOverflow(light);
- testCopy();
- testCopyAssignment();
- testMove();
- testMoveAssignment();
- testToString();
- testRemove();
- testForRange();
- }
|