void test0() { std::cout << "test0 " ; Sorter *sorter = new Sorter(); vector<uint32_t> a; vector<uint32_t> b; a.push_back(3); a.push_back(10); a.push_back(20); a.push_back(1); b.push_back(2); b.push_back(1); b.push_back(0); b.push_back(3); sorter->sort(a, b); assert(a[0] == 20); assert(a[1] == 10); assert(a[2] == 3); assert(a[3] == 1); assert(b[0] == 0); assert(b[1] == 1); assert(b[2] == 2); assert(b[3] == 3); delete sorter; }
void MinUnknownUniverseCover::_initializeVariableCover( unordered_map<uint32_t, uint32_t>& inputVariableFrequencyMap, vector<uint32_t>& outputCoverVariables) { //printf("\n initialize\n"); outputCoverVariables.clear(); vector<uint32_t> counts; for (unordered_map<uint32_t, uint32_t>::const_iterator iter = inputVariableFrequencyMap.begin(); iter != inputVariableFrequencyMap.end(); ++iter) { int var = iter->first; int count = iter->second; outputCoverVariables.push_back(var); counts.push_back(count); } //printf("\n sort by frequency %lu variables\n", counts.size()); // sort by frequency Sorter *sorter = new Sorter(); sorter->sort(counts, outputCoverVariables); delete sorter; //printf("\n initialize end\n"); }
int main(int argc, char** argv) { if (argc < 2) { std::cerr << "No arguments provided\n"; return 1; } Sorter sorter; sorter.sort(argv[1], "sorted_index.bin"); }
void checkSorter(Sorter& sorter, uint32_t count, ...) { va_list args; va_start(args, count); list<string> ordering = sorter.sort(); EXPECT_EQ(ordering.size(), count); foreach (const string& actual, ordering) { const char* expected = va_arg(args, char*); EXPECT_EQ(actual, expected); } va_end(args); }
void doSorter(TaskConfigure& configure, char* rootDirectory) { vector<string> inputFiles; inputFiles.push_back(string(rootDirectory) + "0.par"); inputFiles.push_back(string(rootDirectory) + "1.par"); inputFiles.push_back(string(rootDirectory) + "2.par"); inputFiles.push_back(string(rootDirectory) + "3.par"); inputFiles.push_back(string(rootDirectory) + "4.par"); string outputFile = "sorted.dat"; Sorter *sorter = new Sorter(configure, outputFile, inputFiles); TS_ASSERT(sorter != NULL); TS_ASSERT(sorter->sort() == true); delete sorter; }
void test1() { std::cout << "test1 " ; Sorter *sorter = new Sorter(); vector<uint32_t> a; vector<uint32_t> aIndexes; vector<uint32_t> aOriginal; // random tests time_t seed = time(NULL); srandom(seed); unsigned long nIter = 200000; for (unsigned long i = 0; i < nIter; i++) { long r = random(); uint32_t number = (uint32_t)r; // we're only using positive numbers the using code, but testing for +- a.push_back(number); aOriginal.push_back(number); aIndexes.push_back((uint32_t)i); } sorter->sort(a, aIndexes); assert(a.size() == nIter); assert(aIndexes.size() == nIter); for (unsigned long i = 1; i < nIter; i++) { assert(a[i] <= a[i-1]); uint32_t index = aIndexes[i]; assert(aOriginal[index] == a[i]); } delete sorter; }
int main(int argc, char ** argv) { if (argc != 2) { cerr << argv[0] << " <sorting algorithm>" << endl; exit(1); } Sorter<iterator_t> *mysort = sortingFactory<iterator_t>(string(argv[1])); cout << "Please insert your sequence of numbers (stop the sequence with Ctrl+D):" << endl; vector<T> foo; copy(istream_iterator<T>(cin), istream_iterator<T>(), back_inserter(foo)); double time = mysort->sort(foo.begin(), foo.end()); cout << "time used to sort: " << time << "sec" << endl; cout << endl << "The sorted sequence is:" << endl; copy(foo.begin(), foo.end(), ostream_iterator<T>(cout, "\n")); cout << endl; delete mysort; }
int main() { SorterTest test; QTest::qExec(&test); cout << "Welcome to the program of sorting of array\n"; cout << "Enter size of array "; int size = 0; cin >> size; cout << "Enter array "; const int maxSize = 100; int array1[maxSize]; int array2[maxSize]; int array3[maxSize]; for (int i = 0; i < size; ++i) { cin >> array1[i]; array2[i] = array1[i]; array3[i] = array1[i]; } Sorter *bubbleSort = new BubbleSort(); Sorter *quickSort = new QuickSort(); Sorter *heapSort = new HeapSort(); bubbleSort->sort(array1, size); quickSort->sort(array2, size); heapSort->sort(array3, size); cout << "Sorted by bubble\n"; for (int i = 0; i < size; ++i) { cout << array1[i] << ' '; } cout << '\n'; cout << "Sorted by quicksort\n"; for (int i = 0; i < size; ++i) { cout << array2[i] << ' '; } cout << '\n'; cout << "Sorted by heapsort\n"; for (int i = 0; i < size; ++i) { cout << array3[i] << ' '; } delete bubbleSort; delete quickSort; delete heapSort; return 0; }
int main(int argc, char *argv[]) { char *filename, *ndisp_str, *fdata; unsigned int fd, ndisp; struct stat finfo; if (argv[1] == NULL) { printf("USAGE: %s <filename> <# results>\n", argv[0]); exit(1); } // Initialize some variables filename = argv[1]; ndisp_str = argv[2]; CHECK_ERROR((ndisp = ((ndisp_str == NULL) ? DEFAULT_DISP_NUM : atoi(ndisp_str))) <= 0); printf("Sequential Sort: Running...\n"); // Open the file CHECK_ERROR((fd = open(filename, O_RDONLY)) < 0); CHECK_ERROR(fstat(fd, &finfo) < 0); #ifndef NO_MMAP // Memory map the file printf("Memory mapping the file (with MMAP_POPULATE)\n"); CHECK_ERROR((fdata = (char*) mmap(0, finfo.st_size + 1, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_POPULATE, fd, 0)) == NULL); #else uint64_t r = 0; printf("Mallocing the file\n"); fdata = (char *)malloc (finfo.st_size); CHECK_ERROR(fdata == NULL); while(r < (uint64_t)finfo.st_size) r += pread (fd, fdata + r, finfo.st_size, r); CHECK_ERROR(r != (uint64_t) finfo.st_size); #endif // Prepare splitter arguments Sorter *sort = new Sorter(fdata, finfo.st_size); // Divide file on a word border (i.e. a space) printf("Sequential Sort: Calling word count\n"); sort->splitter(); // Sort the results sort->sort(); printf("Sequential Sort: Completed\n"); // Print out results sort->print_results(ndisp); // Cleanup delete sort; #ifndef NO_MMAP CHECK_ERROR(munmap(fdata, finfo.st_size + 1) < 0); #else free (fdata); #endif CHECK_ERROR(close(fd)); return 0; }
void test2() { std::cout << "test2 " ; Sorter *sorter = new Sorter(); unsigned long len = 6; float* a = (float *)malloc(len * sizeof(float)); float* b = (float *)malloc(len * sizeof(float)); float* c = (float *)malloc(len * sizeof(float)); /* 4.000000e+00 9.499999e-01 3.500000e-01 2.000000e+00 5.500000e-01 6.500000e-01 1.500000e-01 4.000000e-01 3.500000e-01 3.000000e-01 4.000000e-01 3.500000e-01 4.000000e+00 9.499999e-01 5.500000e-01 3.000000e-01 3.000000e-01 3.500000e-01 */ a[0] = 4.000000e+00; b[0] = 9.499999e-01; c[0] = 3.500000e-01; a[1] = 2.000000e+00; b[1] = 5.500000e-01; c[1] = 6.500000e-01; a[2] = 1.500000e-01; b[2] = 4.000000e-01; c[2] = 3.500000e-01; a[3] = 3.000000e-01; b[3] = 4.000000e-01; c[3] = 3.500000e-01; a[4] = 4.000000e+00; b[4] = 9.499999e-01; c[4] = 5.500000e-01; a[5] = 3.000000e-01; b[5] = 3.000000e-01; c[5] = 3.000000e-01; sorter->sort(a, b, c, len); /* 1.500000e-01 4.000000e-01 3.500000e-01 3.000000e-01 3.000000e-01 3.500000e-01 3.000000e-01 4.000000e-01 3.500000e-01 2.000000e+00 5.500000e-01 6.500000e-01 4.000000e+00 9.499999e-01 3.500000e-01 4.000000e+00 9.499999e-01 5.500000e-01 */ float* ea = (float *)malloc(len * sizeof(float)); float* eb = (float *)malloc(len * sizeof(float)); float* ec = (float *)malloc(len * sizeof(float)); ea[0] = 1.500000e-01; eb[0] = 4.000000e-01; ec[0] = 3.500000e-01; ea[1] = 3.000000e-01; eb[1] = 3.000000e-01; ec[1] = 3.500000e-01; ea[2] = 3.000000e-01; eb[2] = 4.000000e-01; ec[2] = 3.500000e-01; ea[3] = 2.000000e+00; eb[3] = 5.500000e-01; ec[3] = 6.500000e-01; ea[4] = 4.000000e+00; eb[4] = 9.499999e-01; ec[4] = 3.500000e-01; ea[5] = 4.000000e+00; eb[5] = 9.499999e-01; ec[5] = 5.500000e-01; //printf("\n"); for (unsigned long i = 0; i < len; i++) { float diff = a[i] - ea[i]; if (diff < 0) { diff *= -1; } float eps = 0.01*ea[i]; if (eps < 0) { eps *= -1; } //printf("%e %e %e\n", a[i], b[i], c[i]); assert(diff < eps); } free(a); free(b); free(c); free(ea); free(eb); free(ec); delete sorter; }