summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/vec.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/vec.c b/tests/vec.c
new file mode 100644
index 0000000..6ad973f
--- /dev/null
+++ b/tests/vec.c
@@ -0,0 +1,54 @@
+#include "test.h"
+#include <lisiblestd/log.h>
+#include <lisiblestd/vec.h>
+#include <memory.h>
+
+VEC_IMPL(int, intvec, 128)
+
+void t_vec_init(void) {
+ intvec vec = {0};
+ intvec_init(&system_allocator, &vec);
+ T_ASSERT(intvec_length(&vec) == 0);
+ T_ASSERT(intvec_capacity(&vec) == 128);
+ intvec_deinit(&vec);
+}
+
+void t_vec_push_back(void) {
+ intvec vec = {0};
+ intvec_init(&system_allocator, &vec);
+ T_ASSERT(intvec_length(&vec) == 0);
+ intvec_push_back(&vec, 10);
+ T_ASSERT(intvec_length(&vec) == 1);
+ intvec_push_back(&vec, 13);
+ intvec_push_back(&vec, 15);
+ T_ASSERT(intvec_length(&vec) == 3);
+ T_ASSERT(vec.data[0] == 10);
+ T_ASSERT(vec.data[1] == 13);
+ T_ASSERT(vec.data[2] == 15);
+ intvec_deinit(&vec);
+}
+void t_vec_append(void) {
+ intvec vec = {0};
+ intvec_init(&system_allocator, &vec);
+ T_ASSERT(intvec_length(&vec) == 0);
+ intvec_push_back(&vec, 10);
+ intvec_append(&vec, (int[]){11, 12, 13}, 3);
+ T_ASSERT(intvec_length(&vec) == 4);
+ T_ASSERT(vec.data[0] == 10);
+ T_ASSERT(vec.data[1] == 11);
+ T_ASSERT(vec.data[2] == 12);
+ T_ASSERT(vec.data[3] == 13);
+ intvec_deinit(&vec);
+}
+
+void t_vec_u8_append_1(void) {
+ u8vec vec;
+ u8vec_init(&system_allocator, &vec);
+ u8 v = 1;
+ for (size_t i = 0; i < 1000; i++)
+ u8vec_append(&vec, &v, 1);
+ u8vec_deinit(&vec);
+}
+
+TEST_SUITE(TEST(t_vec_init), TEST(t_vec_push_back), TEST(t_vec_append),
+ TEST(t_vec_u8_append_1))
Go back to lisible.xyz