Randomly perform fully verifiable test in randomly generated tests
This commit is contained in:
parent
f5582682e9
commit
6e0c74d1b2
@ -49,12 +49,12 @@ public:
|
|||||||
unsigned long longest_start = 0;
|
unsigned long longest_start = 0;
|
||||||
unsigned long longest_end = 0;
|
unsigned long longest_end = 0;
|
||||||
bool match_found = false;
|
bool match_found = false;
|
||||||
bool operator==(const result r);
|
bool operator==(const result r) const;
|
||||||
friend std::istream &operator>>(std::istream &in, result &r);
|
friend std::istream &operator>>(std::istream &in, result &r);
|
||||||
friend std::ostream &operator<<(std::ostream &out, const result &r);
|
friend std::ostream &operator<<(std::ostream &out, const result &r);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool result::operator==(const result r) {
|
bool result::operator==(const result r) const {
|
||||||
return longest_start == r.longest_start && longest_end == r.longest_end &&
|
return longest_start == r.longest_start && longest_end == r.longest_end &&
|
||||||
match_found == r.match_found;
|
match_found == r.match_found;
|
||||||
}
|
}
|
||||||
@ -151,6 +151,20 @@ bool K_verify(const test_case &t) {
|
|||||||
return unique_chars.size() == t.i.k;
|
return unique_chars.size() == t.i.k;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool thorough_test(const test_case &t) {
|
||||||
|
unsigned long org_window_size = t.r.longest_end - t.r.longest_start + 1;
|
||||||
|
if (org_window_size >= t.i.s.length())
|
||||||
|
return true;
|
||||||
|
for (unsigned long i = 0, n_tests = t.i.s.length() - org_window_size;
|
||||||
|
i < n_tests; i++) {
|
||||||
|
result r = {i, i + org_window_size, true};
|
||||||
|
test_case mock_test = {t.i, r};
|
||||||
|
if (K_verify(mock_test))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
std::cout << "Processing static test cases from input file (if any)\n";
|
std::cout << "Processing static test cases from input file (if any)\n";
|
||||||
semicolon_is_space delimeter;
|
semicolon_is_space delimeter;
|
||||||
@ -164,10 +178,13 @@ int main(int argc, char *argv[]) {
|
|||||||
test(t);
|
test(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::cout
|
// Thorough test (100% verifiable correct) is performaned randomly in ~1%
|
||||||
<< "\n\n\nPerforming metamorphic tests from randomly generated input "
|
// cases
|
||||||
"(string and K values)"
|
std::cout << "\n\n\nPerforming metamorphic tests from randomly generated "
|
||||||
|
"input (string and K values).\nThorough test (100\% verifiable "
|
||||||
|
"correct) is performaned randomly in ~1\% cases."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
random_number_generator<unsigned int> random_ascii_char(97, 122); // a-z
|
random_number_generator<unsigned int> random_ascii_char(97, 122); // a-z
|
||||||
random_number_generator<unsigned int> rng;
|
random_number_generator<unsigned int> rng;
|
||||||
@ -187,6 +204,8 @@ int main(int argc, char *argv[]) {
|
|||||||
t.r = r;
|
t.r = r;
|
||||||
std::cout << t;
|
std::cout << t;
|
||||||
assert(K_verify(t));
|
assert(K_verify(t));
|
||||||
|
if (!rng(0, 99))
|
||||||
|
assert(thorough_test(t));
|
||||||
}
|
}
|
||||||
while (t.r.match_found) {
|
while (t.r.match_found) {
|
||||||
result r = find(t.i.s, ++t.i.k);
|
result r = find(t.i.s, ++t.i.k);
|
||||||
@ -196,10 +215,11 @@ int main(int argc, char *argv[]) {
|
|||||||
t.r = r;
|
t.r = r;
|
||||||
std::cout << t;
|
std::cout << t;
|
||||||
assert(K_verify(t));
|
assert(K_verify(t));
|
||||||
|
if (!rng(0, 99))
|
||||||
|
assert(thorough_test(t));
|
||||||
}
|
}
|
||||||
t.i.k = rng(1, --t.i.k);
|
t.i.k = rng(1, --t.i.k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user