123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- #include "../Tests.h"
- #include "core/List.h"
- #include "core/ToString.h"
- #include "core/Vector.h"
- LIST(size_t, Size)
- LIST(Vector3, V3)
- LIST_SOURCE(Vector3, V3)
- LIST(int, Int)
- static void testAdd() {
- ListSize list;
- initListSize(&list);
- addListDataSize(&list, 5);
- TEST_SIZE(5, *getListIndexSize(&list, 0));
- TEST_SIZE(1, list.length);
- destroyListSize(&list);
- }
- static void testMultipleAdd() {
- ListSize list;
- initListSize(&list);
- addListDataSize(&list, 4);
- addListDataSize(&list, 3);
- addListDataSize(&list, 2);
- TEST_SIZE(4, *getListIndexSize(&list, 0));
- TEST_SIZE(3, *getListIndexSize(&list, 1));
- TEST_SIZE(2, *getListIndexSize(&list, 2));
- TEST_SIZE(2, *getListLastSize(&list));
- TEST_SIZE(3, list.length);
- destroyListSize(&list);
- }
- static void testAddLast() {
- ListSize list;
- initListSize(&list);
- addListDataSize(&list, 4);
- addListDataSize(&list, 3);
- addLastListDataSize(&list);
- TEST_SIZE(4, *getListIndexSize(&list, 0));
- TEST_SIZE(3, *getListIndexSize(&list, 1));
- TEST_SIZE(3, *getListIndexSize(&list, 2));
- TEST_SIZE(3, list.length);
- destroyListSize(&list);
- }
- static void testAddReplace() {
- ListSize list;
- initListSize(&list);
- addListDataSize(&list, 5);
- *getListIndexSize(&list, 0) = 3;
- TEST_SIZE(3, *getListIndexSize(&list, 0));
- destroyListSize(&list);
- }
- static void testClear() {
- ListSize list;
- initListSize(&list);
- addListDataSize(&list, 5);
- addListDataSize(&list, 4);
- clearListSize(&list);
- TEST_SIZE(0, list.length);
- destroyListSize(&list);
- }
- static void testBigAdd(bool light) {
- size_t limit = light ? 10000 : 100000;
- ListSize list;
- initListSize(&list);
- for(size_t i = 0; i < limit; i++) {
- addListDataSize(&list, i);
- }
- for(size_t i = 0; i < list.length; i++) {
- TEST_SIZE(i, *getListIndexSize(&list, i));
- }
- TEST_SIZE(limit, list.length);
- destroyListSize(&list);
- }
- static void testToString1() {
- ListSize list;
- initListSize(&list);
- addListDataSize(&list, 1);
- addListDataSize(&list, 243);
- addListDataSize(&list, 423);
- char buffer[128];
- size_t n = toStringListSize(&list, buffer, sizeof(buffer), toStringSize);
- TEST_SIZE(13, n);
- TEST_STRING("[1, 243, 423]", buffer);
- destroyListSize(&list);
- }
- static void testToString2() {
- ListSize list;
- initListSize(&list);
- addListDataSize(&list, 1);
- char buffer[128];
- size_t n = toStringListSize(&list, buffer, sizeof(buffer), toStringSize);
- TEST_SIZE(3, n);
- TEST_STRING("[1]", buffer);
- destroyListSize(&list);
- }
- static void testToString3() {
- ListSize list;
- initListSize(&list);
- char buffer[128];
- size_t n = toStringListSize(&list, buffer, sizeof(buffer), toStringSize);
- TEST_SIZE(2, n);
- TEST_STRING("[]", buffer);
- destroyListSize(&list);
- }
- static void testRemoveBySwap() {
- ListSize list;
- initListSize(&list);
- addListDataSize(&list, 4);
- addListDataSize(&list, 3);
- addListDataSize(&list, 2);
- removeListIndexBySwapSize(&list, 0);
- TEST_SIZE(2, *getListIndexSize(&list, 0));
- TEST_SIZE(3, *getListIndexSize(&list, 1));
- TEST_SIZE(2, list.length);
- removeListIndexBySwapSize(&list, 1);
- TEST_SIZE(2, *getListIndexSize(&list, 0));
- TEST_SIZE(1, list.length);
- removeListIndexBySwapSize(&list, 0);
- TEST_SIZE(0, list.length);
- destroyListSize(&list);
- }
- static void testRemove() {
- ListSize list;
- initListSize(&list);
- addListDataSize(&list, 4);
- addListDataSize(&list, 3);
- addListDataSize(&list, 2);
- removeListIndexSize(&list, 0);
- TEST_SIZE(3, *getListIndexSize(&list, 0));
- TEST_SIZE(2, *getListIndexSize(&list, 1));
- TEST_SIZE(2, list.length);
- removeListIndexSize(&list, 1);
- TEST_SIZE(3, *getListIndexSize(&list, 0));
- TEST_SIZE(1, list.length);
- removeListIndexSize(&list, 0);
- TEST_SIZE(0, list.length);
- destroyListSize(&list);
- }
- static void testRemoveLast() {
- ListSize list;
- initListSize(&list);
- addListDataSize(&list, 4);
- addListDataSize(&list, 3);
- addListDataSize(&list, 2);
- removeListLastSize(&list);
- TEST_SIZE(4, *getListIndexSize(&list, 0));
- TEST_SIZE(3, *getListIndexSize(&list, 1));
- TEST_SIZE(2, list.length);
- removeListLastSize(&list);
- TEST_SIZE(4, *getListIndexSize(&list, 0));
- TEST_SIZE(1, list.length);
- removeListLastSize(&list);
- TEST_SIZE(0, list.length);
- destroyListSize(&list);
- }
- static void testInvalidReserve() {
- ListSize list;
- initListSize(&list);
- reserveListEntriesSize(&list, 0);
- destroyListSize(&list);
- }
- static void testStruct() {
- ListV3 list;
- Vector3 v = {{1, 2, 3}};
- initListV3(&list);
- addListDataV3(&list, v);
- addListDataV3(&list, (Vector3){{2, 3, 4}});
- char buffer[128];
- size_t n = toStringListV3(&list, buffer, sizeof(buffer), toStringV3);
- TEST_SIZE(46, n);
- TEST_STRING("[[1.000, 2.000, 3.000], [2.000, 3.000, 4.000]]", buffer);
- addLastListDataV3(&list);
- addLastListDataV3(&list);
- TEST_SIZE(4, (size_t)(getListEndV3(&list) - getListStartV3(&list)));
- removeListIndexV3(&list, 1);
- removeListIndexBySwapV3(&list, 1);
- removeListLastV3(&list);
- Vector3* entry = getListIndexV3(&list, 0);
- TEST_V3(&v, entry);
- clearListV3(&list);
- TEST_SIZE(0, list.length);
- destroyListV3(&list);
- }
- static void testIntList() {
- ListInt list;
- initListInt(&list);
- addListDataInt(&list, 5);
- addListDataInt(&list, 7);
- char buffer[128];
- size_t n = toStringListInt(&list, buffer, sizeof(buffer), toStringInt);
- TEST_SIZE(6, n);
- TEST_STRING("[5, 7]", buffer);
- addLastListDataInt(&list);
- addLastListDataInt(&list);
- TEST_SIZE(4, (size_t)(getListEndInt(&list) - getListStartInt(&list)));
- removeListIndexInt(&list, 1);
- removeListIndexBySwapInt(&list, 1);
- removeListLastInt(&list);
- int* entry = getListIndexInt(&list, 0);
- TEST_INT(5, *entry);
- clearListInt(&list);
- TEST_SIZE(0, list.length);
- destroyListInt(&list);
- }
- void testList(bool light) {
- testAdd();
- testMultipleAdd();
- testAddLast();
- testAddReplace();
- testClear();
- testBigAdd(light);
- testToString1();
- testToString2();
- testToString3();
- testRemoveBySwap();
- testRemove();
- testRemoveLast();
- testInvalidReserve();
- testStruct();
- testIntList();
- }
|