[yul-phaser] Add --show-initial-population option

This commit is contained in:
Kamil Śliwak
2020-03-25 10:21:18 +01:00
parent d6b96063f8
commit ec10a3d378
4 changed files with 52 additions and 0 deletions
+29
View File
@@ -70,6 +70,7 @@ class AlgorithmRunnerFixture
protected:
// NOTE: Regexes here should not contain spaces because we strip them before matching
regex RoundSummaryRegex{R"(-+ROUND\d+-+)"};
regex InitialPopulationHeaderRegex{"-+INITIALPOPULATION-+"};
string individualPattern(Individual const& individual) const
{
@@ -133,6 +134,7 @@ BOOST_FIXTURE_TEST_CASE(run_should_call_runNextRound_once_per_round, AlgorithmRu
BOOST_FIXTURE_TEST_CASE(run_should_print_round_summary_after_each_round, AlgorithmRunnerFixture)
{
m_options.maxRounds = 1;
m_options.showInitialPopulation = false;
AlgorithmRunner runner(m_population, {}, m_options, m_output);
RandomisingAlgorithm algorithm;
@@ -148,6 +150,33 @@ BOOST_FIXTURE_TEST_CASE(run_should_print_round_summary_after_each_round, Algorit
BOOST_TEST(m_output.peek() == EOF);
}
BOOST_FIXTURE_TEST_CASE(run_should_print_initial_population_if_requested, AlgorithmRunnerFixture)
{
m_options.maxRounds = 0;
m_options.showInitialPopulation = true;
RandomisingAlgorithm algorithm;
AlgorithmRunner runner(m_population, {}, m_options, m_output);
runner.run(algorithm);
BOOST_TEST(nextLineMatches(m_output, InitialPopulationHeaderRegex));
for (auto const& individual: m_population.individuals())
BOOST_TEST(nextLineMatches(m_output, regex(individualPattern(individual))));
BOOST_TEST(m_output.peek() == EOF);
}
BOOST_FIXTURE_TEST_CASE(run_should_not_print_initial_population_if_not_requested, AlgorithmRunnerFixture)
{
m_options.maxRounds = 0;
m_options.showInitialPopulation = false;
RandomisingAlgorithm algorithm;
AlgorithmRunner runner(m_population, {}, m_options, m_output);
runner.run(algorithm);
BOOST_TEST(m_output.peek() == EOF);
}
BOOST_FIXTURE_TEST_CASE(run_should_save_initial_population_to_file_if_autosave_file_specified, AlgorithmRunnerAutosaveFixture)
{
m_options.maxRounds = 0;