Browse Source

Merge matrix stack add last into list

Kajetan Johannes Hammerle 2 weeks ago
parent
commit
3f5d732da4
6 changed files with 18 additions and 4 deletions
  1. 0 2
      CMakeLists.txt
  2. 1 0
      include/core/List.h
  3. 4 0
      src/List.c
  4. 0 1
      test/Main.c
  5. 0 1
      test/Tests.h
  6. 13 0
      test/modules/ListTests.c

+ 0 - 2
CMakeLists.txt

@@ -39,7 +39,6 @@ set(SRC_TESTS
     #"test/modules/ComponentsTests.cpp"
     #"test/modules/HashMapTests.cpp"
     #"test/modules/LinkedListTests.cpp"
-    #"test/modules/MatrixStackTests.cpp"
     #"test/modules/RingBufferTests.cpp"
 )
 
@@ -115,7 +114,6 @@ target_sources(core PUBLIC
 #        ./include/core/Components.hpp
 #        ./include/core/HashMap.hpp
 #        ./include/core/LinkedList.hpp
-#        ./include/core/MatrixStack.hpp
 #        ./include/core/ProbingHashMap.hpp
 #        ./include/core/RingBuffer.hpp
 )

+ 1 - 0
include/core/List.h

@@ -22,6 +22,7 @@ void coreResizeListPointer(CoreList* l, size_t n, const void* data);
     coreResizeListPointer(l, n, &(type){__VA_ARGS__})
 CoreList* coreListAddPointer(CoreList* l, const void* data);
 #define coreListAdd(l, type, ...) coreListAddPointer(l, &(type){__VA_ARGS__})
+CoreList* coreListAddLast(CoreList* l);
 void* coreListGetVoidPointer(CoreList* l, size_t index);
 #define coreListGetPointer(l, index, type)                                     \
     ((type*)coreListGetVoidPointer(l, index))

+ 4 - 0
src/List.c

@@ -86,6 +86,10 @@ CoreList* coreListAddPointer(CoreList* l, const void* data) {
     return l;
 }
 
+CoreList* coreListAddLast(CoreList* l) {
+    return coreListAddPointer(l, coreListLastVoidPointer(l));
+}
+
 void* coreListGetVoidPointer(CoreList* l, size_t index) {
     assert(index < l->length);
     return getPointer(l, index);

+ 0 - 1
test/Main.c

@@ -34,7 +34,6 @@ int main(int argAmount, const char** args) {
     // coreTestComponents();
     // coreTestHashMap(light);
     // coreTestLinkedList(light);
-    // coreTestMatrixStack(light);
     // coreTestRingBuffer();
     coreTestBitArray();
     coreTestBox();

+ 0 - 1
test/Tests.h

@@ -14,7 +14,6 @@ void coreTestHashMap(bool light);
 void coreTestLinkedList(bool light);
 void coreTestList(bool light);
 void coreTestMatrix(void);
-void coreTestMatrixStack(bool light);
 void coreTestPlane(void);
 void coreTestPostCanary(void);
 void coreTestPreCanary(void);

+ 13 - 0
test/modules/ListTests.c

@@ -29,6 +29,18 @@ static void testMultipleAdd() {
     coreDestroyList(&list);
 }
 
+static void testAddLast() {
+    CoreList list = CORE_LIST(sizeof(size_t));
+    coreListAdd(&list, size_t, 4);
+    coreListAdd(&list, size_t, 3);
+    coreListAddLast(&list);
+    CORE_TEST_SIZE(4, coreListGet(&list, 0, size_t));
+    CORE_TEST_SIZE(3, coreListGet(&list, 1, size_t));
+    CORE_TEST_SIZE(3, coreListGet(&list, 2, size_t));
+    CORE_TEST_SIZE(3, list.length);
+    coreDestroyList(&list);
+}
+
 static void testAddReplace() {
     CoreList list = CORE_LIST(sizeof(size_t));
     coreListAdd(&list, size_t, 5);
@@ -259,6 +271,7 @@ static void testStruct() {
 void coreTestList(bool light) {
     testAdd();
     testMultipleAdd();
+    testAddLast();
     testAddReplace();
     testClear();
     testShrink();