aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--include/moslib/ds/array.h22
-rw-r--r--include/moslib/tester.h4
-rw-r--r--src/tester.c2
-rw-r--r--tests/ds/array_tests.c8
-rw-r--r--tests/ds/array_tests.h3
-rw-r--r--tests/tests.c2
7 files changed, 28 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 194aa3b..cc6ffda 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,7 @@ structures:
test:
$(CC) $(CFLAGS_TEST) -c tests/mem/alloc_tests.c
+ $(CC) $(CFLAGS_TEST) -c tests/ds/array_tests.c
$(CC) $(CFLAGS_TEST) *.o tests/tests.c -o run_tests
./run_tests 2>/dev/null
rm run_tests *.o
diff --git a/include/moslib/ds/array.h b/include/moslib/ds/array.h
index a9fb00b..aac2304 100644
--- a/include/moslib/ds/array.h
+++ b/include/moslib/ds/array.h
@@ -30,24 +30,24 @@
//
// To append/push to the array use:
//
-// size_t index = arr_append(&array, item);
+// size_t index = arr_append(array, item);
//
// or:
//
-// size_t index = arr_push(&array, item);
+// size_t index = arr_push(array, item);
//
// It returns the index of the newly appended/pushed item.
//
// To insert into specific index of the array and push items after it to the right use:
//
-// size_t index = arr_insert(&array, i, item);
+// size_t index = arr_insert(array, i, item);
//
// It returns the index of the newly inserted item
// If index is greater or equal to array length then it functions identically to arr_append/arr_push.
//
// To put into specific index (and update if value exists) use:
//
-// size_t zerod = arr_put(&array, i, item);
+// size_t zerod = arr_put(array, i, item);
//
// If index is greater or equal to array length it will extend the length to the put item and it will
// zero all items between previously last item to the new item.
@@ -55,10 +55,10 @@
//
// If you want to add more items than 1 at once, you can use these:
//
-// size_t index = arr_append_n(&array, items, n_items);
-// size_t index = arr_push_n(&array, items, n_items);
-// size_t index = arr_insert_n(&array, i, items, n_items);
-// size_t zerod = arr_put_n(&array, i, items, n_items);
+// size_t index = arr_append_n(array, items, n_items);
+// size_t index = arr_push_n(array, items, n_items);
+// size_t index = arr_insert_n(array, i, items, n_items);
+// size_t zerod = arr_put_n(array, i, items, n_items);
//
// They work the same way as their counterparts without n, but accept an array of items instead.
//
@@ -66,7 +66,7 @@
//
// To concatenate two dynamic arrays of the same type use:
//
-// size_t index = arr_concat(&array1, array2);
+// size_t index = arr_concat(array1, array2);
//
// First array will be the destination.
// Returns index of the first item of array2 in array1.
@@ -117,7 +117,7 @@
//
// You can also set length:
//
-// size_t deleted = arr_set_len(&array, new_len);
+// size_t deleted = arr_set_len(array, new_len);
//
// If it's bigger than current length - it will zero new items.
// If it's smaller than current length - it will delete items.
@@ -131,7 +131,7 @@
//
// You can also set capacity:
//
-// size_t new_cap = arr_cap(&array, target_cap);
+// size_t new_cap = arr_cap(array, target_cap);
//
// When target_cap is lower than array length it will set capacity to array length.
// Returns the new capacity.
diff --git a/include/moslib/tester.h b/include/moslib/tester.h
index 9c3ea04..52a9f14 100644
--- a/include/moslib/tester.h
+++ b/include/moslib/tester.h
@@ -73,14 +73,14 @@
typedef void Test; // this is just for nice indication that a function is a test
typedef struct Tester Tester;
typedef struct TestGroup TestGroup;
-typedef Test (*TestFn)();
+typedef Test (*TestFn)(void);
// Initalize new tester
// You can skip this and just define it as NULL - it will initalize automatically
//
// Returns:
// pointer to the new tester
-extern Tester *new_tester();
+extern Tester *new_tester(void);
// Add new test group to the tester
//
diff --git a/src/tester.c b/src/tester.c
index 766dd0b..c166a48 100644
--- a/src/tester.c
+++ b/src/tester.c
@@ -55,7 +55,7 @@ struct TestGroup {
size_t test_cap;
};
-Tester *new_tester() {
+Tester *new_tester(void) {
Tester *tester = safe_malloc(sizeof(Tester));
*tester = (Tester){
.groups = safe_malloc(INIT_GROUP_CAP * sizeof(TestGroup)),
diff --git a/tests/ds/array_tests.c b/tests/ds/array_tests.c
new file mode 100644
index 0000000..23e2272
--- /dev/null
+++ b/tests/ds/array_tests.c
@@ -0,0 +1,8 @@
+#include "array_tests.h"
+
+// TODO: add tests
+
+void ds_array_tests(Tester *tester) {
+ TestGroup *group = add_test_group(tester, "moslib/ds/array.h");
+ (void)group;
+}
diff --git a/tests/ds/array_tests.h b/tests/ds/array_tests.h
new file mode 100644
index 0000000..254506e
--- /dev/null
+++ b/tests/ds/array_tests.h
@@ -0,0 +1,3 @@
+#include <moslib/tester.h>
+
+extern void ds_array_tests(Tester *tester);
diff --git a/tests/tests.c b/tests/tests.c
index 63e84ca..7846d91 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -1,11 +1,13 @@
#include <moslib/tester.h>
+#include "ds/array_tests.h"
#include "mem/alloc_tests.h"
int main(void) {
Tester *tester = new_tester();
mem_alloc_tests(tester);
+ ds_array_tests(tester);
run_tests(tester);
free_tester(tester);