diff options
author | Derick Huth <derickhuth@gmail.com> | 2016-01-18 15:43:52 -0700 |
---|---|---|
committer | Derick Huth <derickhuth@gmail.com> | 2016-01-18 15:43:52 -0700 |
commit | 983749787ee0dc1beb1107873e8a13ebdaeba576 (patch) | |
tree | e9bff337b4d5582b87ad2edc25baa4d3b0c163fa /test-chill/unit-tests/cprog/main.cc | |
parent | 0cff3f9a3c4ccd434900162ebef4bd814850f481 (diff) | |
download | chill-983749787ee0dc1beb1107873e8a13ebdaeba576.tar.gz chill-983749787ee0dc1beb1107873e8a13ebdaeba576.tar.bz2 chill-983749787ee0dc1beb1107873e8a13ebdaeba576.zip |
restore test suite
Diffstat (limited to 'test-chill/unit-tests/cprog/main.cc')
-rw-r--r-- | test-chill/unit-tests/cprog/main.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test-chill/unit-tests/cprog/main.cc b/test-chill/unit-tests/cprog/main.cc new file mode 100644 index 0000000..3fe960b --- /dev/null +++ b/test-chill/unit-tests/cprog/main.cc @@ -0,0 +1,45 @@ +#include <cstdio> +#include <cstdlib> +#include <map> +#include <string> +#include <vector> + +#include "Sorter.h" +#include "QuickSorter.h" +#include "MergeSorter.h" +//#include "InsertionSorter.h" +//#include "ShellSorter.h" + +void read_vector(std::vector<int>& vec, int start, int stop, char** argv) { + for(int i = start; i < stop; i++) { + vec.push_back((int)strtol(argv[i],NULL,0)); + } +} + +void print_vector(std::vector<int>& vec) { + printf("["); + for(std::vector<int>::iterator iter = vec.begin(); iter != vec.end(); iter++) { + printf(" %d ", *iter); + } + printf("]\n"); +} + +void addsorter(std::map<std::string, Sorter*>& m, Sorter* s) { + m[s->name] = s; +} + +int main(int argc, char** argv) { + std::map<std::string, Sorter*> sorter_map; + std::vector<int> vec; + + read_vector(vec, 2, argc, argv); + print_vector(vec); + + addsorter(sorter_map, new QuickSorter()); + addsorter(sorter_map, new MergeSorter()); + //addsorter(sorter_map, new InsertionSorter()); + //addsorter(sorter_map, new ShellSorter()); + sorter_map[std::string(argv[1])]->sort(vec); + print_vector(vec); +} + |