00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <basis/chaos.h>
00016 #include <basis/function.h>
00017 #include <basis/guards.h>
00018 #include <basis/shell_sort.h>
00019 #include <opsystem/application_shell.h>
00020 #include <loggers/console_logger.h>
00021 #include <data_struct/static_memory_gremlin.h>
00022
00023 const int MAX_ELEMENTS = 1200;
00024
00025 const int MAX_VALUE = 28000;
00026
00027 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s)
00028
00029 class test_sorts : public application_shell
00030 {
00031 public:
00032 test_sorts() : application_shell(class_name()) {}
00033 IMPLEMENT_CLASS_NAME("test_sorts");
00034 virtual int execute();
00035 };
00036
00037 int test_sorts::execute()
00038 {
00039 FUNCDEF("execute");
00040
00041 int *list = new int[MAX_ELEMENTS];
00042 for (int i = 0; i < MAX_ELEMENTS; i++)
00043 list[i] = randomizer().inclusive(0, MAX_VALUE);
00044
00045
00046
00047
00048
00049
00050
00051 shell_sort(list, MAX_ELEMENTS);
00052 int last = -1;
00053 for (int j = 0; j < MAX_ELEMENTS; j++) {
00054 if (list[j] < last)
00055 deadly_error("t_sorts", "ordering check", "list is not ordered");
00056 last = list[j];
00057 }
00058
00059
00060 for (int i = 0; i < MAX_ELEMENTS; i++)
00061 list[i] = randomizer().inclusive(0, MAX_VALUE);
00062
00063
00064 shell_sort(list, MAX_ELEMENTS, true);
00065 last = MAX_VALUE + 100;
00066 for (int j = 0; j < MAX_ELEMENTS; j++) {
00067 if (list[j] > last)
00068 deadly_error("t_sorts", "ordering check", "list is not ordered");
00069 last = list[j];
00070 }
00071
00072
00073 delete [] list;
00074
00075 guards::alert_message("shell_sort:: works for those functions tested.");
00076 return 0;
00077 }
00078
00079 HOOPLE_MAIN(test_sorts, )
00080