diff --git a/.gitignore b/.gitignore index 496ee2c..5b800ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -.DS_Store \ No newline at end of file +.DS_Store + +tests/build/ +build/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e516763 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.16) +project(tests LANGUAGES C) + +enable_testing() + +add_executable(test_vector + tests/test_vector.c +) + +add_executable(test_set + tests/test_set.c +) + +add_test(NAME test_vector COMMAND test_vector) +add_test(NAME test_set COMMAND test_set) \ No newline at end of file diff --git a/README.md b/README.md index 87c14d5..4602abd 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Literally just copy the header file you want and let your favourite semi-usable ## Contributing If you want to contribute, please make a pull request and I'll review it. If you want to contribute a new type or function, please make sure it is useful and not just a "cool" thing. +If you change an existing type, please run **make** in *build/* directory and **ctest** to ensure compatibility hasn't been broken. +If it's new, please write a **test** for it in *tests/test_.c* so others can see the guidelines on how the type is used. ## Legal Mumbo Jumbo Licensed under the MIT License (because GPL doesn't make sense for this (sorry Stallman)) diff --git a/tests/test_set.c b/tests/test_set.c new file mode 100644 index 0000000..9039869 --- /dev/null +++ b/tests/test_set.c @@ -0,0 +1,34 @@ +#include +#include "../set.h" + +int main(void) { + set_t* set = set_create(sizeof(int)); + if (!set) { + fprintf(stderr, "Failed to create set\n"); + return 1; + } + + for (int i = 0; i < 10; ++i) { + if (set_insert(set, &i) != 0) { + fprintf(stderr, "Failed to insert %d\n", i); + set_destroy(&set); + return 1; + } + } + + for (size_t i = 0; i < set_size(set); ++i) { + int* value = (int*)set_get_const(set, i); + if (value) { + printf("set[%zu] = %d\n", i, *value); + } else { + fprintf(stderr, "Failed to get value at index %zu\n", i); + } + } + + set_destroy(&set); + if (set != NULL) { + fprintf(stderr, "Set pointer was not set to NULL after destruction\n"); + return 1; + } + return 0; +} \ No newline at end of file diff --git a/tests/test_vector.c b/tests/test_vector.c new file mode 100644 index 0000000..f5ed596 --- /dev/null +++ b/tests/test_vector.c @@ -0,0 +1,34 @@ +#include +#include "../vector.h" + +int main(void) { + vector_t* vec = vector_create(sizeof(int)); + if (!vec) { + fprintf(stderr, "Failed to create vector\n"); + return 1; + } + + for (int i = 0; i < 10; ++i) { + if (vector_push_back(vec, &i) != 0) { + fprintf(stderr, "Failed to push back %d\n", i); + vector_destroy(&vec); + return 1; + } + } + + for (size_t i = 0; i < vector_size(vec); ++i) { + int* value = (int*)vector_get(vec, i); + if (value) { + printf("vec[%zu] = %d\n", i, *value); + } else { + fprintf(stderr, "Failed to get value at index %zu\n", i); + } + } + + vector_destroy(&vec); + if (vec != NULL) { + fprintf(stderr, "Vector pointer was not set to NULL after destruction\n"); + return 1; + } + return 0; +} \ No newline at end of file