#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <chrono>
// Function to check if a vector is sorted
template <typename T>
bool isSorted(const std::vector<T>& vec) {
return std::is_sorted(vec.begin(), vec.end());
}
// Function to generate a random vector of integers
std::vector<int> generateRandomVector(int size) {
std::vector<int> vec(size);
srand(static_cast<unsigned int>(time(0)));
for (int i = 0; i < size; ++i) {
vec[i] = rand();
}
return vec;
}
// Function to test a sorting algorithm
template <typename SortingFunction>
void testSortingAlgorithm(SortingFunction sortFunc, const std::string& algorithmName) {
std::cout << "Testing " << algorithmName << "..." << std::endl;
// Test with various sizes
for (int size : {10, 100, 1000}) {
std::vector<int> vec = generateRandomVector(size);
// Measure the execution time
auto start = std::chrono::high_resolution_clock::now();
sortFunc(vec.begin(), vec.end());
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> duration = end - start;
// Check if the vector is sorted
assert(isSorted(vec));
// Output the result
std::cout << "Size: " << size << ", Time: " << duration.count() << " seconds." << std::endl;
}
std::cout << algorithmName << " passed all tests." << std::endl;
}
// Implementation of the sorting algorithm to be tested
// Replace this with the sorting algorithm you want to test
template <typename RandomIt>
void yourSortingAlgorithm(RandomIt first, RandomIt last) {
// Your sorting algorithm implementation here
}
int main() {
// Test your sorting algorithm
testSortingAlgorithm(yourSortingAlgorithm, "YourSortingAlgorithm");
return 0;
}