From 69a0bed64e26300bd8144b8dafd5a2bf5dac4d4d Mon Sep 17 00:00:00 2001 From: saundersp Date: Sun, 24 Aug 2025 18:55:07 +0200 Subject: [PATCH] data.cpp : Replaced assertion when sorting failed with log && merged test_sort and test_argsort --- data.cpp | 53 ++++++++++++++++------------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/data.cpp b/data.cpp index d7aa069..eb141d5 100644 --- a/data.cpp +++ b/data.cpp @@ -1,4 +1,3 @@ -#include #include #include "toolbox.hpp" #include "data.hpp" @@ -20,35 +19,19 @@ static constexpr bool is_sorted(const asp::Array& a) noexcept { } template -static constexpr void test_sort(const std::array& gaps, const asp::Array& original, void (* const fnc)(const asp::Array&), const char* const title) noexcept { -#ifdef __DEBUG - printf("xxxxxxxxxxxxxxx IGNORE COPY "); -#endif - const asp::Array a(original); +static constexpr void test_sort(const std::array& gaps, const asp::Array& original, void (* const fnc)(asp::Array&), const char* const title) noexcept { + asp::Array a(original); asp::measure_time_void(gaps, title, fnc, a); -#ifdef __DEBUG - const bool result = asp::measure_time(gaps, "=> Unit test", is_sorted, a); - // asp::print(original); - // asp::print(a); - asp::formatted_row(gaps, { result ? "Success" : "Failure", "-", "-" }); -#else - assert(is_sorted(a)); -#endif + const bool result = is_sorted(a); + asp::formatted_row(gaps, { result ? "=> Unit test success" : "=> Unit test failure", "-", "-" }); } template -static void test_argsort(const std::array& gaps, const asp::Array& original, asp::Array(* const fnc)(const asp::Array&), const char* const title) noexcept { -#ifdef __DEBUG - printf("xxxxxxxxxxxxxxx IGNORE COPY "); -#endif - const asp::Array a(original); +static inline void test_sort(const std::array& gaps, const asp::Array& original, asp::Array(* const fnc)(asp::Array&), const char* const title) noexcept { + asp::Array a(original); const asp::Array indices = asp::measure_time>(gaps, title, fnc, a); -#ifdef __DEBUG - const bool result = asp::measure_time(gaps, "=> Unit test", is_arg_sorted, original, indices); - asp::formatted_row(gaps, { result ? "Success" : "Failure", "-", "-" }); -#else - assert(is_arg_sorted(original, indices)); -#endif + const bool result = is_arg_sorted(original, indices); + asp::formatted_row(gaps, { result ? "=> Unit test success" : "=> Unit test failure", "-", "-" }); } template @@ -64,7 +47,7 @@ int32_t main(int32_t argc, char** argv) { asp::toolbox_unit_test(); using array_type = uint16_t; - int64_t N = (static_cast(1)<<15) - 1; + int64_t N = (static_cast(1)<<16) - 1; // int64_t N = std::numeric_limits::max(); if (argc > 2) { fprintf(stderr, "Too many arguments\nUsage: ./data \n"); @@ -80,21 +63,17 @@ int32_t main(int32_t argc, char** argv) { const asp::Array original = asp::measure_time>(gaps, "Creating random array", create_random_array, N); test_sort(gaps, original, asp::bubble_sort, "Bubble sort"); - test_argsort(gaps, original, asp::bubble_sort_arg, "Bubble sort (arg)"); + test_sort(gaps, original, asp::bubble_sort_arg, "Bubble sort (arg)"); test_sort(gaps, original, asp::quicksort, "Quicksort"); - test_argsort(gaps, original, asp::quicksort_arg, "Quicksort (arg)"); + test_sort(gaps, original, asp::quicksort_arg, "Quicksort (arg)"); test_sort(gaps, original, asp::quicksort_iter, "Quicksort (iterative)"); - test_argsort(gaps, original, asp::quicksort_arg_iter, "Quicksort (iterative) (arg)"); + test_sort(gaps, original, asp::quicksort_arg_iter, "Quicksort (iterative) (arg)"); test_sort(gaps, original, asp::mergesort, "Mergesort"); - test_argsort(gaps, original, asp::mergesort_arg, "Mergesort (arg)"); + test_sort(gaps, original, asp::mergesort_arg, "Mergesort (arg)"); test_sort(gaps, original, asp::insertion_sort, "Insertion sort"); - // test_argsort(gaps, original, asp::insertion_argsort, "Insertion argsort"); - - // W.I.P - // test_sort(gaps, original, asp::counting_sort, "Counting sort"); - // test_argsort(gaps, original, asp::counting_sort_arg, "Counting sort (arg)"); - // test_sort(gaps, original, asp::radix_sort, "Radix sort"); - // test_argsort(gaps, original, asp::radix_sort_arg, "Radix sort (arg)"); + test_sort(gaps, original, asp::insertion_argsort, "Insertion (arg)"); + test_sort(gaps, original, asp::counting_sort, "Counting sort"); + test_sort(gaps, original, asp::radix_sort, "Radix sort"); asp::footer(gaps);