24 using namespace basis;
36 #define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger().get(), to_print)
48 int *populate_random_c_array(
int size);
51 bool verify_ascending(
const int *list,
int size);
52 bool verify_descending(
const int *list,
int size);
54 void test_shell_sort(
int size);
55 void test_heap_sort(
int size);
56 void test_merge_sort(
int size);
57 void test_quick_sort(
int size);
59 virtual int execute();
62 int *test_sorts::populate_random_c_array(
int size)
64 int *list =
new int[size];
65 for (
int i = 0; i < size; i++)
73 for (
int i = 0; i < size; i++)
84 bool test_sorts::verify_ascending(
const int *list,
int size)
88 for (
int j = 1; j < size; j++) {
89 if (list[j] < last)
return false;
95 bool test_sorts::verify_descending(
const int *list,
int size)
99 for (
int j = 1; j < size; j++) {
100 if (list[j] > last)
return false;
106 void test_sorts::test_shell_sort(
int size)
110 int *list = populate_random_c_array(size);
115 "ordering check - list should be ordered at first check");
122 "ordering check - list should be ordered at second check");
128 void test_sorts::test_heap_sort(
int size)
132 int *list = populate_random_c_array(size);
137 "ordering check - list should be ordered at first check");
144 "ordering check - list should be ordered at second check");
150 void test_sorts::test_merge_sort(
int size)
162 "ordering check - list should be ordered at first check");
169 "ordering check - list should be ordered at second check");
172 void test_sorts::test_quick_sort(
int size)
176 int *list = populate_random_c_array(size);
181 "ordering check - list should be ordered at first check");
190 "ordering check - list should be ordered at second check");
197 int test_sorts::execute()
203 test_shell_sort(size);
205 test_heap_sort(size);
207 test_merge_sort(size);
209 test_quick_sort(size);
211 return final_report();
The application_shell is a base object for console programs.
contents * access()
A non-constant access of the underlying C-array. BE REALLY CAREFUL.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
void randomize_list(type v[], int n)
handy method for randomizing the order of a list. not strictly a sorting function....
void heap_sort(type v[], int n, bool reverse=false)
void quick_sort(type v[], int n, bool reverse=false)
void shell_sort(type v[], int n, bool reverse=false)
shell sort algorithm.
basis::array< type > merge_sort(const basis::array< type > &v, bool reverse=false)
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
A dynamic container class that holds any kind of object via pointers.
Useful support functions for unit testing, especially within hoople.
#define ASSERT_TRUE(a, test_name)