- remove testdata length parameter
- added result checks
This commit is contained in:
parent
6e5ddb3c80
commit
67cab6efd1
@ -10,8 +10,7 @@ class Parameters
|
||||
public:
|
||||
Parameters():
|
||||
workerCount_(std::thread::hardware_concurrency()),
|
||||
testDataLength_(4),
|
||||
searchPattern_("ABC")
|
||||
searchPattern_("")
|
||||
{};
|
||||
|
||||
~Parameters() {};
|
||||
@ -25,10 +24,6 @@ public:
|
||||
{
|
||||
workerCount_ = std::stoi(arg.substr(2));
|
||||
}
|
||||
else if (0 == arg.compare(0, 2, "-l"))
|
||||
{
|
||||
testDataLength_ = std::stoi(arg.substr(2));
|
||||
}
|
||||
else if (0 == arg.compare(0, 1, "-"))
|
||||
{
|
||||
// invalid option
|
||||
@ -51,17 +46,14 @@ public:
|
||||
<< "Usage: " << cmd << " [options] [search_pattern]" << std::endl
|
||||
<< "Options" << std::endl
|
||||
<< " -wX Number of parallel workers" << std::endl
|
||||
<< " -lY Length of test-data string" << std::endl
|
||||
<< std::endl;
|
||||
};
|
||||
|
||||
unsigned WorkerCount() const { return workerCount_; };
|
||||
unsigned TestDataLength() const { return testDataLength_; };
|
||||
std::string SearchPattern() const { return searchPattern_; };
|
||||
|
||||
private:
|
||||
unsigned workerCount_;
|
||||
unsigned testDataLength_;
|
||||
std::string searchPattern_;
|
||||
};
|
||||
|
||||
|
||||
36
main.cpp
36
main.cpp
@ -4,7 +4,6 @@
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
|
||||
|
||||
#include "ParallelSearch.hpp"
|
||||
#include "TestRunner.hpp"
|
||||
#include "Parameters.hpp"
|
||||
@ -24,7 +23,9 @@ void create_testdata(WordList& words)
|
||||
for (str[1] = start; str[1] <= end; str[1]++)
|
||||
for (str[2] = start; str[2] <= end; str[2]++)
|
||||
for (str[3] = start; str[3] <= end; str[3]++)
|
||||
{
|
||||
words.push_back(std::string(str, 4));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -39,6 +40,29 @@ void run_wordsearch(ParallelWordSearch& search)
|
||||
search.run();
|
||||
}
|
||||
|
||||
void check_result(const WordList& haystack, const std::string& pattern, const ParallelWordSearch::ResultList& result)
|
||||
{
|
||||
// check number of matches
|
||||
const unsigned TESTPATTERN_LENGTH = 4;
|
||||
unsigned expected_count = static_cast<unsigned>(pow(26.0, double(TESTPATTERN_LENGTH - pattern.size())));
|
||||
std::cout << "Number of matches expected: " << expected_count << " got: " << result.size() << " --> " << ((result.size() == expected_count) ? "OK" : "ERROR") << std::endl;
|
||||
|
||||
// verify matches contain the search-pattern
|
||||
unsigned valid_count = 0;
|
||||
for (WordList::const_iterator itr : result)
|
||||
{
|
||||
if (itr->substr(0, pattern.size()) == pattern)
|
||||
{
|
||||
valid_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Found mismatch: " << *itr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Verified " << valid_count << " matches --> " << ((result.size() == valid_count) ? "OK" : "ERROR") << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
@ -55,7 +79,6 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
std::cout << "Workercount: " << parameters.WorkerCount() << std::endl;
|
||||
std::cout << "Testdata length: " << parameters.TestDataLength() << std::endl;
|
||||
std::cout << "Search pattern: " << parameters.SearchPattern() << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
@ -74,8 +97,13 @@ int main(int argc, char** argv)
|
||||
time_span = TestRunner(run_wordsearch, parallelWordSearch);
|
||||
std::cout << "parallel search found " << parallelWordSearch.get_result().size() << " matches: " << time_span << " seconds" << std::endl;
|
||||
|
||||
// TODO add validation of results
|
||||
// TODO brush up output
|
||||
std::cout << std::endl;
|
||||
std::cout << "checking result of parallel search ..." << std::endl;
|
||||
|
||||
check_result(test_data, parameters.SearchPattern(), parallelWordSearch.get_result());
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "Done." << std::endl;
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user