3 * Author : Chris Koeritz
5 * Copyright (c) 1992-$now By Author. This program is free software; you can *
6 * redistribute it and/or modify it under the terms of the GNU General Public *
7 * License as published by the Free Software Foundation; either version 2 of *
8 * the License or (at your option) any later version. This is online at: *
9 * http://www.fsf.org/copyleft/gpl.html *
10 * Please send any updates to: fred@gruntose.com *
13 #include <algorithms/shell_sort.h>
14 #include <application/hoople_main.h>
15 #include <basis/functions.h>
16 #include <basis/guards.h>
17 #include <loggers/console_logger.h>
18 #include <mathematics/chaos.h>
19 #include <structures/static_memory_gremlin.h>
20 #include <unit_test/unit_base.h>
22 using namespace algorithms;
23 using namespace application;
24 using namespace basis;
25 using namespace loggers;
26 using namespace mathematics;
27 using namespace structures;
28 using namespace textual;
29 using namespace timely;
30 using namespace unit_test;
32 const int MAX_ELEMENTS = 1200;
34 const int MAX_VALUE = 28000;
36 #define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger().get(), to_print)
38 class test_sorts : virtual public unit_base, virtual public application_shell
41 test_sorts() : application_shell() {}
42 DEFINE_CLASS_NAME("test_sorts");
43 virtual int execute();
46 int test_sorts::execute()
50 int *list = new int[MAX_ELEMENTS];
51 for (int i = 0; i < MAX_ELEMENTS; i++)
52 list[i] = randomizer().inclusive(0, MAX_VALUE);
55 //for (int i = 0; i < MAX_ELEMENTS; i++) ret += a_sprintf("%d ", list[i]);
57 //LOG("-------------");
59 // check a normal sort.
60 shell_sort(list, MAX_ELEMENTS);
62 for (int j = 0; j < MAX_ELEMENTS; j++) {
63 ASSERT_FALSE(list[j] < last, "ordering check - list should be ordered at first check");
67 // re-randomize the list.
68 for (int i = 0; i < MAX_ELEMENTS; i++)
69 list[i] = randomizer().inclusive(0, MAX_VALUE);
71 // check a reversed sort.
72 shell_sort(list, MAX_ELEMENTS, true);
73 last = MAX_VALUE + 100; // past the maximum we'll include in the list.
74 for (int j = 0; j < MAX_ELEMENTS; j++) {
75 ASSERT_FALSE(list[j] > last, "ordering check - list should be ordered at second check");
82 return final_report();
85 HOOPLE_MAIN(test_sorts, )