summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/array.c30
-rw-r--r--tests/main.c3
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/array.c b/tests/array.c
index 79664cc..6ac3845 100644
--- a/tests/array.c
+++ b/tests/array.c
@@ -1,5 +1,6 @@
#include <al/test.h>
#include <al/array.h>
+#include <al/random.h>
#include "array.h"
@@ -315,6 +316,34 @@ static bool array_test_foreach(void)
AL_TEST_END();
}
+static s32 int32_compare(const void *a, const void *b)
+{
+ if (*(s32 *)a < *(s32 *)b) return 1;
+ else if (*(s32 *)b < *(s32 *)a) return -1;
+ return 0;
+}
+
+static bool array_test_sort(void)
+{
+ AL_TEST_START("array_sort");
+
+ array(s32) arr;
+ al_array_init(arr);
+
+ s32 end = al_rand() % 2000;
+ for (s32 i = 0; i < end; i++) {
+ al_array_push(arr, al_rand());
+ }
+
+ al_array_sort(arr, s32, int32_compare);
+
+ for (u32 i = 1; i < arr.size; i++) {
+ AL_TEST_GTE(al_array_at(arr, i - 1), al_array_at(arr, i), s32);
+ }
+
+ AL_TEST_END();
+}
+
bool array_tests_run(void)
{
AL_TEST_START_GROUP("array");
@@ -329,6 +358,7 @@ bool array_tests_run(void)
AL_TEST_RUN(array_test_pop_at);
AL_TEST_RUN(array_test_insert);
AL_TEST_RUN(array_test_foreach);
+ AL_TEST_RUN(array_test_sort);
AL_TEST_END_GROUP();
}
diff --git a/tests/main.c b/tests/main.c
index e263dd5..2c13ce9 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -1,4 +1,5 @@
#include <al/lib.h>
+#include <al/random.h>
#include "lib.h"
#include "array.h"
@@ -10,6 +11,8 @@
s32 main(void)
{
+ al_rand_init();
+
if (!lib_tests_run()) goto fail;
if (!array_tests_run()) goto fail;
#if defined AL_HAVE_GNU_EXTENSIONS