diff options
Diffstat (limited to 'libk/test/quicksort.cc')
-rw-r--r-- | libk/test/quicksort.cc | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/libk/test/quicksort.cc b/libk/test/quicksort.cc index 582e49e..7a25c08 100644 --- a/libk/test/quicksort.cc +++ b/libk/test/quicksort.cc @@ -1,9 +1,14 @@ #include <stdlib/quicksort.h> -constexpr bool is_sorted(int a[], size_t from, size_t to) { +constexpr bool is_sorted_asc(int a[], size_t from, size_t to) { for (; from < to - 1; ++from) - if (a[from] > a[from + 1]) - return false; + if (a[from] > a[from + 1]) return false; + return true; +} + +constexpr bool is_sorted_desc(int a[], size_t from, size_t to) { + for (; from < to - 1; ++from) + if (a[from] < a[from + 1]) return false; return true; } @@ -12,5 +17,13 @@ static_assert([]() { const size_t a_len = sizeof(a) / sizeof(int); qsort(a, 0, a_len - 1); - return is_sorted(a, 0, a_len - 1); + return is_sorted_asc(a, 0, a_len - 1); +}()); + +static_assert([]() { + int a[] = {12, 82, 347, 92, 74, 123, 0, 56}; + const size_t a_len = sizeof(a) / sizeof(int); + + qsort<int, SortOrder::Descending>(a, 0, a_len - 1); + return is_sorted_desc(a, 0, a_len - 1); }()); |