refactor: extract finder-test template method
parent
ad8a9ada83
commit
076969f393
|
@ -35,77 +35,31 @@ void test_finder_search(Finder &finder, std::string_view name,
|
|||
<< " element(s) long" << endl;
|
||||
}
|
||||
|
||||
void test_finder(Finder &finder, std::string_view name) {
|
||||
template <typename FINDER>
|
||||
void test_finder(const vector<string> &word_list,
|
||||
std::string_view finder_name) {
|
||||
cout << "\nrunning " << finder_name << endl;
|
||||
|
||||
Timer constructor_timer;
|
||||
FINDER finder(word_list);
|
||||
constructor_timer.stop();
|
||||
cout << finder_name << " constructor took " << constructor_timer << endl;
|
||||
|
||||
for (const auto &search_term : {"A", "AB", "ABC", "ABCD"}) {
|
||||
test_finder_search(finder, name, search_term);
|
||||
test_finder_search(finder, finder_name, search_term);
|
||||
}
|
||||
}
|
||||
|
||||
void test_linear_finder(const vector<string> &word_list) {
|
||||
cout << "\nrunning linear finder" << endl;
|
||||
|
||||
Timer constructor_timer;
|
||||
LinearFinder linear_finder(word_list);
|
||||
constructor_timer.stop();
|
||||
cout << "linear finder constructor took " << constructor_timer << endl;
|
||||
|
||||
test_finder(linear_finder, "linear finder");
|
||||
}
|
||||
|
||||
void test_sorted_linear_finder(const vector<string> &word_list) {
|
||||
cout << "\nrunning sorted linear finder" << endl;
|
||||
|
||||
Timer constructor_timer;
|
||||
SortedLinearFinder sorted_linear_finder(word_list);
|
||||
constructor_timer.stop();
|
||||
cout << "sorted linear finder constructor took " << constructor_timer << endl;
|
||||
|
||||
test_finder(sorted_linear_finder, "sorted linear finder");
|
||||
}
|
||||
|
||||
void test_parallel_finder(const vector<string> &word_list) {
|
||||
cout << "\nrunning parallel finder" << endl;
|
||||
|
||||
Timer constructor_timer;
|
||||
ParallelFinder parallel_finder(word_list);
|
||||
constructor_timer.stop();
|
||||
cout << "linear finder constructor took " << constructor_timer << endl;
|
||||
|
||||
test_finder(parallel_finder, "parallel finder");
|
||||
}
|
||||
|
||||
void test_tree_finder(const vector<string> &word_list) {
|
||||
cout << "\nrunning tree finder" << endl;
|
||||
|
||||
Timer constructor_timer;
|
||||
TreeFinder tree_finder(word_list);
|
||||
constructor_timer.stop();
|
||||
cout << "tree finder constructor took " << constructor_timer << endl;
|
||||
|
||||
test_finder(tree_finder, "tree finder");
|
||||
}
|
||||
|
||||
void test_grouped_finder(const vector<string> &word_list) {
|
||||
cout << "\nrunning grouped finder" << endl;
|
||||
|
||||
Timer constructor_timer;
|
||||
GroupedFinder grouped_finder(word_list);
|
||||
constructor_timer.stop();
|
||||
cout << "grouped finder constructor took " << constructor_timer << endl;
|
||||
|
||||
test_finder(grouped_finder, "grouped_finder");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
cout << "\n== VectorSearch ==" << endl;
|
||||
|
||||
auto word_list = generate_word_list(5);
|
||||
|
||||
test_linear_finder(word_list);
|
||||
test_sorted_linear_finder(word_list);
|
||||
test_parallel_finder(word_list);
|
||||
test_tree_finder(word_list);
|
||||
test_grouped_finder(word_list);
|
||||
test_finder<LinearFinder>(word_list, "linear finder");
|
||||
test_finder<SortedLinearFinder>(word_list, "sorted linear finder");
|
||||
test_finder<ParallelFinder>(word_list, "parallel finder");
|
||||
test_finder<TreeFinder>(word_list, "tree finder");
|
||||
test_finder<GroupedFinder>(word_list, "grouped finder");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue