Skip to content

Generating tests on the fly

Alexey Dmitriev edited this page Nov 11, 2018 · 2 revisions

Sometimes you need to run a big test, but it's not convenient to do that by hand. Also, sometimes you want to run it on many tests, generated automatically. One of they ways to achieve this is the following:

  1. In solver class add a function to generate a test and a variable to show number of times it should be run.
static constexpr int kStressIterations = 0;
void generateTest(std::ostream& test) {
}
void solve(std::istream& in, std::ostream& out) {
}

Now in run.template we need to actually run this generated tests after (or instead of) running on normal tests

for(const jhelper::Test& test: tests) {
	run_test(test);
}
for (int i = 0; i < %ClassName%::kStressIterations; ++i) {
	std::ostringstream generated_test;
	%ClassName%::generateTest(generated_test);
	run_test({generated_test.str(), "", true, false});
}

Adding several types of tests is still not very convenient through, but you may create several tests this way (by returning a collection)