From 71a05dfe538c980c8987a5cdb04b273d6f0d755c Mon Sep 17 00:00:00 2001 From: Nikola Matic Date: Thu, 11 Jan 2024 13:04:52 +0100 Subject: [PATCH] Purge using namespace std from test/yulPhaser --- scripts/check_style.sh | 1 + test/yulPhaser/AlgorithmRunner.cpp | 125 ++++++++++++------------ test/yulPhaser/Chromosome.cpp | 19 ++-- test/yulPhaser/Common.cpp | 25 +++-- test/yulPhaser/FitnessMetrics.cpp | 35 ++++--- test/yulPhaser/GeneticAlgorithms.cpp | 83 ++++++++-------- test/yulPhaser/Mutations.cpp | 139 +++++++++++++-------------- test/yulPhaser/PairSelections.cpp | 52 +++++----- test/yulPhaser/Phaser.cpp | 85 ++++++++-------- test/yulPhaser/Population.cpp | 51 +++++----- test/yulPhaser/Program.cpp | 75 +++++++-------- test/yulPhaser/ProgramCache.cpp | 39 ++++---- test/yulPhaser/Selections.cpp | 93 +++++++++--------- test/yulPhaser/SimulationRNG.cpp | 44 ++++----- test/yulPhaser/TestHelpers.cpp | 27 +++--- test/yulPhaser/TestHelpersTest.cpp | 19 ++-- 16 files changed, 448 insertions(+), 464 deletions(-) diff --git a/scripts/check_style.sh b/scripts/check_style.sh index 7bcd8cca36c9..fe4d19734fc1 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -50,6 +50,7 @@ NAMESPACE_STD_FREE_FILES=( test/libyul/* test/solc/* test/tools/yulInterpreter/* + test/yulPhaser/* ) ( diff --git a/test/yulPhaser/AlgorithmRunner.cpp b/test/yulPhaser/AlgorithmRunner.cpp index 003403929eb2..56868f1ce76e 100644 --- a/test/yulPhaser/AlgorithmRunner.cpp +++ b/test/yulPhaser/AlgorithmRunner.cpp @@ -35,7 +35,6 @@ #include #include -using namespace std; using namespace boost::unit_test::framework; using namespace boost::test_tools; using namespace solidity::langutil; @@ -74,44 +73,44 @@ class AlgorithmRunnerFixture { protected: // NOTE: Regexes here should not contain spaces because we strip them before matching - regex RoundSummaryRegex{R"(-+ROUND\d+\[round:[0-9.]+s,total:[0-9.]+s\]-+)"}; - regex InitialPopulationHeaderRegex{"-+INITIALPOPULATION-+"}; + std::regex RoundSummaryRegex{R"(-+ROUND\d+\[round:[0-9.]+s,total:[0-9.]+s\]-+)"}; + std::regex InitialPopulationHeaderRegex{"-+INITIALPOPULATION-+"}; - string individualPattern(Individual const& individual) const + std::string individualPattern(Individual const& individual) const { - ostringstream output; + std::ostringstream output; output << individual.fitness << individual.chromosome; return output.str(); } - string topChromosomePattern(size_t roundNumber, Individual const& individual) const + std::string topChromosomePattern(size_t roundNumber, Individual const& individual) const { - ostringstream output; + std::ostringstream output; output << roundNumber << R"(\|[0-9.]+\|)" << individualPattern(individual); return output.str(); } - bool nextLineMatches(stringstream& stream, regex const& pattern) const + bool nextLineMatches(std::stringstream& stream, std::regex const& pattern) const { - string line; - if (getline(stream, line).fail()) + std::string line; + if (std::getline(stream, line).fail()) return false; - return regex_match(stripWhitespace(line), pattern); + return std::regex_match(stripWhitespace(line), pattern); } - shared_ptr m_fitnessMetric = make_shared(); + std::shared_ptr m_fitnessMetric = std::make_shared(); Population const m_population = Population::makeRandom(m_fitnessMetric, 5, 0, 20); - stringstream m_output; + std::stringstream m_output; AlgorithmRunner::Options m_options; }; class AlgorithmRunnerAutosaveFixture: public AlgorithmRunnerFixture { public: - static vector chromosomeStrings(Population const& _population) + static std::vector chromosomeStrings(Population const& _population) { - vector lines; + std::vector lines; for (auto const& individual: _population.individuals()) lines.push_back(toString(individual.chromosome)); @@ -120,7 +119,7 @@ class AlgorithmRunnerAutosaveFixture: public AlgorithmRunnerFixture protected: TemporaryDirectory m_tempDir; - string const m_autosavePath = (m_tempDir.path() / "population-autosave.txt").string(); + std::string const m_autosavePath = (m_tempDir.path() / "population-autosave.txt").string(); RandomisingAlgorithm m_algorithm; }; @@ -153,12 +152,12 @@ BOOST_FIXTURE_TEST_CASE(run_should_print_round_summary_after_each_round, Algorit runner.run(algorithm); BOOST_TEST(nextLineMatches(m_output, RoundSummaryRegex)); for (auto const& individual: runner.population().individuals()) - BOOST_TEST(nextLineMatches(m_output, regex(individualPattern(individual)))); + BOOST_TEST(nextLineMatches(m_output, std::regex(individualPattern(individual)))); runner.run(algorithm); BOOST_TEST(nextLineMatches(m_output, RoundSummaryRegex)); for (auto const& individual: runner.population().individuals()) - BOOST_TEST(nextLineMatches(m_output, regex(individualPattern(individual)))); + BOOST_TEST(nextLineMatches(m_output, std::regex(individualPattern(individual)))); BOOST_TEST(m_output.peek() == EOF); } @@ -172,9 +171,9 @@ BOOST_FIXTURE_TEST_CASE(run_should_not_print_round_summary_if_not_requested, Alg RandomisingAlgorithm algorithm; runner.run(algorithm); - BOOST_TEST(nextLineMatches(m_output, regex(""))); + BOOST_TEST(nextLineMatches(m_output, std::regex(""))); for (auto const& individual: runner.population().individuals()) - BOOST_TEST(nextLineMatches(m_output, regex(individualPattern(individual)))); + BOOST_TEST(nextLineMatches(m_output, std::regex(individualPattern(individual)))); BOOST_TEST(m_output.peek() == EOF); } @@ -202,7 +201,7 @@ BOOST_FIXTURE_TEST_CASE(run_should_print_only_top_chromosome_if_requested, Algor RandomisingAlgorithm algorithm; runner.run(algorithm); - BOOST_TEST(nextLineMatches(m_output, regex(topChromosomePattern(1, runner.population().individuals()[0])))); + BOOST_TEST(nextLineMatches(m_output, std::regex(topChromosomePattern(1, runner.population().individuals()[0])))); BOOST_TEST(m_output.peek() == EOF); } @@ -216,7 +215,7 @@ BOOST_FIXTURE_TEST_CASE(run_should_not_print_round_number_for_top_chromosome_if_ RandomisingAlgorithm algorithm; runner.run(algorithm); - BOOST_TEST(nextLineMatches(m_output, regex(individualPattern(runner.population().individuals()[0])))); + BOOST_TEST(nextLineMatches(m_output, std::regex(individualPattern(runner.population().individuals()[0])))); BOOST_TEST(m_output.peek() == EOF); } @@ -246,7 +245,7 @@ BOOST_FIXTURE_TEST_CASE(run_should_print_initial_population_if_requested, Algori BOOST_TEST(nextLineMatches(m_output, InitialPopulationHeaderRegex)); for (auto const& individual: m_population.individuals()) - BOOST_TEST(nextLineMatches(m_output, regex(individualPattern(individual)))); + BOOST_TEST(nextLineMatches(m_output, std::regex(individualPattern(individual)))); BOOST_TEST(m_output.peek() == EOF); } @@ -277,7 +276,7 @@ BOOST_FIXTURE_TEST_CASE(run_should_print_whole_initial_population_even_if_only_t BOOST_TEST(nextLineMatches(m_output, InitialPopulationHeaderRegex)); for (auto const& individual: m_population.individuals()) - BOOST_TEST(nextLineMatches(m_output, regex(individualPattern(individual)))); + BOOST_TEST(nextLineMatches(m_output, std::regex(individualPattern(individual)))); BOOST_TEST(m_output.peek() == EOF); } @@ -290,21 +289,21 @@ BOOST_FIXTURE_TEST_CASE(run_should_print_cache_stats_if_requested, AlgorithmRunn m_options.showCacheStats = true; RandomisingAlgorithm algorithm; - vector sourceStreams = { + std::vector sourceStreams = { CharStream("{mstore(10, 20)}", ""), CharStream("{mstore(10, 20)\nsstore(10, 20)}", ""), }; - vector programs = { + std::vector programs = { get(Program::load(sourceStreams[0])), get(Program::load(sourceStreams[1])), }; - vector> caches = { - make_shared(programs[0]), - make_shared(programs[1]), + std::vector> caches = { + std::make_shared(programs[0]), + std::make_shared(programs[1]), }; - shared_ptr fitnessMetric = make_shared(vector>{ - make_shared(nullopt, caches[0], CodeWeights{}), - make_shared(nullopt, caches[1], CodeWeights{}), + std::shared_ptr fitnessMetric = std::make_shared(std::vector>{ + std::make_shared(std::nullopt, caches[0], CodeWeights{}), + std::make_shared(std::nullopt, caches[1], CodeWeights{}), }); Population population = Population::makeRandom(fitnessMetric, 2, 0, 5); @@ -318,14 +317,14 @@ BOOST_FIXTURE_TEST_CASE(run_should_print_cache_stats_if_requested, AlgorithmRunn for (size_t i = 0; i < m_options.maxRounds.value() - 1; ++i) { - BOOST_TEST(nextLineMatches(m_output, regex(".*"))); - BOOST_TEST(nextLineMatches(m_output, regex("-+CACHESTATS-+"))); + BOOST_TEST(nextLineMatches(m_output, std::regex(".*"))); + BOOST_TEST(nextLineMatches(m_output, std::regex("-+CACHESTATS-+"))); if (i > 0) - BOOST_TEST(nextLineMatches(m_output, regex(R"(Round\d+:\d+entries)"))); - BOOST_TEST(nextLineMatches(m_output, regex(R"(Round\d+:\d+entries)"))); - BOOST_TEST(nextLineMatches(m_output, regex(R"(Totalhits:\d+)"))); - BOOST_TEST(nextLineMatches(m_output, regex(R"(Totalmisses:\d+)"))); - BOOST_TEST(nextLineMatches(m_output, regex(R"(Sizeofcachedcode:\d+)"))); + BOOST_TEST(nextLineMatches(m_output, std::regex(R"(Round\d+:\d+entries)"))); + BOOST_TEST(nextLineMatches(m_output, std::regex(R"(Round\d+:\d+entries)"))); + BOOST_TEST(nextLineMatches(m_output, std::regex(R"(Totalhits:\d+)"))); + BOOST_TEST(nextLineMatches(m_output, std::regex(R"(Totalmisses:\d+)"))); + BOOST_TEST(nextLineMatches(m_output, std::regex(R"(Sizeofcachedcode:\d+)"))); } BOOST_REQUIRE(stats.roundEntryCounts.size() == 2); @@ -333,13 +332,13 @@ BOOST_FIXTURE_TEST_CASE(run_should_print_cache_stats_if_requested, AlgorithmRunn BOOST_REQUIRE(stats.roundEntryCounts.count(m_options.maxRounds.value()) == 1); size_t round = m_options.maxRounds.value(); - BOOST_TEST(nextLineMatches(m_output, regex(".*"))); - BOOST_TEST(nextLineMatches(m_output, regex("-+CACHESTATS-+"))); - BOOST_TEST(nextLineMatches(m_output, regex("Round" + toString(round - 1) + ":" + toString(stats.roundEntryCounts[round - 1]) + "entries"))); - BOOST_TEST(nextLineMatches(m_output, regex("Round" + toString(round) + ":" + toString(stats.roundEntryCounts[round]) + "entries"))); - BOOST_TEST(nextLineMatches(m_output, regex("Totalhits:" + toString(stats.hits)))); - BOOST_TEST(nextLineMatches(m_output, regex("Totalmisses:" + toString(stats.misses)))); - BOOST_TEST(nextLineMatches(m_output, regex("Sizeofcachedcode:" + toString(stats.totalCodeSize)))); + BOOST_TEST(nextLineMatches(m_output, std::regex(".*"))); + BOOST_TEST(nextLineMatches(m_output, std::regex("-+CACHESTATS-+"))); + BOOST_TEST(nextLineMatches(m_output, std::regex("Round" + toString(round - 1) + ":" + toString(stats.roundEntryCounts[round - 1]) + "entries"))); + BOOST_TEST(nextLineMatches(m_output, std::regex("Round" + toString(round) + ":" + toString(stats.roundEntryCounts[round]) + "entries"))); + BOOST_TEST(nextLineMatches(m_output, std::regex("Totalhits:" + toString(stats.hits)))); + BOOST_TEST(nextLineMatches(m_output, std::regex("Totalmisses:" + toString(stats.misses)))); + BOOST_TEST(nextLineMatches(m_output, std::regex("Sizeofcachedcode:" + toString(stats.totalCodeSize)))); BOOST_TEST(m_output.peek() == EOF); } @@ -355,9 +354,9 @@ BOOST_FIXTURE_TEST_CASE(run_should_print_message_if_cache_stats_requested_but_ca AlgorithmRunner runner(m_population, {nullptr}, m_options, m_output); runner.run(algorithm); - BOOST_TEST(nextLineMatches(m_output, regex(".*"))); - BOOST_TEST(nextLineMatches(m_output, regex("-+CACHESTATS-+"))); - BOOST_TEST(nextLineMatches(m_output, regex(stripWhitespace("Program cache disabled")))); + BOOST_TEST(nextLineMatches(m_output, std::regex(".*"))); + BOOST_TEST(nextLineMatches(m_output, std::regex("-+CACHESTATS-+"))); + BOOST_TEST(nextLineMatches(m_output, std::regex(stripWhitespace("Program cache disabled")))); BOOST_TEST(m_output.peek() == EOF); } @@ -371,18 +370,18 @@ BOOST_FIXTURE_TEST_CASE(run_should_print_partial_stats_and_message_if_some_cache RandomisingAlgorithm algorithm; CharStream sourceStream = CharStream("{}", ""); - shared_ptr cache = make_shared(get(Program::load(sourceStream))); + std::shared_ptr cache = std::make_shared(std::get(Program::load(sourceStream))); AlgorithmRunner runner(m_population, {cache, nullptr}, m_options, m_output); BOOST_REQUIRE(cache->gatherStats().roundEntryCounts.size() == 0); runner.run(algorithm); - BOOST_TEST(nextLineMatches(m_output, regex(".*"))); - BOOST_TEST(nextLineMatches(m_output, regex("-+CACHESTATS-+"))); - BOOST_TEST(nextLineMatches(m_output, regex(R"(Totalhits:\d+)"))); - BOOST_TEST(nextLineMatches(m_output, regex(R"(Totalmisses:\d+)"))); - BOOST_TEST(nextLineMatches(m_output, regex(R"(Sizeofcachedcode:\d+)"))); - BOOST_TEST(nextLineMatches(m_output, regex(stripWhitespace("Program cache disabled for 1 out of 2 programs")))); + BOOST_TEST(nextLineMatches(m_output, std::regex(".*"))); + BOOST_TEST(nextLineMatches(m_output, std::regex("-+CACHESTATS-+"))); + BOOST_TEST(nextLineMatches(m_output, std::regex(R"(Totalhits:\d+)"))); + BOOST_TEST(nextLineMatches(m_output, std::regex(R"(Totalmisses:\d+)"))); + BOOST_TEST(nextLineMatches(m_output, std::regex(R"(Sizeofcachedcode:\d+)"))); + BOOST_TEST(nextLineMatches(m_output, std::regex(stripWhitespace("Program cache disabled for 1 out of 2 programs")))); BOOST_TEST(m_output.peek() == EOF); } @@ -421,10 +420,10 @@ BOOST_FIXTURE_TEST_CASE(run_should_overwrite_existing_file_if_autosave_file_spec AlgorithmRunner runner(m_population, {}, m_options, m_output); assert(!fs::exists(m_autosavePath)); - vector originalContent = {"Original content"}; + std::vector originalContent = {"Original content"}; { - ofstream tmpFile(m_autosavePath); - tmpFile << originalContent[0] << endl; + std::ofstream tmpFile(m_autosavePath); + tmpFile << originalContent[0] << std::endl; } assert(fs::exists(m_autosavePath)); assert(readLinesFromFile(m_autosavePath) == originalContent); @@ -438,7 +437,7 @@ BOOST_FIXTURE_TEST_CASE(run_should_overwrite_existing_file_if_autosave_file_spec BOOST_FIXTURE_TEST_CASE(run_should_not_save_population_to_file_if_autosave_file_not_specified, AlgorithmRunnerAutosaveFixture) { m_options.maxRounds = 5; - m_options.populationAutosaveFile = nullopt; + m_options.populationAutosaveFile = std::nullopt; AlgorithmRunner runner(m_population, {}, m_options, m_output); assert(!fs::exists(m_autosavePath)); @@ -499,9 +498,9 @@ BOOST_FIXTURE_TEST_CASE(run_should_not_randomise_duplicate_chromosomes_if_not_re BOOST_FIXTURE_TEST_CASE(run_should_clear_cache_at_the_beginning_and_update_it_before_each_round, AlgorithmRunnerFixture) { CharStream sourceStream = CharStream("{}", current_test_case().p_name); - vector> caches = { - make_shared(get(Program::load(sourceStream))), - make_shared(get(Program::load(sourceStream))), + std::vector> caches = { + std::make_shared(std::get(Program::load(sourceStream))), + std::make_shared(std::get(Program::load(sourceStream))), }; m_options.maxRounds = 10; diff --git a/test/yulPhaser/Chromosome.cpp b/test/yulPhaser/Chromosome.cpp index 1d12bf18c161..da109086a916 100644 --- a/test/yulPhaser/Chromosome.cpp +++ b/test/yulPhaser/Chromosome.cpp @@ -40,14 +40,13 @@ #include -using namespace std; using namespace solidity::yul; using namespace solidity::util; namespace solidity::phaser::test { -vector const ChrOmOsoMeSteps{ +std::vector const ChrOmOsoMeSteps{ ConditionalSimplifier::name, FunctionHoister::name, UnusedAssignEliminator::name, @@ -76,10 +75,10 @@ BOOST_AUTO_TEST_CASE(makeRandom_should_use_every_possible_step_with_the_same_pro constexpr int samplesPerStep = 500; constexpr double relativeTolerance = 0.02; - map stepIndices = enumerateOptmisationSteps(); + std::map stepIndices = enumerateOptmisationSteps(); auto chromosome = Chromosome::makeRandom(stepIndices.size() * samplesPerStep); - vector samples; + std::vector samples; for (auto& step: chromosome.optimisationSteps()) samples.push_back(stepIndices.at(step)); @@ -97,7 +96,7 @@ BOOST_AUTO_TEST_CASE(constructor_should_store_genes) BOOST_AUTO_TEST_CASE(constructor_should_store_optimisation_steps) { - vector steps = { + std::vector steps = { StructuralSimplifier::name, BlockFlattener::name, UnusedPruner::name, @@ -108,7 +107,7 @@ BOOST_AUTO_TEST_CASE(constructor_should_store_optimisation_steps) BOOST_AUTO_TEST_CASE(constructor_should_allow_duplicate_steps) { - vector steps = { + std::vector steps = { StructuralSimplifier::name, StructuralSimplifier::name, BlockFlattener::name, @@ -131,7 +130,7 @@ BOOST_AUTO_TEST_CASE(constructor_should_allow_genes_that_do_not_correspond_to_an BOOST_AUTO_TEST_CASE(output_operator_should_create_concise_and_unambiguous_string_representation) { - vector allSteps; + std::vector allSteps; for (auto const& step: OptimiserSuite::allSteps()) allSteps.push_back(step.first); Chromosome chromosome(allSteps); @@ -152,8 +151,8 @@ BOOST_AUTO_TEST_CASE(randomOptimisationStep_should_return_each_step_with_same_pr constexpr int samplesPerStep = 500; constexpr double relativeTolerance = 0.02; - map stepIndices = enumerateOptmisationSteps(); - vector samples; + std::map stepIndices = enumerateOptmisationSteps(); + std::vector samples; for (size_t i = 0; i <= stepIndices.size() * samplesPerStep; ++i) samples.push_back(stepIndices.at(Chromosome::randomOptimisationStep())); @@ -172,7 +171,7 @@ BOOST_AUTO_TEST_CASE(stepsToGenes_should_translate_optimisation_step_names_to_ab BOOST_AUTO_TEST_CASE(genesToSteps_should_translate_optimisation_step_abbreviations_to_names) { - BOOST_TEST(Chromosome::genesToSteps("") == vector{}); + BOOST_TEST(Chromosome::genesToSteps("") == std::vector{}); BOOST_TEST(Chromosome::genesToSteps("ChrOmOsoMe") == ChrOmOsoMeSteps); } diff --git a/test/yulPhaser/Common.cpp b/test/yulPhaser/Common.cpp index 734738483547..c4842045fa3f 100644 --- a/test/yulPhaser/Common.cpp +++ b/test/yulPhaser/Common.cpp @@ -30,7 +30,6 @@ #include #include -using namespace std; using namespace boost::test_tools; using namespace solidity::util; @@ -56,7 +55,7 @@ enum class TestEnum GH, }; -map const TestEnumToStringMap = +std::map const TestEnumToStringMap = { {TestEnum::A, "a"}, {TestEnum::B, "b"}, @@ -64,7 +63,7 @@ map const TestEnumToStringMap = {TestEnum::CD, "c-d"}, {TestEnum::EF, "e f"}, }; -map const StringToTestEnumMap = invertMap(TestEnumToStringMap); +std::map const StringToTestEnumMap = invertMap(TestEnumToStringMap); } @@ -74,29 +73,29 @@ BOOST_AUTO_TEST_SUITE(CommonTest) BOOST_FIXTURE_TEST_CASE(readLinesFromFile_should_return_all_lines_from_a_text_file_as_strings_without_newlines, ReadLinesFromFileFixture) { { - ofstream tmpFile((m_tempDir.path() / "test-file.txt").string()); - tmpFile << endl << "Line 1" << endl << endl << endl << "Line 2" << endl << "#" << endl << endl; + std::ofstream tmpFile((m_tempDir.path() / "test-file.txt").string()); + tmpFile << std::endl << "Line 1" << std::endl << std::endl << std::endl << "Line 2" << std::endl << "#" << std::endl << std::endl; } - vector lines = readLinesFromFile((m_tempDir.path() / "test-file.txt").string()); - BOOST_TEST((lines == vector{"", "Line 1", "", "", "Line 2", "#", ""})); + std::vector lines = readLinesFromFile((m_tempDir.path() / "test-file.txt").string()); + BOOST_TEST((lines == std::vector{"", "Line 1", "", "", "Line 2", "#", ""})); } BOOST_AUTO_TEST_CASE(deserializeChoice_should_convert_string_to_enum) { - istringstream aStream("a"); + std::istringstream aStream("a"); TestEnum aResult; deserializeChoice(aStream, aResult, StringToTestEnumMap); BOOST_CHECK(aResult == TestEnum::A); BOOST_TEST(!aStream.fail()); - istringstream bStream("b"); + std::istringstream bStream("b"); TestEnum bResult; deserializeChoice(bStream, bResult, StringToTestEnumMap); BOOST_CHECK(bResult == TestEnum::B); BOOST_TEST(!bStream.fail()); - istringstream cdStream("c-d"); + std::istringstream cdStream("c-d"); TestEnum cdResult; deserializeChoice(cdStream, cdResult, StringToTestEnumMap); BOOST_CHECK(cdResult == TestEnum::CD); @@ -105,7 +104,7 @@ BOOST_AUTO_TEST_CASE(deserializeChoice_should_convert_string_to_enum) BOOST_AUTO_TEST_CASE(deserializeChoice_should_set_failbit_if_there_is_no_enum_corresponding_to_string) { - istringstream xyzStream("xyz"); + std::istringstream xyzStream("xyz"); TestEnum xyzResult; deserializeChoice(xyzStream, xyzResult, StringToTestEnumMap); BOOST_TEST(xyzStream.fail()); @@ -113,13 +112,13 @@ BOOST_AUTO_TEST_CASE(deserializeChoice_should_set_failbit_if_there_is_no_enum_co BOOST_AUTO_TEST_CASE(deserializeChoice_does_not_have_to_support_strings_with_spaces) { - istringstream abStream("a b"); + std::istringstream abStream("a b"); TestEnum abResult; deserializeChoice(abStream, abResult, StringToTestEnumMap); BOOST_CHECK(abResult == TestEnum::A); BOOST_TEST(!abStream.fail()); - istringstream efStream("e f"); + std::istringstream efStream("e f"); TestEnum efResult; deserializeChoice(efStream, efResult, StringToTestEnumMap); BOOST_TEST(efStream.fail()); diff --git a/test/yulPhaser/FitnessMetrics.cpp b/test/yulPhaser/FitnessMetrics.cpp index bde15a537fd8..7fab2e18935e 100644 --- a/test/yulPhaser/FitnessMetrics.cpp +++ b/test/yulPhaser/FitnessMetrics.cpp @@ -29,7 +29,6 @@ #include -using namespace std; using namespace solidity::langutil; using namespace solidity::util; using namespace solidity::yul; @@ -74,22 +73,22 @@ class ProgramBasedMetricFixture } CharStream m_sourceStream = CharStream(SampleSourceCode, ""); - Chromosome m_chromosome{vector{UnusedPruner::name, EquivalentFunctionCombiner::name}}; - Program m_program = get(Program::load(m_sourceStream)); + Chromosome m_chromosome{std::vector{UnusedPruner::name, EquivalentFunctionCombiner::name}}; + Program m_program = std::get(Program::load(m_sourceStream)); Program m_optimisedProgram = optimisedProgram(m_program); - shared_ptr m_programCache = make_shared(m_program); + std::shared_ptr m_programCache = std::make_shared(m_program); static constexpr CodeWeights m_weights{}; }; class FitnessMetricCombinationFixture: public ProgramBasedMetricFixture { protected: - vector> m_simpleMetrics = { - make_shared(m_program, nullptr, m_weights, 1), - make_shared(m_program, nullptr, m_weights, 2), - make_shared(m_program, nullptr, m_weights, 3), + std::vector> m_simpleMetrics = { + std::make_shared(m_program, nullptr, m_weights, 1), + std::make_shared(m_program, nullptr, m_weights, 2), + std::make_shared(m_program, nullptr, m_weights, 3), }; - vector m_fitness = { + std::vector m_fitness = { m_simpleMetrics[0]->evaluate(m_chromosome), m_simpleMetrics[1]->evaluate(m_chromosome), m_simpleMetrics[2]->evaluate(m_chromosome), @@ -102,7 +101,7 @@ BOOST_AUTO_TEST_SUITE(ProgramBasedMetricTest) BOOST_FIXTURE_TEST_CASE(optimisedProgram_should_return_optimised_program_even_if_cache_not_available, ProgramBasedMetricFixture) { - string code = toString(DummyProgramBasedMetric(m_program, nullptr, m_weights).optimisedProgram(m_chromosome)); + std::string code = toString(DummyProgramBasedMetric(m_program, nullptr, m_weights).optimisedProgram(m_chromosome)); BOOST_TEST(code != toString(m_program)); BOOST_TEST(code == toString(m_optimisedProgram)); @@ -110,7 +109,7 @@ BOOST_FIXTURE_TEST_CASE(optimisedProgram_should_return_optimised_program_even_if BOOST_FIXTURE_TEST_CASE(optimisedProgram_should_use_cache_if_available, ProgramBasedMetricFixture) { - string code = toString(DummyProgramBasedMetric(nullopt, m_programCache, m_weights).optimisedProgram(m_chromosome)); + std::string code = toString(DummyProgramBasedMetric(std::nullopt, m_programCache, m_weights).optimisedProgram(m_chromosome)); BOOST_TEST(code != toString(m_program)); BOOST_TEST(code == toString(m_optimisedProgram)); @@ -119,7 +118,7 @@ BOOST_FIXTURE_TEST_CASE(optimisedProgram_should_use_cache_if_available, ProgramB BOOST_FIXTURE_TEST_CASE(optimisedProgramNoCache_should_return_optimised_program_even_if_cache_not_available, ProgramBasedMetricFixture) { - string code = toString(DummyProgramBasedMetric(m_program, nullptr, m_weights).optimisedProgramNoCache(m_chromosome)); + std::string code = toString(DummyProgramBasedMetric(m_program, nullptr, m_weights).optimisedProgramNoCache(m_chromosome)); BOOST_TEST(code != toString(m_program)); BOOST_TEST(code == toString(m_optimisedProgram)); @@ -127,7 +126,7 @@ BOOST_FIXTURE_TEST_CASE(optimisedProgramNoCache_should_return_optimised_program_ BOOST_FIXTURE_TEST_CASE(optimisedProgramNoCache_should_not_use_cache_even_if_available, ProgramBasedMetricFixture) { - string code = toString(DummyProgramBasedMetric(nullopt, m_programCache, m_weights).optimisedProgramNoCache(m_chromosome)); + std::string code = toString(DummyProgramBasedMetric(std::nullopt, m_programCache, m_weights).optimisedProgramNoCache(m_chromosome)); BOOST_TEST(code != toString(m_program)); BOOST_TEST(code == toString(m_optimisedProgram)); @@ -147,7 +146,7 @@ BOOST_FIXTURE_TEST_CASE(evaluate_should_compute_size_of_the_optimised_program, P BOOST_FIXTURE_TEST_CASE(evaluate_should_be_able_to_use_program_cache_if_available, ProgramBasedMetricFixture) { - size_t fitness = ProgramSize(nullopt, m_programCache, m_weights).evaluate(m_chromosome); + size_t fitness = ProgramSize(std::nullopt, m_programCache, m_weights).evaluate(m_chromosome); BOOST_TEST(fitness != m_program.codeSize(m_weights)); BOOST_TEST(fitness == m_optimisedProgram.codeSize(m_weights)); @@ -190,7 +189,7 @@ BOOST_FIXTURE_TEST_CASE(evaluate_should_compute_the_size_ratio_between_optimised BOOST_FIXTURE_TEST_CASE(evaluate_should_be_able_to_use_program_cache_if_available, ProgramBasedMetricFixture) { BOOST_TEST( - RelativeProgramSize(nullopt, m_programCache, 3, m_weights).evaluate(m_chromosome) == + RelativeProgramSize(std::nullopt, m_programCache, 3, m_weights).evaluate(m_chromosome) == round(1000.0 * double(m_optimisedProgram.codeSize(m_weights)) / double(m_program.codeSize(m_weights))) ); BOOST_TEST(m_programCache->size() == m_chromosome.length()); @@ -219,7 +218,7 @@ BOOST_FIXTURE_TEST_CASE(evaluate_should_return_one_if_number_of_repetitions_is_z BOOST_FIXTURE_TEST_CASE(evaluate_should_return_one_if_the_original_program_size_is_zero, ProgramBasedMetricFixture) { CharStream sourceStream = CharStream("{}", ""); - Program program = get(Program::load(sourceStream)); + Program program = std::get(Program::load(sourceStream)); RelativeProgramSize metric(program, nullptr, 3, m_weights); @@ -264,7 +263,7 @@ BOOST_FIXTURE_TEST_CASE(FitnessMetricMaximum_evaluate_should_compute_maximum_of_ FitnessMetricMaximum metric(m_simpleMetrics); assert(m_simpleMetrics.size() == 3); - BOOST_TEST(metric.evaluate(m_chromosome) == max(m_fitness[0], max(m_fitness[1], m_fitness[2]))); + BOOST_TEST(metric.evaluate(m_chromosome) == std::max(m_fitness[0], std::max(m_fitness[1], m_fitness[2]))); BOOST_TEST(metric.metrics() == m_simpleMetrics); } @@ -273,7 +272,7 @@ BOOST_FIXTURE_TEST_CASE(FitnessMetricMinimum_evaluate_should_compute_minimum_of_ FitnessMetricMinimum metric(m_simpleMetrics); assert(m_simpleMetrics.size() == 3); - BOOST_TEST(metric.evaluate(m_chromosome) == min(m_fitness[0], min(m_fitness[1], m_fitness[2]))); + BOOST_TEST(metric.evaluate(m_chromosome) == std::min(m_fitness[0], std::min(m_fitness[1], m_fitness[2]))); BOOST_TEST(metric.metrics() == m_simpleMetrics); } diff --git a/test/yulPhaser/GeneticAlgorithms.cpp b/test/yulPhaser/GeneticAlgorithms.cpp index 29c9cfa2ecaf..c3b661334499 100644 --- a/test/yulPhaser/GeneticAlgorithms.cpp +++ b/test/yulPhaser/GeneticAlgorithms.cpp @@ -29,7 +29,6 @@ #include #include -using namespace std; using namespace boost::unit_test::framework; using namespace boost::test_tools; using namespace solidity::util; @@ -40,7 +39,7 @@ namespace solidity::phaser::test class GeneticAlgorithmFixture { protected: - shared_ptr m_fitnessMetric = make_shared(); + std::shared_ptr m_fitnessMetric = std::make_shared(); }; class ClassicGeneticAlgorithmFixture: public GeneticAlgorithmFixture @@ -64,41 +63,41 @@ BOOST_AUTO_TEST_SUITE(RandomAlgorithmTest) BOOST_FIXTURE_TEST_CASE(runNextRound_should_preserve_elite_and_randomise_rest_of_population, GeneticAlgorithmFixture) { auto population = Population::makeRandom(m_fitnessMetric, 4, 3, 3) + Population::makeRandom(m_fitnessMetric, 4, 5, 5); - assert((chromosomeLengths(population) == vector{3, 3, 3, 3, 5, 5, 5, 5})); + assert((chromosomeLengths(population) == std::vector{3, 3, 3, 3, 5, 5, 5, 5})); RandomAlgorithm algorithm({0.5, 1, 1}); Population newPopulation = algorithm.runNextRound(population); - BOOST_TEST((chromosomeLengths(newPopulation) == vector{1, 1, 1, 1, 3, 3, 3, 3})); + BOOST_TEST((chromosomeLengths(newPopulation) == std::vector{1, 1, 1, 1, 3, 3, 3, 3})); } BOOST_FIXTURE_TEST_CASE(runNextRound_should_not_replace_elite_with_worse_individuals, GeneticAlgorithmFixture) { auto population = Population::makeRandom(m_fitnessMetric, 4, 3, 3) + Population::makeRandom(m_fitnessMetric, 4, 5, 5); - assert((chromosomeLengths(population) == vector{3, 3, 3, 3, 5, 5, 5, 5})); + assert((chromosomeLengths(population) == std::vector{3, 3, 3, 3, 5, 5, 5, 5})); RandomAlgorithm algorithm({0.5, 7, 7}); Population newPopulation = algorithm.runNextRound(population); - BOOST_TEST((chromosomeLengths(newPopulation) == vector{3, 3, 3, 3, 7, 7, 7, 7})); + BOOST_TEST((chromosomeLengths(newPopulation) == std::vector{3, 3, 3, 3, 7, 7, 7, 7})); } BOOST_FIXTURE_TEST_CASE(runNextRound_should_replace_all_chromosomes_if_zero_size_elite, GeneticAlgorithmFixture) { auto population = Population::makeRandom(m_fitnessMetric, 4, 3, 3) + Population::makeRandom(m_fitnessMetric, 4, 5, 5); - assert((chromosomeLengths(population) == vector{3, 3, 3, 3, 5, 5, 5, 5})); + assert((chromosomeLengths(population) == std::vector{3, 3, 3, 3, 5, 5, 5, 5})); RandomAlgorithm algorithm({0.0, 1, 1}); Population newPopulation = algorithm.runNextRound(population); - BOOST_TEST((chromosomeLengths(newPopulation) == vector{1, 1, 1, 1, 1, 1, 1, 1})); + BOOST_TEST((chromosomeLengths(newPopulation) == std::vector{1, 1, 1, 1, 1, 1, 1, 1})); } BOOST_FIXTURE_TEST_CASE(runNextRound_should_not_replace_any_chromosomes_if_whole_population_is_the_elite, GeneticAlgorithmFixture) { auto population = Population::makeRandom(m_fitnessMetric, 4, 3, 3) + Population::makeRandom(m_fitnessMetric, 4, 5, 5); - assert((chromosomeLengths(population) == vector{3, 3, 3, 3, 5, 5, 5, 5})); + assert((chromosomeLengths(population) == std::vector{3, 3, 3, 3, 5, 5, 5, 5})); RandomAlgorithm algorithm({1.0, 1, 1}); Population newPopulation = algorithm.runNextRound(population); - BOOST_TEST((chromosomeLengths(newPopulation) == vector{3, 3, 3, 3, 5, 5, 5, 5})); + BOOST_TEST((chromosomeLengths(newPopulation) == std::vector{3, 3, 3, 3, 5, 5, 5, 5})); } BOOST_AUTO_TEST_SUITE_END() @@ -107,7 +106,7 @@ BOOST_AUTO_TEST_SUITE(GenerationalElitistWithExclusivePoolsTest) BOOST_FIXTURE_TEST_CASE(runNextRound_should_preserve_elite_and_regenerate_rest_of_population, GeneticAlgorithmFixture) { auto population = Population::makeRandom(m_fitnessMetric, 6, 3, 3) + Population::makeRandom(m_fitnessMetric, 4, 5, 5); - assert((chromosomeLengths(population) == vector{3, 3, 3, 3, 3, 3, 5, 5, 5, 5})); + assert((chromosomeLengths(population) == std::vector{3, 3, 3, 3, 3, 3, 5, 5, 5, 5})); GenerationalElitistWithExclusivePools::Options options = { /* mutationPoolSize = */ 0.2, @@ -123,13 +122,13 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_preserve_elite_and_regenerate_rest_o Population newPopulation = algorithm.runNextRound(population); - BOOST_TEST((chromosomeLengths(newPopulation) == vector{0, 0, 3, 3, 3, 3, 3, 3, 3, 3})); + BOOST_TEST((chromosomeLengths(newPopulation) == std::vector{0, 0, 3, 3, 3, 3, 3, 3, 3, 3})); } BOOST_FIXTURE_TEST_CASE(runNextRound_should_not_replace_elite_with_worse_individuals, GeneticAlgorithmFixture) { auto population = Population::makeRandom(m_fitnessMetric, 6, 3, 3) + Population::makeRandom(m_fitnessMetric, 4, 5, 5); - assert(chromosomeLengths(population) == (vector{3, 3, 3, 3, 3, 3, 5, 5, 5, 5})); + assert(chromosomeLengths(population) == (std::vector{3, 3, 3, 3, 3, 3, 5, 5, 5, 5})); GenerationalElitistWithExclusivePools::Options options = { /* mutationPoolSize = */ 0.2, @@ -145,7 +144,7 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_not_replace_elite_with_worse_individ Population newPopulation = algorithm.runNextRound(population); - BOOST_TEST((chromosomeLengths(newPopulation) == vector{3, 3, 3, 3, 3, 3, 3, 3, 7, 7})); + BOOST_TEST((chromosomeLengths(newPopulation) == std::vector{3, 3, 3, 3, 3, 3, 3, 3, 7, 7})); } BOOST_FIXTURE_TEST_CASE(runNextRound_should_generate_individuals_in_the_crossover_pool_by_mutating_the_elite, GeneticAlgorithmFixture) @@ -169,7 +168,7 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_generate_individuals_in_the_crossove BOOST_TEST(( chromosomeLengths(newPopulation) == - vector{0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 11, 11, 11} + std::vector{0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 11, 11, 11} )); } @@ -179,7 +178,7 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_generate_individuals_in_the_crossove Population(m_fitnessMetric, {Chromosome("aa"), Chromosome("ff")}) + Population::makeRandom(m_fitnessMetric, 8, 6, 6) ); - assert((chromosomeLengths(population) == vector{2, 2, 6, 6, 6, 6, 6, 6, 6, 6})); + assert((chromosomeLengths(population) == std::vector{2, 2, 6, 6, 6, 6, 6, 6, 6, 6})); GenerationalElitistWithExclusivePools::Options options = { /* mutationPoolSize = */ 0.0, @@ -196,8 +195,8 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_generate_individuals_in_the_crossove SimulationRNG::reset(1); Population newPopulation = algorithm.runNextRound(population); - vector const& newIndividuals = newPopulation.individuals(); - BOOST_TEST((chromosomeLengths(newPopulation) == vector{2, 2, 2, 2, 2, 2, 2, 2, 2, 2})); + std::vector const& newIndividuals = newPopulation.individuals(); + BOOST_TEST((chromosomeLengths(newPopulation) == std::vector{2, 2, 2, 2, 2, 2, 2, 2, 2, 2})); for (auto& individual: newIndividuals) BOOST_TEST(( individual.chromosome == Chromosome("aa") || @@ -228,7 +227,7 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_select_individuals_with_probability_ Population::makeRandom(m_fitnessMetric, populationSize / 4, 2, 2) + Population::makeRandom(m_fitnessMetric, populationSize / 4, 3, 3); - map expectedProbabilities = { + std::map expectedProbabilities = { {0, 4.0 / (4 + 3 + 2 + 1)}, {1, 3.0 / (4 + 3 + 2 + 1)}, {2, 2.0 / (4 + 3 + 2 + 1)}, @@ -252,9 +251,9 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_select_individuals_with_probability_ BOOST_TEST(newPopulation.individuals().size() == population.individuals().size()); - vector newFitness = chromosomeLengths(newPopulation); - BOOST_TEST(abs(mean(newFitness) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(newFitness, expectedValue) - variance) < variance * relativeTolerance); + std::vector newFitness = chromosomeLengths(newPopulation); + BOOST_TEST(std::abs(mean(newFitness) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(newFitness, expectedValue) - variance) < variance * relativeTolerance); } BOOST_FIXTURE_TEST_CASE(runNextRound_should_select_only_individuals_existing_in_the_original_population, ClassicGeneticAlgorithmFixture) @@ -262,7 +261,7 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_select_only_individuals_existing_in_ constexpr size_t populationSize = 1000; auto population = Population::makeRandom(m_fitnessMetric, populationSize, 1, 10); - set originalSteps; + std::set originalSteps; for (auto const& individual: population.individuals()) originalSteps.insert(toString(individual.chromosome)); @@ -281,8 +280,8 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_do_crossover, ClassicGeneticAlgorith Chromosome("gg"), Chromosome("gg"), Chromosome("gg"), }); - set originalSteps{"aa", "ff", "gg"}; - set crossedSteps{"af", "fa", "fg", "gf", "ga", "ag"}; + std::set originalSteps{"aa", "ff", "gg"}; + std::set crossedSteps{"af", "fa", "fg", "gf", "ga", "ag"}; m_options.crossoverChance = 0.8; ClassicGeneticAlgorithm algorithm(m_options); @@ -312,22 +311,22 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_do_mutation, ClassicGeneticAlgorithm double const variance = m_options.mutationChance * (1 - m_options.mutationChance); Chromosome chromosome("aaaaaaaaaa"); - vector chromosomes(populationSize, chromosome); + std::vector chromosomes(populationSize, chromosome); Population population(m_fitnessMetric, chromosomes); SimulationRNG::reset(1); Population newPopulation = algorithm.runNextRound(population); - vector bernoulliTrials; + std::vector bernoulliTrials; for (auto const& individual: newPopulation.individuals()) { - string steps = toString(individual.chromosome); + std::string steps = toString(individual.chromosome); for (char step: steps) bernoulliTrials.push_back(static_cast(step != 'a')); } - BOOST_TEST(abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); } BOOST_FIXTURE_TEST_CASE(runNextRound_should_do_deletion, ClassicGeneticAlgorithmFixture) @@ -341,22 +340,22 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_do_deletion, ClassicGeneticAlgorithm double const variance = m_options.deletionChance * (1 - m_options.deletionChance); Chromosome chromosome("aaaaaaaaaa"); - vector chromosomes(populationSize, chromosome); + std::vector chromosomes(populationSize, chromosome); Population population(m_fitnessMetric, chromosomes); SimulationRNG::reset(1); Population newPopulation = algorithm.runNextRound(population); - vector bernoulliTrials; + std::vector bernoulliTrials; for (auto const& individual: newPopulation.individuals()) { - string steps = toString(individual.chromosome); + std::string steps = toString(individual.chromosome); for (size_t i = 0; i < chromosome.length(); ++i) bernoulliTrials.push_back(static_cast(i >= steps.size())); } - BOOST_TEST(abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); } BOOST_FIXTURE_TEST_CASE(runNextRound_should_do_addition, ClassicGeneticAlgorithmFixture) @@ -370,16 +369,16 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_do_addition, ClassicGeneticAlgorithm double const variance = m_options.additionChance * (1 - m_options.additionChance); Chromosome chromosome("aaaaaaaaaa"); - vector chromosomes(populationSize, chromosome); + std::vector chromosomes(populationSize, chromosome); Population population(m_fitnessMetric, chromosomes); SimulationRNG::reset(1); Population newPopulation = algorithm.runNextRound(population); - vector bernoulliTrials; + std::vector bernoulliTrials; for (auto const& individual: newPopulation.individuals()) { - string steps = toString(individual.chromosome); + std::string steps = toString(individual.chromosome); for (size_t i = 0; i < chromosome.length() + 1; ++i) { BOOST_REQUIRE(chromosome.length() <= steps.size() && steps.size() <= 2 * chromosome.length() + 1); @@ -387,21 +386,21 @@ BOOST_FIXTURE_TEST_CASE(runNextRound_should_do_addition, ClassicGeneticAlgorithm } } - BOOST_TEST(abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); } BOOST_FIXTURE_TEST_CASE(runNextRound_should_preserve_elite, ClassicGeneticAlgorithmFixture) { auto population = Population::makeRandom(m_fitnessMetric, 4, 3, 3) + Population::makeRandom(m_fitnessMetric, 6, 5, 5); - assert((chromosomeLengths(population) == vector{3, 3, 3, 3, 5, 5, 5, 5, 5, 5})); + assert((chromosomeLengths(population) == std::vector{3, 3, 3, 3, 5, 5, 5, 5, 5, 5})); m_options.elitePoolSize = 0.5; m_options.deletionChance = 1.0; ClassicGeneticAlgorithm algorithm(m_options); Population newPopulation = algorithm.runNextRound(population); - BOOST_TEST((chromosomeLengths(newPopulation) == vector{0, 0, 0, 0, 0, 3, 3, 3, 3, 5})); + BOOST_TEST((chromosomeLengths(newPopulation) == std::vector{0, 0, 0, 0, 0, 3, 3, 3, 3, 5})); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/yulPhaser/Mutations.cpp b/test/yulPhaser/Mutations.cpp index 8e1d0238b3ef..a5a715e23a2a 100644 --- a/test/yulPhaser/Mutations.cpp +++ b/test/yulPhaser/Mutations.cpp @@ -30,7 +30,6 @@ #include #include -using namespace std; using namespace solidity::util; using namespace solidity::yul; @@ -48,7 +47,7 @@ BOOST_AUTO_TEST_CASE(geneRandomisation_should_iterate_over_genes_and_replace_the // Use genes that do not represent valid step abbreviations to be able to easily spot added steps. assert(OptimiserSuite::stepAbbreviationToNameMap().count('.') == 0); - Chromosome input = Chromosome(string(inputLength, '.')); + Chromosome input = Chromosome(std::string(inputLength, '.')); SimulationRNG::reset(1); for (size_t randomisationChancePercent = 20; randomisationChancePercent <= 100; randomisationChancePercent += 20) @@ -56,7 +55,7 @@ BOOST_AUTO_TEST_CASE(geneRandomisation_should_iterate_over_genes_and_replace_the double const randomisationChance = double(randomisationChancePercent) / 100.0; Chromosome output = geneRandomisation(randomisationChance)(input); - string outputGenes = output.genes(); + std::string outputGenes = output.genes(); BOOST_REQUIRE(output.length() == input.length()); double const expectedValue = randomisationChance; @@ -66,15 +65,15 @@ BOOST_AUTO_TEST_CASE(geneRandomisation_should_iterate_over_genes_and_replace_the (inputLength - randomisedGeneCount) * expectedValue * expectedValue + randomisedGeneCount * (1 - expectedValue) * (1 - expectedValue); - BOOST_TEST(abs(randomisedGeneCount / inputLength - expectedValue) < tolerance); - BOOST_TEST(abs(squaredError / inputLength - variance) < tolerance); + BOOST_TEST(std::abs(randomisedGeneCount / inputLength - expectedValue) < tolerance); + BOOST_TEST(std::abs(squaredError / inputLength - variance) < tolerance); } } BOOST_AUTO_TEST_CASE(geneRandomisation_should_return_identical_chromosome_if_probability_is_zero) { Chromosome chromosome("fcCUnDvejsrmV"); - function mutation = geneRandomisation(0.0); + std::function mutation = geneRandomisation(0.0); BOOST_TEST(mutation(chromosome) == chromosome); } @@ -86,7 +85,7 @@ BOOST_AUTO_TEST_CASE(geneDeletion_should_iterate_over_genes_and_delete_them_with // Use genes that do not represent valid step abbreviations to be able to easily spot added steps. assert(OptimiserSuite::stepAbbreviationToNameMap().count('.') == 0); - Chromosome input = Chromosome(string(inputLength, '.')); + Chromosome input = Chromosome(std::string(inputLength, '.')); SimulationRNG::reset(1); for (size_t deletionChancePercent = 20; deletionChancePercent < 100; deletionChancePercent += 20) @@ -94,7 +93,7 @@ BOOST_AUTO_TEST_CASE(geneDeletion_should_iterate_over_genes_and_delete_them_with double const deletionChance = double(deletionChancePercent) / 100.0; Chromosome output = geneDeletion(deletionChance)(input); - string outputGenes = output.genes(); + std::string outputGenes = output.genes(); BOOST_REQUIRE(output.length() <= input.length()); BOOST_REQUIRE(static_cast(count(outputGenes.begin(), outputGenes.end(), '.')) == output.length()); @@ -105,15 +104,15 @@ BOOST_AUTO_TEST_CASE(geneDeletion_should_iterate_over_genes_and_delete_them_with (double(inputLength) - deletedGeneCount) * expectedValue * expectedValue + deletedGeneCount * (1.0 - expectedValue) * (1.0 - expectedValue); - BOOST_TEST(abs(deletedGeneCount / double(inputLength) - expectedValue) < tolerance); - BOOST_TEST(abs(squaredError / double(inputLength) - variance) < tolerance); + BOOST_TEST(std::abs(deletedGeneCount / double(inputLength) - expectedValue) < tolerance); + BOOST_TEST(std::abs(squaredError / double(inputLength) - variance) < tolerance); } } BOOST_AUTO_TEST_CASE(geneDeletion_should_return_identical_chromosome_if_probability_is_zero) { Chromosome chromosome("fcCUnDvejsrmV"); - function mutation = geneDeletion(0.0); + std::function mutation = geneDeletion(0.0); BOOST_TEST(mutation(chromosome) == chromosome); } @@ -121,7 +120,7 @@ BOOST_AUTO_TEST_CASE(geneDeletion_should_return_identical_chromosome_if_probabil BOOST_AUTO_TEST_CASE(geneDeletion_should_delete_all_genes_if_probability_is_one) { Chromosome chromosome("fcCUnDvejsrmV"); - function mutation = geneDeletion(1.0); + std::function mutation = geneDeletion(1.0); BOOST_TEST(mutation(chromosome) == Chromosome("")); } @@ -134,7 +133,7 @@ BOOST_AUTO_TEST_CASE(geneAddition_should_iterate_over_gene_positions_and_insert_ // Use genes that do not represent valid step abbreviations to be able to easily spot added steps. assert(OptimiserSuite::stepAbbreviationToNameMap().count('.') == 0); - Chromosome input = Chromosome(string(inputLength, '.')); + Chromosome input = Chromosome(std::string(inputLength, '.')); SimulationRNG::reset(1); for (size_t additionChancePercent = 20; additionChancePercent < 100; additionChancePercent += 20) @@ -145,8 +144,8 @@ BOOST_AUTO_TEST_CASE(geneAddition_should_iterate_over_gene_positions_and_insert_ BOOST_REQUIRE(output.length() >= input.length()); BOOST_REQUIRE(output.length() <= inputLength + maxAdditions); - string_view outputGenes = output.genes(); - size_t preservedGeneCount = static_cast(count(outputGenes.begin(), outputGenes.end(), '.')); + std::string_view outputGenes = output.genes(); + size_t preservedGeneCount = static_cast(std::count(outputGenes.begin(), outputGenes.end(), '.')); BOOST_REQUIRE(preservedGeneCount == input.length()); double const expectedValue = additionChance; @@ -156,8 +155,8 @@ BOOST_AUTO_TEST_CASE(geneAddition_should_iterate_over_gene_positions_and_insert_ (double(maxAdditions) - addedGeneCount) * expectedValue * expectedValue + addedGeneCount * (1.0 - expectedValue) * (1.0 - expectedValue); - BOOST_TEST(abs(addedGeneCount / double(maxAdditions) - expectedValue) < tolerance); - BOOST_TEST(abs(squaredError / double(maxAdditions) - variance) < tolerance); + BOOST_TEST(std::abs(addedGeneCount / double(maxAdditions) - expectedValue) < tolerance); + BOOST_TEST(std::abs(squaredError / double(maxAdditions) - variance) < tolerance); } } @@ -165,7 +164,7 @@ BOOST_AUTO_TEST_CASE(geneAddition_should_be_able_to_insert_before_first_position { SimulationRNG::reset(7); Chromosome chromosome("fcCUnDvejs"); - function mutation = geneAddition(0.1); + std::function mutation = geneAddition(0.1); Chromosome mutatedChromosome = mutation(chromosome); BOOST_TEST(mutatedChromosome.length() > chromosome.length()); @@ -176,7 +175,7 @@ BOOST_AUTO_TEST_CASE(geneAddition_should_be_able_to_insert_after_last_position) { SimulationRNG::reset(81); Chromosome chromosome("fcCUnDvejs"); - function mutation = geneAddition(0.1); + std::function mutation = geneAddition(0.1); Chromosome mutatedChromosome = mutation(chromosome); BOOST_TEST(mutatedChromosome.length() > chromosome.length()); @@ -186,7 +185,7 @@ BOOST_AUTO_TEST_CASE(geneAddition_should_be_able_to_insert_after_last_position) BOOST_AUTO_TEST_CASE(geneAddition_should_return_identical_chromosome_if_probability_is_zero) { Chromosome chromosome("fcCUnDvejsrmV"); - function mutation = geneAddition(0.0); + std::function mutation = geneAddition(0.0); BOOST_TEST(mutation(chromosome) == chromosome); } @@ -194,12 +193,12 @@ BOOST_AUTO_TEST_CASE(geneAddition_should_return_identical_chromosome_if_probabil BOOST_AUTO_TEST_CASE(geneAddition_should_insert_genes_at_all_positions_if_probability_is_one) { Chromosome chromosome("fcCUnDvejsrmV"); - function mutation = geneAddition(1.0); + std::function mutation = geneAddition(1.0); Chromosome mutatedChromosome = mutation(chromosome); BOOST_TEST(mutatedChromosome.length() == chromosome.length() * 2 + 1); - vector originalGenes; + std::vector originalGenes; for (size_t i = 0; i < mutatedChromosome.length() - 1; ++i) if (i % 2 == 1) originalGenes.push_back(mutatedChromosome.optimisationSteps()[i]); @@ -211,7 +210,7 @@ BOOST_AUTO_TEST_CASE(alternativeMutations_should_choose_between_mutations_with_g { SimulationRNG::reset(1); Chromosome chromosome("a"); - function mutation = alternativeMutations( + std::function mutation = alternativeMutations( 0.8, wholeChromosomeReplacement(Chromosome("c")), wholeChromosomeReplacement(Chromosome("f")) @@ -234,7 +233,7 @@ BOOST_AUTO_TEST_CASE(alternativeMutations_should_choose_between_mutations_with_g BOOST_AUTO_TEST_CASE(alternativeMutations_should_always_choose_first_mutation_if_probability_is_one) { Chromosome chromosome("a"); - function mutation = alternativeMutations( + std::function mutation = alternativeMutations( 1.0, wholeChromosomeReplacement(Chromosome("c")), wholeChromosomeReplacement(Chromosome("f")) @@ -247,7 +246,7 @@ BOOST_AUTO_TEST_CASE(alternativeMutations_should_always_choose_first_mutation_if BOOST_AUTO_TEST_CASE(alternativeMutations_should_always_choose_second_mutation_if_probability_is_zero) { Chromosome chromosome("a"); - function mutation = alternativeMutations( + std::function mutation = alternativeMutations( 0.0, wholeChromosomeReplacement(Chromosome("c")), wholeChromosomeReplacement(Chromosome("f")) @@ -260,8 +259,8 @@ BOOST_AUTO_TEST_CASE(alternativeMutations_should_always_choose_second_mutation_i BOOST_AUTO_TEST_CASE(mutationSequence_should_apply_all_mutations) { Chromosome chromosome("aaaaa"); - vector steps = Chromosome::genesToSteps("gfc"); - function mutation = mutationSequence({ + std::vector steps = Chromosome::genesToSteps("gfc"); + std::function mutation = mutationSequence({ geneSubstitution(3, steps[0]), geneSubstitution(2, steps[1]), geneSubstitution(1, steps[2]), @@ -273,8 +272,8 @@ BOOST_AUTO_TEST_CASE(mutationSequence_should_apply_all_mutations) BOOST_AUTO_TEST_CASE(mutationSequence_apply_mutations_in_the_order_they_are_given) { Chromosome chromosome("aa"); - vector steps = Chromosome::genesToSteps("gcfo"); - function mutation = mutationSequence({ + std::vector steps = Chromosome::genesToSteps("gcfo"); + std::function mutation = mutationSequence({ geneSubstitution(0, steps[0]), geneSubstitution(1, steps[1]), geneSubstitution(0, steps[2]), @@ -287,14 +286,14 @@ BOOST_AUTO_TEST_CASE(mutationSequence_apply_mutations_in_the_order_they_are_give BOOST_AUTO_TEST_CASE(mutationSequence_should_return_unmodified_chromosome_if_given_no_mutations) { Chromosome chromosome("aa"); - function mutation = mutationSequence({}); + std::function mutation = mutationSequence({}); BOOST_TEST(mutation(chromosome) == chromosome); } BOOST_AUTO_TEST_CASE(randomPointCrossover_should_swap_chromosome_parts_at_random_point) { - function crossover = randomPointCrossover(); + std::function crossover = randomPointCrossover(); SimulationRNG::reset(1); Chromosome result1 = crossover(Chromosome("aaaaaaaaaa"), Chromosome("cccccc")); @@ -307,22 +306,22 @@ BOOST_AUTO_TEST_CASE(randomPointCrossover_should_swap_chromosome_parts_at_random BOOST_AUTO_TEST_CASE(symmetricRandomPointCrossover_should_swap_chromosome_parts_at_random_point) { - function crossover = symmetricRandomPointCrossover(); + std::function crossover = symmetricRandomPointCrossover(); SimulationRNG::reset(1); - tuple result1 = crossover(Chromosome("aaaaaaaaaa"), Chromosome("cccccc")); - tuple expectedPair1 = {Chromosome("aaaccc"), Chromosome("cccaaaaaaa")}; + std::tuple result1 = crossover(Chromosome("aaaaaaaaaa"), Chromosome("cccccc")); + std::tuple expectedPair1 = {Chromosome("aaaccc"), Chromosome("cccaaaaaaa")}; BOOST_TEST(result1 == expectedPair1); - tuple result2 = crossover(Chromosome("cccccc"), Chromosome("aaaaaaaaaa")); - tuple expectedPair2 = {Chromosome("ccccccaaaa"), Chromosome("aaaaaa")}; + std::tuple result2 = crossover(Chromosome("cccccc"), Chromosome("aaaaaaaaaa")); + std::tuple expectedPair2 = {Chromosome("ccccccaaaa"), Chromosome("aaaaaa")}; BOOST_TEST(result2 == expectedPair2); } BOOST_AUTO_TEST_CASE(randomPointCrossover_should_only_consider_points_available_on_both_chromosomes) { SimulationRNG::reset(1); - function crossover = randomPointCrossover(); + std::function crossover = randomPointCrossover(); for (size_t i = 0; i < 30; ++i) { @@ -346,7 +345,7 @@ BOOST_AUTO_TEST_CASE(randomPointCrossover_should_only_consider_points_available_ BOOST_AUTO_TEST_CASE(randomPointCrossover_should_never_split_at_position_zero_if_chromosomes_are_splittable) { SimulationRNG::reset(1); - function crossover = randomPointCrossover(); + std::function crossover = randomPointCrossover(); for (size_t i = 0; i < 30; ++i) { @@ -360,7 +359,7 @@ BOOST_AUTO_TEST_CASE(randomPointCrossover_should_never_split_at_position_zero_if BOOST_AUTO_TEST_CASE(randomPointCrossover_should_never_split_at_position_zero_if_chromosomes_are_not_empty) { SimulationRNG::reset(1); - function crossover = randomPointCrossover(); + std::function crossover = randomPointCrossover(); for (size_t i = 0; i < 30; ++i) { @@ -373,7 +372,7 @@ BOOST_AUTO_TEST_CASE(randomPointCrossover_should_never_split_at_position_zero_if BOOST_AUTO_TEST_CASE(randomPointCrossover_should_work_even_if_one_chromosome_is_unsplittable) { - function crossover = randomPointCrossover(); + std::function crossover = randomPointCrossover(); SimulationRNG::reset(1); BOOST_CHECK(crossover(Chromosome("ff"), Chromosome("a")) == Chromosome("f")); @@ -385,7 +384,7 @@ BOOST_AUTO_TEST_CASE(randomPointCrossover_should_split_at_position_zero_only_if_ Chromosome empty(""); Chromosome unsplittable("a"); Chromosome splittable("aaaa"); - function crossover = randomPointCrossover(); + std::function crossover = randomPointCrossover(); SimulationRNG::reset(1); BOOST_CHECK(crossover(empty, empty) == empty); @@ -447,13 +446,13 @@ BOOST_AUTO_TEST_CASE(fixedPointCrossover_should_split_at_end_of_shorter_chromoso BOOST_AUTO_TEST_CASE(fixedPointCrossover_should_select_correct_split_point_for_unsplittable_chromosomes) { - function crossover00 = fixedPointCrossover(0.0); + std::function crossover00 = fixedPointCrossover(0.0); BOOST_CHECK(crossover00(Chromosome("fff"), Chromosome("a")) == Chromosome("a")); BOOST_CHECK(crossover00(Chromosome("a"), Chromosome("fff")) == Chromosome("fff")); BOOST_CHECK(crossover00(Chromosome("f"), Chromosome("a")) == Chromosome("a")); - function crossover10 = fixedPointCrossover(1.0); + std::function crossover10 = fixedPointCrossover(1.0); BOOST_CHECK(crossover10(Chromosome("fff"), Chromosome("a")) == Chromosome("f")); BOOST_CHECK(crossover10(Chromosome("a"), Chromosome("fff")) == Chromosome("aff")); @@ -466,14 +465,14 @@ BOOST_AUTO_TEST_CASE(fixedPointCrossover_should_always_use_position_zero_as_spli Chromosome unsplittable("f"); Chromosome splittable("aaaa"); - function crossover00 = fixedPointCrossover(0.0); + std::function crossover00 = fixedPointCrossover(0.0); BOOST_CHECK(crossover00(empty, empty) == empty); BOOST_CHECK(crossover00(unsplittable, empty) == empty); BOOST_CHECK(crossover00(empty, unsplittable) == unsplittable); BOOST_CHECK(crossover00(splittable, empty) == empty); BOOST_CHECK(crossover00(empty, splittable) == splittable); - function crossover10 = fixedPointCrossover(1.0); + std::function crossover10 = fixedPointCrossover(1.0); BOOST_CHECK(crossover10(empty, empty) == empty); BOOST_CHECK(crossover10(unsplittable, empty) == empty); BOOST_CHECK(crossover10(empty, unsplittable) == unsplittable); @@ -483,7 +482,7 @@ BOOST_AUTO_TEST_CASE(fixedPointCrossover_should_always_use_position_zero_as_spli BOOST_AUTO_TEST_CASE(randomTwoPointCrossover_should_swap_chromosome_parts_between_two_random_points) { - function crossover = randomTwoPointCrossover(); + std::function crossover = randomTwoPointCrossover(); SimulationRNG::reset(1); Chromosome result1 = crossover(Chromosome("aaaaaaaaaa"), Chromosome("cccccc")); @@ -496,21 +495,21 @@ BOOST_AUTO_TEST_CASE(randomTwoPointCrossover_should_swap_chromosome_parts_betwee BOOST_AUTO_TEST_CASE(symmetricRandomTwoPointCrossover_should_swap_chromosome_parts_at_random_point) { - function crossover = symmetricRandomTwoPointCrossover(); + std::function crossover = symmetricRandomTwoPointCrossover(); SimulationRNG::reset(1); - tuple result1 = crossover(Chromosome("aaaaaaaaaa"), Chromosome("cccccc")); - tuple expectedPair1 = {Chromosome("aaacccaaaa"), Chromosome("cccaaa")}; + std::tuple result1 = crossover(Chromosome("aaaaaaaaaa"), Chromosome("cccccc")); + std::tuple expectedPair1 = {Chromosome("aaacccaaaa"), Chromosome("cccaaa")}; BOOST_TEST(result1 == expectedPair1); - tuple result2 = crossover(Chromosome("cccccc"), Chromosome("aaaaaaaaaa")); - tuple expectedPair2 = {Chromosome("ccccca"), Chromosome("aaaaacaaaa")}; + std::tuple result2 = crossover(Chromosome("cccccc"), Chromosome("aaaaaaaaaa")); + std::tuple expectedPair2 = {Chromosome("ccccca"), Chromosome("aaaaacaaaa")}; BOOST_TEST(result2 == expectedPair2); } BOOST_AUTO_TEST_CASE(randomTwoPointCrossover_should_only_consider_points_available_on_both_chromosomes) { - function crossover = randomTwoPointCrossover(); + std::function crossover = randomTwoPointCrossover(); for (size_t i = 0; i < 30; ++i) { @@ -539,7 +538,7 @@ BOOST_AUTO_TEST_CASE(randomTwoPointCrossover_should_only_consider_points_availab BOOST_AUTO_TEST_CASE(uniformCrossover_should_swap_randomly_selected_genes) { - function crossover = uniformCrossover(0.7); + std::function crossover = uniformCrossover(0.7); SimulationRNG::reset(1); Chromosome result1 = crossover(Chromosome("aaaaaaaaaa"), Chromosome("cccccc")); @@ -552,23 +551,23 @@ BOOST_AUTO_TEST_CASE(uniformCrossover_should_swap_randomly_selected_genes) BOOST_AUTO_TEST_CASE(symmetricUniformCrossover_should_swap_randomly_selected_genes) { - function crossover = symmetricUniformCrossover(0.7); + std::function crossover = symmetricUniformCrossover(0.7); SimulationRNG::reset(1); - tuple result1 = crossover(Chromosome("aaaaaaaaaa"), Chromosome("cccccc")); - tuple expectedPair1 = {Chromosome("caaacc"), Chromosome("acccaaaaaa")}; + std::tuple result1 = crossover(Chromosome("aaaaaaaaaa"), Chromosome("cccccc")); + std::tuple expectedPair1 = {Chromosome("caaacc"), Chromosome("acccaaaaaa")}; BOOST_TEST(result1 == expectedPair1); - tuple result2 = crossover(Chromosome("cccccc"), Chromosome("aaaaaaaaaa")); - tuple expectedPair2 = {Chromosome("caaaaaaaaa"), Chromosome("accccc")}; + std::tuple result2 = crossover(Chromosome("cccccc"), Chromosome("aaaaaaaaaa")); + std::tuple expectedPair2 = {Chromosome("caaaaaaaaa"), Chromosome("accccc")}; BOOST_TEST(result2 == expectedPair2); } BOOST_AUTO_TEST_CASE(uniformCrossover_should_only_consider_points_available_on_both_chromosomes) { - function crossover = uniformCrossover(0.7); + std::function crossover = uniformCrossover(0.7); - set expectedPatterns = { + std::set expectedPatterns = { "TTTTTTTTTTTTTTTTTTTT", "aTTTTTTTTTTTTTTTTTTT", "TaTTTTTTTTTTTTTTTTTT", @@ -616,20 +615,20 @@ BOOST_AUTO_TEST_CASE(uniformCrossover_should_swap_genes_with_uniform_probability double const expectedValue = swapChance; double const variance = swapChance * (1 - swapChance); - function crossover = uniformCrossover(swapChance); + std::function crossover = uniformCrossover(swapChance); Chromosome chromosome1("aaaaaaaaaa"); Chromosome chromosome2("cccccccccc"); - vector bernoulliTrials; + std::vector bernoulliTrials; for (size_t i = 0; i < operationCount; ++i) { - string genes = toString(crossover(chromosome1, chromosome2)); + std::string genes = toString(crossover(chromosome1, chromosome2)); for (size_t j = 0; j < chromosome1.length(); ++j) bernoulliTrials.push_back(static_cast(genes[j] == 'c')); } - BOOST_TEST(abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); } BOOST_AUTO_TEST_CASE(uniformCrossover_should_swap_tail_with_uniform_probability) @@ -640,22 +639,22 @@ BOOST_AUTO_TEST_CASE(uniformCrossover_should_swap_tail_with_uniform_probability) double const expectedValue = swapChance; double const variance = swapChance * (1 - swapChance); - function crossover = uniformCrossover(swapChance); + std::function crossover = uniformCrossover(swapChance); Chromosome chromosome1("aaaaa"); Chromosome chromosome2("cccccccccc"); SimulationRNG::reset(1); - vector bernoulliTrials; + std::vector bernoulliTrials; for (size_t i = 0; i < operationCount; ++i) { - string genes = toString(crossover(chromosome1, chromosome2)); + std::string genes = toString(crossover(chromosome1, chromosome2)); BOOST_REQUIRE(genes.size() == 5 || genes.size() == 10); bernoulliTrials.push_back(static_cast(genes.size() == 10)); } - BOOST_TEST(abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/yulPhaser/PairSelections.cpp b/test/yulPhaser/PairSelections.cpp index f3d13a5b3b27..82b9a900b68c 100644 --- a/test/yulPhaser/PairSelections.cpp +++ b/test/yulPhaser/PairSelections.cpp @@ -27,8 +27,6 @@ #include #include -using namespace std; - namespace solidity::phaser::test { @@ -45,35 +43,35 @@ BOOST_AUTO_TEST_CASE(materialise_should_return_random_values_with_equal_probabil constexpr double variance = (collectionSize * collectionSize - 1) / 12.0; SimulationRNG::reset(1); - vector> pairs = RandomPairSelection(selectionSize).materialise(collectionSize); - vector samples; + std::vector> pairs = RandomPairSelection(selectionSize).materialise(collectionSize); + std::vector samples; for (auto& [first, second]: pairs) { samples.push_back(first); samples.push_back(second); } - BOOST_TEST(abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); } BOOST_AUTO_TEST_CASE(materialise_should_return_only_values_that_can_be_used_as_collection_indices) { const size_t collectionSize = 200; - vector> pairs = RandomPairSelection(0.5).materialise(collectionSize); + std::vector> pairs = RandomPairSelection(0.5).materialise(collectionSize); BOOST_TEST(pairs.size() == 100); - BOOST_TEST(all_of(pairs.begin(), pairs.end(), [&](auto const& pair){ return get<0>(pair) <= collectionSize; })); - BOOST_TEST(all_of(pairs.begin(), pairs.end(), [&](auto const& pair){ return get<1>(pair) <= collectionSize; })); + BOOST_TEST(all_of(pairs.begin(), pairs.end(), [&](auto const& pair){ return std::get<0>(pair) <= collectionSize; })); + BOOST_TEST(all_of(pairs.begin(), pairs.end(), [&](auto const& pair){ return std::get<1>(pair) <= collectionSize; })); } BOOST_AUTO_TEST_CASE(materialise_should_never_return_a_pair_of_identical_indices) { - vector> pairs = RandomPairSelection(0.5).materialise(100); + std::vector> pairs = RandomPairSelection(0.5).materialise(100); BOOST_TEST(pairs.size() == 50); - BOOST_TEST(all_of(pairs.begin(), pairs.end(), [](auto const& pair){ return get<0>(pair) != get<1>(pair); })); + BOOST_TEST(all_of(pairs.begin(), pairs.end(), [](auto const& pair){ return std::get<0>(pair) != std::get<1>(pair); })); } BOOST_AUTO_TEST_CASE(materialise_should_return_number_of_pairs_thats_a_fraction_of_collection_size) @@ -132,18 +130,18 @@ BOOST_AUTO_TEST_CASE(materialise_should_return_random_values_with_equal_probabil constexpr double variance = selectionChance * (1 - selectionChance); SimulationRNG::reset(1); - vector> pairs = PairsFromRandomSubset(selectionChance).materialise(collectionSize); - vector bernoulliTrials(collectionSize, 0); + std::vector> pairs = PairsFromRandomSubset(selectionChance).materialise(collectionSize); + std::vector bernoulliTrials(collectionSize, 0); for (auto& pair: pairs) { - BOOST_REQUIRE(get<1>(pair) < collectionSize); - BOOST_REQUIRE(get<1>(pair) < collectionSize); - bernoulliTrials[get<0>(pair)] = 1.0; - bernoulliTrials[get<1>(pair)] = 1.0; + BOOST_REQUIRE(std::get<1>(pair) < collectionSize); + BOOST_REQUIRE(std::get<1>(pair) < collectionSize); + bernoulliTrials[std::get<0>(pair)] = 1.0; + bernoulliTrials[std::get<1>(pair)] = 1.0; } - BOOST_TEST(abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); } BOOST_AUTO_TEST_CASE(materialise_should_return_only_values_that_can_be_used_as_collection_indices) @@ -151,10 +149,10 @@ BOOST_AUTO_TEST_CASE(materialise_should_return_only_values_that_can_be_used_as_c const size_t collectionSize = 200; constexpr double selectionChance = 0.5; - vector> pairs = PairsFromRandomSubset(selectionChance).materialise(collectionSize); + std::vector> pairs = PairsFromRandomSubset(selectionChance).materialise(collectionSize); - BOOST_TEST(all_of(pairs.begin(), pairs.end(), [&](auto const& pair){ return get<0>(pair) <= collectionSize; })); - BOOST_TEST(all_of(pairs.begin(), pairs.end(), [&](auto const& pair){ return get<1>(pair) <= collectionSize; })); + BOOST_TEST(all_of(pairs.begin(), pairs.end(), [&](auto const& pair){ return std::get<0>(pair) <= collectionSize; })); + BOOST_TEST(all_of(pairs.begin(), pairs.end(), [&](auto const& pair){ return std::get<1>(pair) <= collectionSize; })); } BOOST_AUTO_TEST_CASE(materialise_should_use_unique_indices) @@ -162,12 +160,12 @@ BOOST_AUTO_TEST_CASE(materialise_should_use_unique_indices) constexpr size_t collectionSize = 200; constexpr double selectionChance = 0.5; - vector> pairs = PairsFromRandomSubset(selectionChance).materialise(collectionSize); - set indices; + std::vector> pairs = PairsFromRandomSubset(selectionChance).materialise(collectionSize); + std::set indices; for (auto& pair: pairs) { - indices.insert(get<0>(pair)); - indices.insert(get<1>(pair)); + indices.insert(std::get<0>(pair)); + indices.insert(std::get<1>(pair)); } BOOST_TEST(indices.size() == 2 * pairs.size()); @@ -195,7 +193,7 @@ BOOST_AUTO_TEST_CASE(materialise_should_return_all_pairs_if_selection_chance_is_ BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE(PairMosaicSelectionTest) -using IndexPairs = vector>; +using IndexPairs = std::vector>; BOOST_AUTO_TEST_CASE(materialise) { diff --git a/test/yulPhaser/Phaser.cpp b/test/yulPhaser/Phaser.cpp index feee2269e761..671f75546305 100644 --- a/test/yulPhaser/Phaser.cpp +++ b/test/yulPhaser/Phaser.cpp @@ -32,7 +32,6 @@ #include #include -using namespace std; using namespace solidity::util; using namespace solidity::langutil; using namespace solidity::yul; @@ -69,15 +68,15 @@ class GeneticAlgorithmFactoryFixture class FixtureWithPrograms { protected: - vector m_sourceStreams = { + std::vector m_sourceStreams = { CharStream("{}", ""), CharStream("{{}}", ""), CharStream("{{{}}}", ""), }; - vector m_programs = { - get(Program::load(m_sourceStreams[0])), - get(Program::load(m_sourceStreams[1])), - get(Program::load(m_sourceStreams[2])), + std::vector m_programs = { + std::get(Program::load(m_sourceStreams[0])), + std::get(Program::load(m_sourceStreams[1])), + std::get(Program::load(m_sourceStreams[2])), }; }; @@ -96,7 +95,7 @@ class FitnessMetricFactoryFixture: public FixtureWithPrograms class PoulationFactoryFixture { protected: - shared_ptr m_fitnessMetric = make_shared(); + std::shared_ptr m_fitnessMetric = std::make_shared(); PopulationFactory::Options m_options = { /* minChromosomeLength = */ 0, /* maxChromosomeLength = */ 0, @@ -113,7 +112,7 @@ BOOST_AUTO_TEST_SUITE(GeneticAlgorithmFactoryTest) BOOST_FIXTURE_TEST_CASE(build_should_select_the_right_algorithm_and_pass_the_options_to_it, GeneticAlgorithmFactoryFixture) { m_options.algorithm = Algorithm::Random; - unique_ptr algorithm1 = GeneticAlgorithmFactory::build(m_options, 100); + std::unique_ptr algorithm1 = GeneticAlgorithmFactory::build(m_options, 100); BOOST_REQUIRE(algorithm1 != nullptr); auto randomAlgorithm = dynamic_cast(algorithm1.get()); @@ -123,7 +122,7 @@ BOOST_FIXTURE_TEST_CASE(build_should_select_the_right_algorithm_and_pass_the_opt BOOST_TEST(randomAlgorithm->options().maxChromosomeLength == m_options.maxChromosomeLength); m_options.algorithm = Algorithm::GEWEP; - unique_ptr algorithm2 = GeneticAlgorithmFactory::build(m_options, 100); + std::unique_ptr algorithm2 = GeneticAlgorithmFactory::build(m_options, 100); BOOST_REQUIRE(algorithm2 != nullptr); auto gewepAlgorithm = dynamic_cast(algorithm2.get()); @@ -139,7 +138,7 @@ BOOST_FIXTURE_TEST_CASE(build_should_select_the_right_algorithm_and_pass_the_opt BOOST_TEST(gewepAlgorithm->options().percentGenesToAddOrDelete == m_options.gewepGenesToAddOrDelete.value()); m_options.algorithm = Algorithm::Classic; - unique_ptr algorithm3 = GeneticAlgorithmFactory::build(m_options, 100); + std::unique_ptr algorithm3 = GeneticAlgorithmFactory::build(m_options, 100); BOOST_REQUIRE(algorithm3 != nullptr); auto classicAlgorithm = dynamic_cast(algorithm3.get()); @@ -156,8 +155,8 @@ BOOST_FIXTURE_TEST_CASE(build_should_select_the_right_algorithm_and_pass_the_opt BOOST_FIXTURE_TEST_CASE(build_should_set_random_algorithm_elite_pool_size_based_on_population_size_if_not_specified, GeneticAlgorithmFactoryFixture) { m_options.algorithm = Algorithm::Random; - m_options.randomElitePoolSize = nullopt; - unique_ptr algorithm = GeneticAlgorithmFactory::build(m_options, 100); + m_options.randomElitePoolSize = std::nullopt; + std::unique_ptr algorithm = GeneticAlgorithmFactory::build(m_options, 100); BOOST_REQUIRE(algorithm != nullptr); auto randomAlgorithm = dynamic_cast(algorithm.get()); @@ -168,11 +167,11 @@ BOOST_FIXTURE_TEST_CASE(build_should_set_random_algorithm_elite_pool_size_based_ BOOST_FIXTURE_TEST_CASE(build_should_set_gewep_mutation_percentages_based_on_maximum_chromosome_length_if_not_specified, GeneticAlgorithmFactoryFixture) { m_options.algorithm = Algorithm::GEWEP; - m_options.gewepGenesToRandomise = nullopt; - m_options.gewepGenesToAddOrDelete = nullopt; + m_options.gewepGenesToRandomise = std::nullopt; + m_options.gewepGenesToAddOrDelete = std::nullopt; m_options.maxChromosomeLength = 125; - unique_ptr algorithm = GeneticAlgorithmFactory::build(m_options, 100); + std::unique_ptr algorithm = GeneticAlgorithmFactory::build(m_options, 100); BOOST_REQUIRE(algorithm != nullptr); auto gewepAlgorithm = dynamic_cast(algorithm.get()); @@ -188,7 +187,7 @@ BOOST_FIXTURE_TEST_CASE(build_should_create_metric_of_the_right_type, FitnessMet { m_options.metric = MetricChoice::RelativeCodeSize; m_options.metricAggregator = MetricAggregatorChoice::Sum; - unique_ptr metric = FitnessMetricFactory::build(m_options, {m_programs[0]}, {nullptr}, m_weights); + std::unique_ptr metric = FitnessMetricFactory::build(m_options, {m_programs[0]}, {nullptr}, m_weights); BOOST_REQUIRE(metric != nullptr); auto sumMetric = dynamic_cast(metric.get()); @@ -206,7 +205,7 @@ BOOST_FIXTURE_TEST_CASE(build_should_respect_chromosome_repetitions_option, Fitn m_options.metric = MetricChoice::CodeSize; m_options.metricAggregator = MetricAggregatorChoice::Average; m_options.chromosomeRepetitions = 5; - unique_ptr metric = FitnessMetricFactory::build(m_options, {m_programs[0]}, {nullptr}, m_weights); + std::unique_ptr metric = FitnessMetricFactory::build(m_options, {m_programs[0]}, {nullptr}, m_weights); BOOST_REQUIRE(metric != nullptr); auto averageMetric = dynamic_cast(metric.get()); @@ -224,7 +223,7 @@ BOOST_FIXTURE_TEST_CASE(build_should_set_relative_metric_scale, FitnessMetricFac m_options.metric = MetricChoice::RelativeCodeSize; m_options.metricAggregator = MetricAggregatorChoice::Average; m_options.relativeMetricScale = 10; - unique_ptr metric = FitnessMetricFactory::build(m_options, {m_programs[0]}, {nullptr}, m_weights); + std::unique_ptr metric = FitnessMetricFactory::build(m_options, {m_programs[0]}, {nullptr}, m_weights); BOOST_REQUIRE(metric != nullptr); auto averageMetric = dynamic_cast(metric.get()); @@ -239,10 +238,10 @@ BOOST_FIXTURE_TEST_CASE(build_should_set_relative_metric_scale, FitnessMetricFac BOOST_FIXTURE_TEST_CASE(build_should_create_metric_for_each_input_program, FitnessMetricFactoryFixture) { - unique_ptr metric = FitnessMetricFactory::build( + std::unique_ptr metric = FitnessMetricFactory::build( m_options, m_programs, - vector>(m_programs.size(), nullptr), + std::vector>(m_programs.size(), nullptr), m_weights ); BOOST_REQUIRE(metric != nullptr); @@ -255,14 +254,14 @@ BOOST_FIXTURE_TEST_CASE(build_should_create_metric_for_each_input_program, Fitne BOOST_FIXTURE_TEST_CASE(build_should_pass_program_caches_to_metrics, FitnessMetricFactoryFixture) { assert(m_programs.size() == 3); - vector> caches = { - make_shared(m_programs[0]), - make_shared(m_programs[1]), - make_shared(m_programs[2]), + std::vector> caches = { + std::make_shared(m_programs[0]), + std::make_shared(m_programs[1]), + std::make_shared(m_programs[2]), }; m_options.metric = MetricChoice::RelativeCodeSize; - unique_ptr metric = FitnessMetricFactory::build(m_options, m_programs, caches, m_weights); + std::unique_ptr metric = FitnessMetricFactory::build(m_options, m_programs, caches, m_weights); BOOST_REQUIRE(metric != nullptr); auto combinedMetric = dynamic_cast(metric.get()); @@ -287,7 +286,7 @@ BOOST_FIXTURE_TEST_CASE(build_should_create_an_empty_population_if_no_specific_o m_options.populationFromFile = {}; BOOST_TEST( PopulationFactory::build(m_options, m_fitnessMetric) == - Population(m_fitnessMetric, vector{}) + Population(m_fitnessMetric, std::vector{}) ); } @@ -318,7 +317,7 @@ BOOST_FIXTURE_TEST_CASE(build_should_respect_random_population_option, Poulation BOOST_FIXTURE_TEST_CASE(build_should_respect_population_from_file_option, PoulationFactoryFixture) { - map> fileContent = { + std::map> fileContent = { {"a.txt", {"a", "fff", "", "jxccLTa"}}, {"b.txt", {}}, {"c.txt", {""}}, @@ -328,9 +327,9 @@ BOOST_FIXTURE_TEST_CASE(build_should_respect_population_from_file_option, Poulat TemporaryDirectory tempDir; for (auto const& [fileName, chromosomes]: fileContent) { - ofstream tmpFile((tempDir.path() / fileName).string()); + std::ofstream tmpFile((tempDir.path() / fileName).string()); for (auto const& chromosome: chromosomes) - tmpFile << chromosome << endl; + tmpFile << chromosome << std::endl; m_options.populationFromFile.push_back((tempDir.path() / fileName).string()); } @@ -361,8 +360,8 @@ BOOST_FIXTURE_TEST_CASE(build_should_combine_populations_from_all_sources, Poula { TemporaryDirectory tempDir; { - ofstream tmpFile((tempDir.path() / "population.txt").string()); - tmpFile << "axc" << endl << "fcL" << endl; + std::ofstream tmpFile((tempDir.path() / "population.txt").string()); + tmpFile << "axc" << std::endl << "fcL" << std::endl; } m_options.population = {"axc", "fcL"}; @@ -388,7 +387,7 @@ BOOST_AUTO_TEST_SUITE(ProgramCacheFactoryTest) BOOST_FIXTURE_TEST_CASE(build_should_create_cache_for_each_input_program_if_cache_enabled, FixtureWithPrograms) { ProgramCacheFactory::Options options{/* programCacheEnabled = */ true}; - vector> caches = ProgramCacheFactory::build(options, m_programs); + std::vector> caches = ProgramCacheFactory::build(options, m_programs); assert(m_programs.size() >= 2 && "There must be at least 2 programs for this test to be meaningful"); BOOST_TEST(caches.size() == m_programs.size()); @@ -402,7 +401,7 @@ BOOST_FIXTURE_TEST_CASE(build_should_create_cache_for_each_input_program_if_cach BOOST_FIXTURE_TEST_CASE(build_should_return_nullptr_for_each_input_program_if_cache_disabled, FixtureWithPrograms) { ProgramCacheFactory::Options options{/* programCacheEnabled = */ false}; - vector> caches = ProgramCacheFactory::build(options, m_programs); + std::vector> caches = ProgramCacheFactory::build(options, m_programs); assert(m_programs.size() >= 2 && "There must be at least 2 programs for this test to be meaningful"); BOOST_TEST(caches.size() == m_programs.size()); @@ -416,7 +415,7 @@ BOOST_AUTO_TEST_SUITE(ProgramFactoryTest) BOOST_AUTO_TEST_CASE(build_should_load_programs_from_files) { TemporaryDirectory tempDir; - vector sources{"{}", "{{}}", "{{{}}}"}; + std::vector sources{"{}", "{{}}", "{{{}}}"}; ProgramFactory::Options options{ /* inputFiles = */ { (tempDir.path() / "program1.yul").string(), @@ -428,17 +427,17 @@ BOOST_AUTO_TEST_CASE(build_should_load_programs_from_files) for (size_t i = 0; i < sources.size(); ++i) { - ofstream tmpFile(options.inputFiles[i]); - tmpFile << sources[i] << endl; + std::ofstream tmpFile(options.inputFiles[i]); + tmpFile << sources[i] << std::endl; } - vector programs = ProgramFactory::build(options); + std::vector programs = ProgramFactory::build(options); BOOST_TEST(programs.size() == sources.size()); for (size_t i = 0; i < sources.size(); ++i) { CharStream sourceStream(sources[i], options.inputFiles[i]); - BOOST_TEST(toString(programs[i]) == toString(get(Program::load(sourceStream)))); + BOOST_TEST(toString(programs[i]) == toString(std::get(Program::load(sourceStream)))); } } @@ -451,17 +450,17 @@ BOOST_AUTO_TEST_CASE(build_should_apply_prefix) }; CharStream nestedSource("{{{let x:= 1}}}", ""); - Program nestedProgram = get(Program::load(nestedSource)); - Program flatProgram = get(Program::load(nestedSource)); + Program nestedProgram = std::get(Program::load(nestedSource)); + Program flatProgram = std::get(Program::load(nestedSource)); flatProgram.optimise(Chromosome::genesToSteps("f")); assert(toString(nestedProgram) != toString(flatProgram)); { - ofstream tmpFile(options.inputFiles[0]); - tmpFile << nestedSource.source() << endl; + std::ofstream tmpFile(options.inputFiles[0]); + tmpFile << nestedSource.source() << std::endl; } - vector programs = ProgramFactory::build(options); + std::vector programs = ProgramFactory::build(options); BOOST_TEST(programs.size() == 1); BOOST_TEST(toString(programs[0]) == toString(flatProgram)); diff --git a/test/yulPhaser/Population.cpp b/test/yulPhaser/Population.cpp index 13d06b521030..aed014592c1b 100644 --- a/test/yulPhaser/Population.cpp +++ b/test/yulPhaser/Population.cpp @@ -38,7 +38,6 @@ #include #include -using namespace std; using namespace solidity::langutil; using namespace solidity::yul; using namespace boost::unit_test::framework; @@ -52,12 +51,12 @@ class PopulationFixture static ChromosomePair twoStepSwap(Chromosome const& _chromosome1, Chromosome const& _chromosome2) { return ChromosomePair{ - Chromosome(vector{_chromosome1.optimisationSteps()[0], _chromosome2.optimisationSteps()[1]}), - Chromosome(vector{_chromosome2.optimisationSteps()[0], _chromosome1.optimisationSteps()[1]}), + Chromosome(std::vector{_chromosome1.optimisationSteps()[0], _chromosome2.optimisationSteps()[1]}), + Chromosome(std::vector{_chromosome2.optimisationSteps()[0], _chromosome1.optimisationSteps()[1]}), }; } - shared_ptr m_fitnessMetric = make_shared(); + std::shared_ptr m_fitnessMetric = std::make_shared(); }; BOOST_AUTO_TEST_SUITE(Phaser, *boost::unit_test::label("nooptions")) @@ -95,14 +94,14 @@ BOOST_AUTO_TEST_CASE(isFitter_should_return_false_for_identical_individuals) BOOST_FIXTURE_TEST_CASE(constructor_should_copy_chromosomes_compute_fitness_and_sort_chromosomes, PopulationFixture) { - vector chromosomes = { + std::vector chromosomes = { Chromosome::makeRandom(5), Chromosome::makeRandom(15), Chromosome::makeRandom(10), }; Population population(m_fitnessMetric, chromosomes); - vector const& individuals = population.individuals(); + std::vector const& individuals = population.individuals(); BOOST_TEST(individuals.size() == 3); BOOST_TEST(individuals[0].fitness == 5); @@ -115,7 +114,7 @@ BOOST_FIXTURE_TEST_CASE(constructor_should_copy_chromosomes_compute_fitness_and_ BOOST_FIXTURE_TEST_CASE(constructor_should_accept_individuals_without_recalculating_fitness, PopulationFixture) { - vector customIndividuals = { + std::vector customIndividuals = { Individual(Chromosome("aaaccc"), 20), Individual(Chromosome("aaa"), 10), Individual(Chromosome("aaaf"), 30), @@ -126,7 +125,7 @@ BOOST_FIXTURE_TEST_CASE(constructor_should_accept_individuals_without_recalculat Population population(m_fitnessMetric, customIndividuals); - vector expectedIndividuals{customIndividuals[1], customIndividuals[0], customIndividuals[2]}; + std::vector expectedIndividuals{customIndividuals[1], customIndividuals[0], customIndividuals[2]}; BOOST_TEST(population.individuals() == expectedIndividuals); } @@ -170,13 +169,13 @@ BOOST_FIXTURE_TEST_CASE(makeRandom_should_use_random_chromosome_length, Populati constexpr double relativeTolerance = 0.05; auto population = Population::makeRandom(m_fitnessMetric, populationSize, minLength, maxLength); - vector samples = chromosomeLengths(population); + std::vector samples = chromosomeLengths(population); const double expectedValue = (maxLength + minLength) / 2.0; const double variance = ((maxLength - minLength + 1) * (maxLength - minLength + 1) - 1) / 12.0; - BOOST_TEST(abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); } BOOST_FIXTURE_TEST_CASE(makeRandom_should_return_population_with_random_chromosomes, PopulationFixture) @@ -186,10 +185,10 @@ BOOST_FIXTURE_TEST_CASE(makeRandom_should_return_population_with_random_chromoso constexpr int chromosomeLength = 30; constexpr double relativeTolerance = 0.01; - map stepIndices = enumerateOptmisationSteps(); + std::map stepIndices = enumerateOptmisationSteps(); auto population = Population::makeRandom(m_fitnessMetric, populationSize, chromosomeLength, chromosomeLength); - vector samples; + std::vector samples; for (auto& individual: population.individuals()) for (auto& step: individual.chromosome.optimisationSteps()) samples.push_back(stepIndices.at(step)); @@ -197,8 +196,8 @@ BOOST_FIXTURE_TEST_CASE(makeRandom_should_return_population_with_random_chromoso const double expectedValue = double(stepIndices.size() - 1) / 2.0; const double variance = double(stepIndices.size() * stepIndices.size() - 1) / 12.0; - BOOST_TEST(abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); } BOOST_FIXTURE_TEST_CASE(makeRandom_should_compute_fitness, PopulationFixture) @@ -223,7 +222,7 @@ BOOST_FIXTURE_TEST_CASE(select_should_return_population_containing_individuals_i { Population population(m_fitnessMetric, {Chromosome("a"), Chromosome("c"), Chromosome("g"), Chromosome("h")}); RangeSelection selection(0.25, 0.75); - assert(selection.materialise(population.individuals().size()) == (vector{1, 2})); + assert(selection.materialise(population.individuals().size()) == (std::vector{1, 2})); BOOST_TEST( population.select(selection) == @@ -235,7 +234,7 @@ BOOST_FIXTURE_TEST_CASE(select_should_include_duplicates_if_selection_contains_d { Population population(m_fitnessMetric, {Chromosome("a"), Chromosome("c")}); MosaicSelection selection({0, 1}, 2.0); - assert(selection.materialise(population.individuals().size()) == (vector{0, 1, 0, 1})); + assert(selection.materialise(population.individuals().size()) == (std::vector{0, 1, 0, 1})); BOOST_TEST(population.select(selection) == Population(m_fitnessMetric, { population.individuals()[0].chromosome, @@ -258,7 +257,7 @@ BOOST_FIXTURE_TEST_CASE(mutate_should_return_population_containing_individuals_i { Population population(m_fitnessMetric, {Chromosome("aa"), Chromosome("cc"), Chromosome("gg"), Chromosome("hh")}); RangeSelection selection(0.25, 0.75); - assert(selection.materialise(population.individuals().size()) == (vector{1, 2})); + assert(selection.materialise(population.individuals().size()) == (std::vector{1, 2})); Population expectedPopulation(m_fitnessMetric, {Chromosome("fc"), Chromosome("fg")}); @@ -269,7 +268,7 @@ BOOST_FIXTURE_TEST_CASE(mutate_should_include_duplicates_if_selection_contains_d { Population population(m_fitnessMetric, {Chromosome("aa"), Chromosome("aa")}); RangeSelection selection(0.0, 1.0); - assert(selection.materialise(population.individuals().size()) == (vector{0, 1})); + assert(selection.materialise(population.individuals().size()) == (std::vector{0, 1})); BOOST_TEST( population.mutate(selection, geneSubstitution(0, BlockFlattener::name)) == @@ -290,7 +289,7 @@ BOOST_FIXTURE_TEST_CASE(crossover_should_return_population_containing_individual { Population population(m_fitnessMetric, {Chromosome("aa"), Chromosome("cc"), Chromosome("gg"), Chromosome("hh")}); PairMosaicSelection selection({{0, 1}, {2, 1}}, 1.0); - assert(selection.materialise(population.individuals().size()) == (vector>{{0, 1}, {2, 1}, {0, 1}, {2, 1}})); + assert(selection.materialise(population.individuals().size()) == (std::vector>{{0, 1}, {2, 1}, {0, 1}, {2, 1}})); Population expectedPopulation(m_fitnessMetric, {Chromosome("ac"), Chromosome("ac"), Chromosome("gc"), Chromosome("gc")}); @@ -301,7 +300,7 @@ BOOST_FIXTURE_TEST_CASE(crossover_should_include_duplicates_if_selection_contain { Population population(m_fitnessMetric, {Chromosome("aa"), Chromosome("aa")}); PairMosaicSelection selection({{0, 0}, {1, 1}}, 2.0); - assert(selection.materialise(population.individuals().size()) == (vector>{{0, 0}, {1, 1}, {0, 0}, {1, 1}})); + assert(selection.materialise(population.individuals().size()) == (std::vector>{{0, 0}, {1, 1}, {0, 0}, {1, 1}})); BOOST_TEST( population.crossover(selection, fixedPointCrossover(0.5)) == @@ -322,14 +321,14 @@ BOOST_FIXTURE_TEST_CASE(symmetricCrossoverWithRemainder_should_return_crossed_po { Population population(m_fitnessMetric, {Chromosome("aa"), Chromosome("cc"), Chromosome("gg"), Chromosome("hh")}); PairMosaicSelection selection({{2, 1}}, 0.25); - assert(selection.materialise(population.individuals().size()) == (vector>{{2, 1}})); + assert(selection.materialise(population.individuals().size()) == (std::vector>{{2, 1}})); Population expectedCrossedPopulation(m_fitnessMetric, {Chromosome("gc"), Chromosome("cg")}); Population expectedRemainder(m_fitnessMetric, {Chromosome("aa"), Chromosome("hh")}); BOOST_TEST( population.symmetricCrossoverWithRemainder(selection, twoStepSwap) == - (tuple{expectedCrossedPopulation, expectedRemainder}) + (std::tuple{expectedCrossedPopulation, expectedRemainder}) ); } @@ -337,7 +336,7 @@ BOOST_FIXTURE_TEST_CASE(symmetricCrossoverWithRemainder_should_allow_crossing_th { Population population(m_fitnessMetric, {Chromosome("aa"), Chromosome("cc"), Chromosome("gg"), Chromosome("hh")}); PairMosaicSelection selection({{0, 0}, {2, 1}}, 1.0); - assert(selection.materialise(population.individuals().size()) == (vector>{{0, 0}, {2, 1}, {0, 0}, {2, 1}})); + assert(selection.materialise(population.individuals().size()) == (std::vector>{{0, 0}, {2, 1}, {0, 0}, {2, 1}})); Population expectedCrossedPopulation(m_fitnessMetric, { Chromosome("aa"), Chromosome("aa"), @@ -349,7 +348,7 @@ BOOST_FIXTURE_TEST_CASE(symmetricCrossoverWithRemainder_should_allow_crossing_th BOOST_TEST( population.symmetricCrossoverWithRemainder(selection, twoStepSwap) == - (tuple{expectedCrossedPopulation, expectedRemainder}) + (std::tuple{expectedCrossedPopulation, expectedRemainder}) ); } @@ -361,7 +360,7 @@ BOOST_FIXTURE_TEST_CASE(symmetricCrossoverWithRemainder_should_return_empty_popu BOOST_TEST( population.symmetricCrossoverWithRemainder(selection, twoStepSwap) == - (tuple{Population(m_fitnessMetric), population}) + (std::tuple{Population(m_fitnessMetric), population}) ); } diff --git a/test/yulPhaser/Program.cpp b/test/yulPhaser/Program.cpp index 2e91926d059f..a54bf09af146 100644 --- a/test/yulPhaser/Program.cpp +++ b/test/yulPhaser/Program.cpp @@ -34,7 +34,6 @@ #include #include -using namespace std; using namespace solidity::langutil; using namespace solidity::util; using namespace solidity::yul; @@ -47,7 +46,7 @@ namespace /// If the block isn't redundant it just returns it immediately. Block const& skipRedundantBlocks(Block const& _block) { - if (_block.statements.size() == 1 && holds_alternative(_block.statements[0])) + if (_block.statements.size() == 1 && std::holds_alternative(_block.statements[0])) return skipRedundantBlocks(get(_block.statements[0])); else return _block; @@ -62,7 +61,7 @@ BOOST_AUTO_TEST_SUITE(ProgramTest) BOOST_AUTO_TEST_CASE(copy_constructor_should_make_deep_copy_of_ast) { - string sourceCode( + std::string sourceCode( "{\n" " let x := 1\n" "}\n" @@ -82,7 +81,7 @@ BOOST_AUTO_TEST_CASE(copy_constructor_should_make_deep_copy_of_ast) BOOST_AUTO_TEST_CASE(load_should_rewind_the_stream) { - string sourceCode( + std::string sourceCode( "{\n" " let x := 1\n" " let y := 2\n" @@ -98,7 +97,7 @@ BOOST_AUTO_TEST_CASE(load_should_rewind_the_stream) BOOST_AUTO_TEST_CASE(load_should_disambiguate) { - string sourceCode( + std::string sourceCode( "{\n" " {\n" " let x := 1\n" @@ -126,7 +125,7 @@ BOOST_AUTO_TEST_CASE(load_should_disambiguate) BOOST_AUTO_TEST_CASE(load_should_do_function_grouping_and_hoisting) { - string sourceCode( + std::string sourceCode( "{\n" " function foo() -> result\n" " {\n" @@ -144,14 +143,14 @@ BOOST_AUTO_TEST_CASE(load_should_do_function_grouping_and_hoisting) Program program = get(Program::load(sourceStream)); BOOST_TEST(program.ast().statements.size() == 3); - BOOST_TEST(holds_alternative(program.ast().statements[0])); - BOOST_TEST(holds_alternative(program.ast().statements[1])); - BOOST_TEST(holds_alternative(program.ast().statements[2])); + BOOST_TEST(std::holds_alternative(program.ast().statements[0])); + BOOST_TEST(std::holds_alternative(program.ast().statements[1])); + BOOST_TEST(std::holds_alternative(program.ast().statements[2])); } BOOST_AUTO_TEST_CASE(load_should_do_loop_init_rewriting) { - string sourceCode( + std::string sourceCode( "{\n" " for { let i := 0 } true {}\n" " {\n" @@ -163,35 +162,35 @@ BOOST_AUTO_TEST_CASE(load_should_do_loop_init_rewriting) // skipRedundantBlocks() makes the test independent of whether load() includes function grouping or not. Block const& parentBlock = skipRedundantBlocks(program.ast()); - BOOST_TEST(holds_alternative(parentBlock.statements[0])); - BOOST_TEST(holds_alternative(parentBlock.statements[1])); + BOOST_TEST(std::holds_alternative(parentBlock.statements[0])); + BOOST_TEST(std::holds_alternative(parentBlock.statements[1])); } BOOST_AUTO_TEST_CASE(load_should_throw_InvalidProgram_if_program_cant_be_parsed) { - string sourceCode("invalid program\n"); + std::string sourceCode("invalid program\n"); CharStream sourceStream(sourceCode, current_test_case().p_name); - BOOST_TEST(holds_alternative(Program::load(sourceStream))); + BOOST_TEST(std::holds_alternative(Program::load(sourceStream))); } BOOST_AUTO_TEST_CASE(load_should_throw_InvalidProgram_if_program_cant_be_analyzed) { // This should be parsed just fine but fail the analysis with: // Error: Variable not found or variable not lvalue. - string sourceCode( + std::string sourceCode( "{\n" " x := 1\n" "}\n" ); CharStream sourceStream(sourceCode, current_test_case().p_name); - BOOST_TEST(holds_alternative(Program::load(sourceStream))); + BOOST_TEST(std::holds_alternative(Program::load(sourceStream))); } BOOST_AUTO_TEST_CASE(load_should_accept_yul_objects_as_input) { - string sourceCode( + std::string sourceCode( "object \"C_178\" {\n" " code {\n" " mstore(64, 128)\n" @@ -203,12 +202,12 @@ BOOST_AUTO_TEST_CASE(load_should_accept_yul_objects_as_input) CharStream sourceStream(sourceCode, current_test_case().p_name); auto programOrErrors = Program::load(sourceStream); - BOOST_TEST(holds_alternative(programOrErrors)); + BOOST_TEST(std::holds_alternative(programOrErrors)); } BOOST_AUTO_TEST_CASE(load_should_return_errors_if_analysis_of_object_code_fails) { - string sourceCode( + std::string sourceCode( "object \"C_178\" {\n" " code {\n" " return(0, datasize(\"C_178_deployed\"))\n" @@ -218,12 +217,12 @@ BOOST_AUTO_TEST_CASE(load_should_return_errors_if_analysis_of_object_code_fails) CharStream sourceStream(sourceCode, current_test_case().p_name); auto programOrErrors = Program::load(sourceStream); - BOOST_TEST(holds_alternative(programOrErrors)); + BOOST_TEST(std::holds_alternative(programOrErrors)); } BOOST_AUTO_TEST_CASE(load_should_return_errors_if_parsing_of_nested_object_fails) { - string sourceCode( + std::string sourceCode( "object \"C_178\" {\n" " code {\n" " return(0, datasize(\"C_178_deployed\"))\n" @@ -243,12 +242,12 @@ BOOST_AUTO_TEST_CASE(load_should_return_errors_if_parsing_of_nested_object_fails CharStream sourceStream(sourceCode, current_test_case().p_name); auto programOrErrors = Program::load(sourceStream); - BOOST_TEST(holds_alternative(programOrErrors)); + BOOST_TEST(std::holds_alternative(programOrErrors)); } BOOST_AUTO_TEST_CASE(load_should_extract_nested_object_with_deployed_suffix_if_present) { - string sourceCode( + std::string sourceCode( "object \"C_178\" {\n" " code {\n" " return(0, datasize(\"C_178_deployed\"))\n" @@ -265,12 +264,12 @@ BOOST_AUTO_TEST_CASE(load_should_extract_nested_object_with_deployed_suffix_if_p CharStream sourceStream(sourceCode, current_test_case().p_name); auto programOrErrors = Program::load(sourceStream); - BOOST_TEST(holds_alternative(programOrErrors)); + BOOST_TEST(std::holds_alternative(programOrErrors)); } BOOST_AUTO_TEST_CASE(load_should_fall_back_to_parsing_the_whole_object_if_there_is_no_subobject_with_the_right_name) { - string sourceCode( + std::string sourceCode( "object \"C_178\" {\n" " code {\n" " mstore(64, 128)\n" @@ -292,16 +291,16 @@ BOOST_AUTO_TEST_CASE(load_should_fall_back_to_parsing_the_whole_object_if_there_ CharStream sourceStream(sourceCode, current_test_case().p_name); auto programOrErrors = Program::load(sourceStream); - BOOST_TEST(holds_alternative(programOrErrors)); + BOOST_TEST(std::holds_alternative(programOrErrors)); Block const& parentBlock = skipRedundantBlocks(get(programOrErrors).ast()); BOOST_TEST(parentBlock.statements.size() == 1); - BOOST_TEST(holds_alternative(parentBlock.statements[0])); + BOOST_TEST(std::holds_alternative(parentBlock.statements[0])); } BOOST_AUTO_TEST_CASE(load_should_ignore_data_in_objects) { - string sourceCode( + std::string sourceCode( "object \"C_178\" {\n" " code {\n" " mstore(64, 128)\n" @@ -312,12 +311,12 @@ BOOST_AUTO_TEST_CASE(load_should_ignore_data_in_objects) CharStream sourceStream(sourceCode, current_test_case().p_name); auto programOrErrors = Program::load(sourceStream); - BOOST_TEST(holds_alternative(programOrErrors)); + BOOST_TEST(std::holds_alternative(programOrErrors)); } BOOST_AUTO_TEST_CASE(optimise) { - string sourceCode( + std::string sourceCode( "{\n" " {\n" " if 1 { let x := 1 }\n" @@ -330,22 +329,22 @@ BOOST_AUTO_TEST_CASE(optimise) [[maybe_unused]] Block const& parentBlockBefore = skipRedundantBlocks(program.ast()); assert(parentBlockBefore.statements.size() == 2); - assert(holds_alternative(parentBlockBefore.statements[0])); - assert(holds_alternative(parentBlockBefore.statements[1])); + assert(std::holds_alternative(parentBlockBefore.statements[0])); + assert(std::holds_alternative(parentBlockBefore.statements[1])); program.optimise({StructuralSimplifier::name, BlockFlattener::name}); Block const& parentBlockAfter = program.ast(); BOOST_TEST(parentBlockAfter.statements.size() == 1); - BOOST_TEST(holds_alternative(parentBlockAfter.statements[0])); + BOOST_TEST(std::holds_alternative(parentBlockAfter.statements[0])); Block const& innerBlock = get(parentBlockAfter.statements[0]); BOOST_TEST(innerBlock.statements.size() == 1); - BOOST_TEST(holds_alternative(innerBlock.statements[0])); + BOOST_TEST(std::holds_alternative(innerBlock.statements[0])); } BOOST_AUTO_TEST_CASE(output_operator) { - string sourceCode( + std::string sourceCode( "{\n" " let factor := 13\n" " {\n" @@ -369,7 +368,7 @@ BOOST_AUTO_TEST_CASE(output_operator) BOOST_AUTO_TEST_CASE(toJson) { - string sourceCode( + std::string sourceCode( "{\n" " let a := 3\n" " if a\n" @@ -382,14 +381,14 @@ BOOST_AUTO_TEST_CASE(toJson) Program program = get(Program::load(sourceStream)); Json::Value parsingResult; - string errors; + std::string errors; BOOST_TEST(jsonParseStrict(program.toJson(), parsingResult, &errors)); BOOST_TEST(errors.empty()); } BOOST_AUTO_TEST_CASE(codeSize) { - string sourceCode( + std::string sourceCode( "{\n" " function foo() -> result\n" " {\n" diff --git a/test/yulPhaser/ProgramCache.cpp b/test/yulPhaser/ProgramCache.cpp index 2dab86fcda17..c4bf7f609e61 100644 --- a/test/yulPhaser/ProgramCache.cpp +++ b/test/yulPhaser/ProgramCache.cpp @@ -30,7 +30,6 @@ #include #include -using namespace std; using namespace solidity::util; using namespace solidity::langutil; using namespace solidity::yul; @@ -50,16 +49,16 @@ class ProgramCacheFixture " }\n" "}\n"; - Program optimisedProgram(Program _program, string _abbreviatedOptimisationSteps) const + Program optimisedProgram(Program _program, std::string _abbreviatedOptimisationSteps) const { Program result = std::move(_program); result.optimise(Chromosome::genesToSteps(_abbreviatedOptimisationSteps)); return result; } - static set cachedKeys(ProgramCache const& _programCache) + static std::set cachedKeys(ProgramCache const& _programCache) { - set keys; + std::set keys; for (auto pair = _programCache.entries().begin(); pair != _programCache.entries().end(); ++pair) keys.insert(pair->first); @@ -67,7 +66,7 @@ class ProgramCacheFixture } CharStream m_sourceStream = CharStream(SampleSourceCode, "program-cache-test"); - Program m_program = get(Program::load(m_sourceStream)); + Program m_program = std::get(Program::load(m_sourceStream)); ProgramCache m_programCache{m_program}; }; @@ -111,7 +110,7 @@ BOOST_FIXTURE_TEST_CASE(optimiseProgram_should_store_programs_for_all_prefixes, BOOST_TEST(toString(cachedProgram) == toString(programIuO)); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"I", "Iu", "IuO"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"I", "Iu", "IuO"})); BOOST_TEST(toString(*m_programCache.find("I")) == toString(programI)); BOOST_TEST(toString(*m_programCache.find("Iu")) == toString(programIu)); BOOST_TEST(toString(*m_programCache.find("IuO")) == toString(programIuO)); @@ -119,7 +118,7 @@ BOOST_FIXTURE_TEST_CASE(optimiseProgram_should_store_programs_for_all_prefixes, BOOST_FIXTURE_TEST_CASE(optimiseProgram_should_repeat_the_chromosome_requested_number_of_times, ProgramCacheFixture) { - string steps = "IuOIuO"; + std::string steps = "IuOIuO"; Program cachedProgram = m_programCache.optimiseProgram("IuO", 2); @@ -148,14 +147,14 @@ BOOST_FIXTURE_TEST_CASE(optimiseProgram_should_reuse_the_longest_prefix_and_move m_programCache.startRound(1); BOOST_TEST(m_programCache.currentRound() == 1); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"I", "Iu", "Ia"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"I", "Iu", "Ia"})); BOOST_TEST(m_programCache.entries().find("I")->second.roundNumber == 0); BOOST_TEST(m_programCache.entries().find("Iu")->second.roundNumber == 0); BOOST_TEST(m_programCache.entries().find("Ia")->second.roundNumber == 0); m_programCache.optimiseProgram("IuOI"); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"I", "Iu", "Ia", "IuO", "IuOI"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"I", "Iu", "Ia", "IuO", "IuOI"})); BOOST_TEST(m_programCache.entries().find("I")->second.roundNumber == 1); BOOST_TEST(m_programCache.entries().find("Iu")->second.roundNumber == 1); BOOST_TEST(m_programCache.entries().find("Ia")->second.roundNumber == 0); @@ -171,14 +170,14 @@ BOOST_FIXTURE_TEST_CASE(startRound_should_remove_entries_older_than_two_rounds, m_programCache.optimiseProgram("Iu"); BOOST_TEST(m_programCache.currentRound() == 0); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"I", "Iu"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"I", "Iu"})); BOOST_TEST(m_programCache.entries().find("I")->second.roundNumber == 0); BOOST_TEST(m_programCache.entries().find("Iu")->second.roundNumber == 0); m_programCache.optimiseProgram("a"); BOOST_TEST(m_programCache.currentRound() == 0); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"I", "Iu", "a"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"I", "Iu", "a"})); BOOST_TEST(m_programCache.entries().find("I")->second.roundNumber == 0); BOOST_TEST(m_programCache.entries().find("Iu")->second.roundNumber == 0); BOOST_TEST(m_programCache.entries().find("a")->second.roundNumber == 0); @@ -186,7 +185,7 @@ BOOST_FIXTURE_TEST_CASE(startRound_should_remove_entries_older_than_two_rounds, m_programCache.startRound(1); BOOST_TEST(m_programCache.currentRound() == 1); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"I", "Iu", "a"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"I", "Iu", "a"})); BOOST_TEST(m_programCache.entries().find("I")->second.roundNumber == 0); BOOST_TEST(m_programCache.entries().find("Iu")->second.roundNumber == 0); BOOST_TEST(m_programCache.entries().find("a")->second.roundNumber == 0); @@ -194,7 +193,7 @@ BOOST_FIXTURE_TEST_CASE(startRound_should_remove_entries_older_than_two_rounds, m_programCache.optimiseProgram("af"); BOOST_TEST(m_programCache.currentRound() == 1); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"I", "Iu", "a", "af"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"I", "Iu", "a", "af"})); BOOST_TEST(m_programCache.entries().find("I")->second.roundNumber == 0); BOOST_TEST(m_programCache.entries().find("Iu")->second.roundNumber == 0); BOOST_TEST(m_programCache.entries().find("a")->second.roundNumber == 1); @@ -203,7 +202,7 @@ BOOST_FIXTURE_TEST_CASE(startRound_should_remove_entries_older_than_two_rounds, m_programCache.startRound(2); BOOST_TEST(m_programCache.currentRound() == 2); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"a", "af"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"a", "af"})); BOOST_TEST(m_programCache.entries().find("a")->second.roundNumber == 1); BOOST_TEST(m_programCache.entries().find("af")->second.roundNumber == 1); @@ -223,31 +222,31 @@ BOOST_FIXTURE_TEST_CASE(gatherStats_should_return_cache_statistics, ProgramCache m_programCache.optimiseProgram("L"); m_programCache.optimiseProgram("Iu"); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"L", "I", "Iu"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"L", "I", "Iu"})); CacheStats expectedStats1{0, 3, sizeL + sizeI + sizeIu, {{0, 3}}}; BOOST_CHECK(m_programCache.gatherStats() == expectedStats1); m_programCache.optimiseProgram("IuO"); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"L", "I", "Iu", "IuO"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"L", "I", "Iu", "IuO"})); CacheStats expectedStats2{2, 4, sizeL + sizeI + sizeIu + sizeIuO, {{0, 4}}}; BOOST_CHECK(m_programCache.gatherStats() == expectedStats2); m_programCache.startRound(1); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"L", "I", "Iu", "IuO"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"L", "I", "Iu", "IuO"})); BOOST_CHECK(m_programCache.gatherStats() == expectedStats2); m_programCache.optimiseProgram("IuO"); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"L", "I", "Iu", "IuO"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"L", "I", "Iu", "IuO"})); CacheStats expectedStats3{5, 4, sizeL + sizeI + sizeIu + sizeIuO, {{0, 1}, {1, 3}}}; BOOST_CHECK(m_programCache.gatherStats() == expectedStats3); m_programCache.startRound(2); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"I", "Iu", "IuO"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"I", "Iu", "IuO"})); CacheStats expectedStats4{5, 4, sizeI + sizeIu + sizeIuO, {{1, 3}}}; BOOST_CHECK(m_programCache.gatherStats() == expectedStats4); m_programCache.optimiseProgram("LT"); - BOOST_REQUIRE((cachedKeys(m_programCache) == set{"L", "LT", "I", "Iu", "IuO"})); + BOOST_REQUIRE((cachedKeys(m_programCache) == std::set{"L", "LT", "I", "Iu", "IuO"})); CacheStats expectedStats5{5, 6, sizeL + sizeLT + sizeI + sizeIu + sizeIuO, {{1, 3}, {2, 2}}}; BOOST_CHECK(m_programCache.gatherStats() == expectedStats5); } diff --git a/test/yulPhaser/Selections.cpp b/test/yulPhaser/Selections.cpp index 28c8b8a879dc..866234978590 100644 --- a/test/yulPhaser/Selections.cpp +++ b/test/yulPhaser/Selections.cpp @@ -29,7 +29,6 @@ #include #include -using namespace std; using namespace solidity::util; namespace solidity::phaser::test @@ -41,28 +40,28 @@ BOOST_AUTO_TEST_SUITE(RangeSelectionTest) BOOST_AUTO_TEST_CASE(materialise) { - BOOST_TEST(RangeSelection(0.0, 1.0).materialise(10) == vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); - BOOST_TEST(RangeSelection(0.0, 0.1).materialise(10) == vector({0})); - BOOST_TEST(RangeSelection(0.0, 0.2).materialise(10) == vector({0, 1})); - BOOST_TEST(RangeSelection(0.0, 0.7).materialise(10) == vector({0, 1, 2, 3, 4, 5, 6})); + BOOST_TEST(RangeSelection(0.0, 1.0).materialise(10) == std::vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); + BOOST_TEST(RangeSelection(0.0, 0.1).materialise(10) == std::vector({0})); + BOOST_TEST(RangeSelection(0.0, 0.2).materialise(10) == std::vector({0, 1})); + BOOST_TEST(RangeSelection(0.0, 0.7).materialise(10) == std::vector({0, 1, 2, 3, 4, 5, 6})); - BOOST_TEST(RangeSelection(0.9, 1.0).materialise(10) == vector({ 9})); - BOOST_TEST(RangeSelection(0.8, 1.0).materialise(10) == vector({ 8, 9})); - BOOST_TEST(RangeSelection(0.5, 1.0).materialise(10) == vector({ 5, 6, 7, 8, 9})); + BOOST_TEST(RangeSelection(0.9, 1.0).materialise(10) == std::vector({ 9})); + BOOST_TEST(RangeSelection(0.8, 1.0).materialise(10) == std::vector({ 8, 9})); + BOOST_TEST(RangeSelection(0.5, 1.0).materialise(10) == std::vector({ 5, 6, 7, 8, 9})); - BOOST_TEST(RangeSelection(0.3, 0.6).materialise(10) == vector({ 3, 4, 5 })); - BOOST_TEST(RangeSelection(0.2, 0.7).materialise(10) == vector({ 2, 3, 4, 5, 6 })); - BOOST_TEST(RangeSelection(0.4, 0.7).materialise(10) == vector({ 4, 5, 6 })); + BOOST_TEST(RangeSelection(0.3, 0.6).materialise(10) == std::vector({ 3, 4, 5 })); + BOOST_TEST(RangeSelection(0.2, 0.7).materialise(10) == std::vector({ 2, 3, 4, 5, 6 })); + BOOST_TEST(RangeSelection(0.4, 0.7).materialise(10) == std::vector({ 4, 5, 6 })); - BOOST_TEST(RangeSelection(0.4, 0.7).materialise(5) == vector({2, 3})); + BOOST_TEST(RangeSelection(0.4, 0.7).materialise(5) == std::vector({2, 3})); } BOOST_AUTO_TEST_CASE(materialise_should_round_indices) { - BOOST_TEST(RangeSelection(0.01, 0.99).materialise(10) == vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); - BOOST_TEST(RangeSelection(0.04, 0.96).materialise(10) == vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); - BOOST_TEST(RangeSelection(0.05, 0.95).materialise(10) == vector({ 1, 2, 3, 4, 5, 6, 7, 8, 9})); - BOOST_TEST(RangeSelection(0.06, 0.94).materialise(10) == vector({ 1, 2, 3, 4, 5, 6, 7, 8 })); + BOOST_TEST(RangeSelection(0.01, 0.99).materialise(10) == std::vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); + BOOST_TEST(RangeSelection(0.04, 0.96).materialise(10) == std::vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); + BOOST_TEST(RangeSelection(0.05, 0.95).materialise(10) == std::vector({ 1, 2, 3, 4, 5, 6, 7, 8, 9})); + BOOST_TEST(RangeSelection(0.06, 0.94).materialise(10) == std::vector({ 1, 2, 3, 4, 5, 6, 7, 8 })); } BOOST_AUTO_TEST_CASE(materialise_should_handle_empty_collections) @@ -93,27 +92,27 @@ BOOST_AUTO_TEST_SUITE(MosaicSelectionTest) BOOST_AUTO_TEST_CASE(materialise) { - BOOST_TEST(MosaicSelection({1}, 0.5).materialise(4) == vector({1, 1})); - BOOST_TEST(MosaicSelection({1}, 1.0).materialise(4) == vector({1, 1, 1, 1})); - BOOST_TEST(MosaicSelection({1}, 2.0).materialise(4) == vector({1, 1, 1, 1, 1, 1, 1, 1})); - BOOST_TEST(MosaicSelection({1}, 1.0).materialise(2) == vector({1, 1})); - - BOOST_TEST(MosaicSelection({0, 1}, 0.5).materialise(4) == vector({0, 1})); - BOOST_TEST(MosaicSelection({0, 1}, 1.0).materialise(4) == vector({0, 1, 0, 1})); - BOOST_TEST(MosaicSelection({0, 1}, 2.0).materialise(4) == vector({0, 1, 0, 1, 0, 1, 0, 1})); - BOOST_TEST(MosaicSelection({0, 1}, 1.0).materialise(2) == vector({0, 1})); - - BOOST_TEST(MosaicSelection({3, 2, 1, 0}, 0.5).materialise(4) == vector({3, 2})); - BOOST_TEST(MosaicSelection({3, 2, 1, 0}, 1.0).materialise(4) == vector({3, 2, 1, 0})); - BOOST_TEST(MosaicSelection({3, 2, 1, 0}, 2.0).materialise(4) == vector({3, 2, 1, 0, 3, 2, 1, 0})); - BOOST_TEST(MosaicSelection({1, 0, 1, 0}, 1.0).materialise(2) == vector({1, 0})); + BOOST_TEST(MosaicSelection({1}, 0.5).materialise(4) == std::vector({1, 1})); + BOOST_TEST(MosaicSelection({1}, 1.0).materialise(4) == std::vector({1, 1, 1, 1})); + BOOST_TEST(MosaicSelection({1}, 2.0).materialise(4) == std::vector({1, 1, 1, 1, 1, 1, 1, 1})); + BOOST_TEST(MosaicSelection({1}, 1.0).materialise(2) == std::vector({1, 1})); + + BOOST_TEST(MosaicSelection({0, 1}, 0.5).materialise(4) == std::vector({0, 1})); + BOOST_TEST(MosaicSelection({0, 1}, 1.0).materialise(4) == std::vector({0, 1, 0, 1})); + BOOST_TEST(MosaicSelection({0, 1}, 2.0).materialise(4) == std::vector({0, 1, 0, 1, 0, 1, 0, 1})); + BOOST_TEST(MosaicSelection({0, 1}, 1.0).materialise(2) == std::vector({0, 1})); + + BOOST_TEST(MosaicSelection({3, 2, 1, 0}, 0.5).materialise(4) == std::vector({3, 2})); + BOOST_TEST(MosaicSelection({3, 2, 1, 0}, 1.0).materialise(4) == std::vector({3, 2, 1, 0})); + BOOST_TEST(MosaicSelection({3, 2, 1, 0}, 2.0).materialise(4) == std::vector({3, 2, 1, 0, 3, 2, 1, 0})); + BOOST_TEST(MosaicSelection({1, 0, 1, 0}, 1.0).materialise(2) == std::vector({1, 0})); } BOOST_AUTO_TEST_CASE(materialise_should_round_indices) { - BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 0.49).materialise(5) == vector({4, 3})); - BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 0.50).materialise(5) == vector({4, 3, 2})); - BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 0.51).materialise(5) == vector({4, 3, 2})); + BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 0.49).materialise(5) == std::vector({4, 3})); + BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 0.50).materialise(5) == std::vector({4, 3, 2})); + BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 0.51).materialise(5) == std::vector({4, 3, 2})); } BOOST_AUTO_TEST_CASE(materialise_should_handle_empty_collections) @@ -132,10 +131,10 @@ BOOST_AUTO_TEST_CASE(materialise_should_handle_empty_selections) BOOST_AUTO_TEST_CASE(materialise_should_clamp_indices_at_collection_size) { - BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 1.0).materialise(4) == vector({3, 3, 2, 1})); - BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 2.0).materialise(3) == vector({2, 2, 2, 1, 0, 2})); - BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 1.0).materialise(1) == vector({0})); - BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 7.0).materialise(1) == vector({0, 0, 0, 0, 0, 0, 0})); + BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 1.0).materialise(4) == std::vector({3, 3, 2, 1})); + BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 2.0).materialise(3) == std::vector({2, 2, 2, 1, 0, 2})); + BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 1.0).materialise(1) == std::vector({0})); + BOOST_TEST(MosaicSelection({4, 3, 2, 1, 0}, 7.0).materialise(1) == std::vector({0, 0, 0, 0, 0, 0, 0})); } BOOST_AUTO_TEST_SUITE_END() @@ -150,17 +149,17 @@ BOOST_AUTO_TEST_CASE(materialise_should_return_random_values_with_equal_probabil constexpr double variance = (collectionSize * collectionSize - 1) / 12.0; SimulationRNG::reset(1); - vector samples = RandomSelection(selectionSize).materialise(collectionSize); + std::vector samples = RandomSelection(selectionSize).materialise(collectionSize); - BOOST_TEST(abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); } BOOST_AUTO_TEST_CASE(materialise_should_return_only_values_that_can_be_used_as_collection_indices) { const size_t collectionSize = 200; - vector indices = RandomSelection(0.5).materialise(collectionSize); + std::vector indices = RandomSelection(0.5).materialise(collectionSize); BOOST_TEST(indices.size() == 100); BOOST_TEST(all_of(indices.begin(), indices.end(), [&](auto const& index){ return index <= collectionSize; })); @@ -214,20 +213,20 @@ BOOST_AUTO_TEST_CASE(materialise_should_return_random_values_with_equal_probabil constexpr double variance = selectionChance * (1 - selectionChance); SimulationRNG::reset(1); - auto indices = convertContainer>(RandomSubset(selectionChance).materialise(collectionSize)); + auto indices = convertContainer>(RandomSubset(selectionChance).materialise(collectionSize)); - vector bernoulliTrials(collectionSize); + std::vector bernoulliTrials(collectionSize); for (size_t i = 0; i < collectionSize; ++i) bernoulliTrials[i] = double(indices.count(i)); - BOOST_TEST(abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance); } BOOST_AUTO_TEST_CASE(materialise_should_return_only_values_that_can_be_used_as_collection_indices) { const size_t collectionSize = 200; - vector indices = RandomSubset(0.5).materialise(collectionSize); + std::vector indices = RandomSubset(0.5).materialise(collectionSize); BOOST_TEST(all_of(indices.begin(), indices.end(), [&](auto const& index){ return index <= collectionSize; })); } @@ -235,7 +234,7 @@ BOOST_AUTO_TEST_CASE(materialise_should_return_only_values_that_can_be_used_as_c BOOST_AUTO_TEST_CASE(materialise_should_return_indices_in_the_same_order_they_are_in_the_container) { const size_t collectionSize = 200; - vector indices = RandomSubset(0.5).materialise(collectionSize); + std::vector indices = RandomSubset(0.5).materialise(collectionSize); for (size_t i = 1; i < indices.size(); ++i) BOOST_TEST(indices[i - 1] < indices[i]); diff --git a/test/yulPhaser/SimulationRNG.cpp b/test/yulPhaser/SimulationRNG.cpp index d6e8c3a81150..ff91846e30d8 100644 --- a/test/yulPhaser/SimulationRNG.cpp +++ b/test/yulPhaser/SimulationRNG.cpp @@ -24,8 +24,6 @@ #include -using namespace std; - namespace solidity::phaser::test { @@ -43,12 +41,12 @@ BOOST_AUTO_TEST_CASE(bernoulliTrial_should_produce_samples_with_right_expected_v constexpr double expectedValue = successProbability; constexpr double variance = successProbability * (1 - successProbability); - vector samples; + std::vector samples; for (uint32_t i = 0; i < numSamples; ++i) samples.push_back(static_cast(SimulationRNG::bernoulliTrial(successProbability))); - BOOST_TEST(abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); } BOOST_AUTO_TEST_CASE(bernoulliTrial_can_be_reset) @@ -57,21 +55,21 @@ BOOST_AUTO_TEST_CASE(bernoulliTrial_can_be_reset) constexpr double successProbability = 0.4; SimulationRNG::reset(1); - vector samples1; + std::vector samples1; for (uint32_t i = 0; i < numSamples; ++i) samples1.push_back(static_cast(SimulationRNG::bernoulliTrial(successProbability))); - vector samples2; + std::vector samples2; for (uint32_t i = 0; i < numSamples; ++i) samples2.push_back(static_cast(SimulationRNG::bernoulliTrial(successProbability))); SimulationRNG::reset(1); - vector samples3; + std::vector samples3; for (uint32_t i = 0; i < numSamples; ++i) samples3.push_back(static_cast(SimulationRNG::bernoulliTrial(successProbability))); SimulationRNG::reset(2); - vector samples4; + std::vector samples4; for (uint32_t i = 0; i < numSamples; ++i) samples4.push_back(static_cast(SimulationRNG::bernoulliTrial(successProbability))); @@ -95,12 +93,12 @@ BOOST_AUTO_TEST_CASE(uniformInt_returns_different_values_when_called_multiple_ti constexpr double expectedValue = (minValue + maxValue) / 2.0; constexpr double variance = ((maxValue - minValue + 1) * (maxValue - minValue + 1) - 1) / 12.0; - vector samples; + std::vector samples; for (uint32_t i = 0; i < numSamples; ++i) samples.push_back(SimulationRNG::uniformInt(minValue, maxValue)); - BOOST_TEST(abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); } BOOST_AUTO_TEST_CASE(uniformInt_can_be_reset) @@ -110,21 +108,21 @@ BOOST_AUTO_TEST_CASE(uniformInt_can_be_reset) constexpr uint32_t maxValue = 80; SimulationRNG::reset(1); - vector samples1; + std::vector samples1; for (uint32_t i = 0; i < numSamples; ++i) samples1.push_back(SimulationRNG::uniformInt(minValue, maxValue)); - vector samples2; + std::vector samples2; for (uint32_t i = 0; i < numSamples; ++i) samples2.push_back(SimulationRNG::uniformInt(minValue, maxValue)); SimulationRNG::reset(1); - vector samples3; + std::vector samples3; for (uint32_t i = 0; i < numSamples; ++i) samples3.push_back(SimulationRNG::uniformInt(minValue, maxValue)); SimulationRNG::reset(2); - vector samples4; + std::vector samples4; for (uint32_t i = 0; i < numSamples; ++i) samples4.push_back(SimulationRNG::uniformInt(minValue, maxValue)); @@ -148,12 +146,12 @@ BOOST_AUTO_TEST_CASE(binomialInt_should_produce_samples_with_right_expected_valu constexpr double expectedValue = numTrials * successProbability; constexpr double variance = numTrials * successProbability * (1 - successProbability); - vector samples; + std::vector samples; for (uint32_t i = 0; i < numSamples; ++i) samples.push_back(SimulationRNG::binomialInt(numTrials, successProbability)); - BOOST_TEST(abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); - BOOST_TEST(abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); + BOOST_TEST(std::abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance); + BOOST_TEST(std::abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance); } BOOST_AUTO_TEST_CASE(binomialInt_can_be_reset) @@ -163,21 +161,21 @@ BOOST_AUTO_TEST_CASE(binomialInt_can_be_reset) constexpr double successProbability = 0.6; SimulationRNG::reset(1); - vector samples1; + std::vector samples1; for (uint32_t i = 0; i < numSamples; ++i) samples1.push_back(SimulationRNG::binomialInt(numTrials, successProbability)); - vector samples2; + std::vector samples2; for (uint32_t i = 0; i < numSamples; ++i) samples2.push_back(SimulationRNG::binomialInt(numTrials, successProbability)); SimulationRNG::reset(1); - vector samples3; + std::vector samples3; for (uint32_t i = 0; i < numSamples; ++i) samples3.push_back(SimulationRNG::binomialInt(numTrials, successProbability)); SimulationRNG::reset(2); - vector samples4; + std::vector samples4; for (uint32_t i = 0; i < numSamples; ++i) samples4.push_back(SimulationRNG::binomialInt(numTrials, successProbability)); diff --git a/test/yulPhaser/TestHelpers.cpp b/test/yulPhaser/TestHelpers.cpp index 50afd70a3eb3..d75b63b4ac8b 100644 --- a/test/yulPhaser/TestHelpers.cpp +++ b/test/yulPhaser/TestHelpers.cpp @@ -22,22 +22,21 @@ #include -using namespace std; using namespace solidity; using namespace solidity::yul; using namespace solidity::phaser; using namespace solidity::phaser::test; -function phaser::test::wholeChromosomeReplacement(Chromosome _newChromosome) +std::function phaser::test::wholeChromosomeReplacement(Chromosome _newChromosome) { return [_newChromosome = std::move(_newChromosome)](Chromosome const&) { return _newChromosome; }; } -function phaser::test::geneSubstitution(size_t _geneIndex, string _geneValue) +std::function phaser::test::geneSubstitution(size_t _geneIndex, std::string _geneValue) { return [=](Chromosome const& _chromosome) { - vector newGenes = _chromosome.optimisationSteps(); + std::vector newGenes = _chromosome.optimisationSteps(); assert(_geneIndex < newGenes.size()); newGenes[_geneIndex] = _geneValue; @@ -45,18 +44,18 @@ function phaser::test::geneSubstitution(size_t _geneIndex, string _gen }; } -vector phaser::test::chromosomeLengths(Population const& _population) +std::vector phaser::test::chromosomeLengths(Population const& _population) { - vector lengths; + std::vector lengths; for (auto const& individual: _population.individuals()) lengths.push_back(individual.chromosome.length()); return lengths; } -map phaser::test::enumerateOptmisationSteps() +std::map phaser::test::enumerateOptmisationSteps() { - map stepIndices; + std::map stepIndices; size_t i = 0; for (auto const& nameAndAbbreviation: OptimiserSuite::stepNameToAbbreviationMap()) stepIndices.insert({nameAndAbbreviation.first, i++}); @@ -67,29 +66,29 @@ map phaser::test::enumerateOptmisationSteps() size_t phaser::test::countDifferences(Chromosome const& _chromosome1, Chromosome const& _chromosome2) { size_t count = 0; - for (size_t i = 0; i < min(_chromosome1.length(), _chromosome2.length()); ++i) + for (size_t i = 0; i < std::min(_chromosome1.length(), _chromosome2.length()); ++i) if (_chromosome1.optimisationSteps()[i] != _chromosome2.optimisationSteps()[i]) ++count; - return count + static_cast(abs( + return count + static_cast(std::abs( static_cast(_chromosome1.length()) - static_cast(_chromosome2.length()) )); } -string phaser::test::stripWhitespace(string const& input) +std::string phaser::test::stripWhitespace(std::string const& input) { - regex whitespaceRegex("\\s+"); + std::regex whitespaceRegex("\\s+"); return regex_replace(input, whitespaceRegex, ""); } -size_t phaser::test::countSubstringOccurrences(string const& _inputString, string const& _substring) +size_t phaser::test::countSubstringOccurrences(std::string const& _inputString, std::string const& _substring) { assert(_substring.size() > 0); size_t count = 0; size_t lastOccurrence = 0; - while ((lastOccurrence = _inputString.find(_substring, lastOccurrence)) != string::npos) + while ((lastOccurrence = _inputString.find(_substring, lastOccurrence)) != std::string::npos) { ++count; lastOccurrence += _substring.size(); diff --git a/test/yulPhaser/TestHelpersTest.cpp b/test/yulPhaser/TestHelpersTest.cpp index 89b98ecad7aa..23be74230cca 100644 --- a/test/yulPhaser/TestHelpersTest.cpp +++ b/test/yulPhaser/TestHelpersTest.cpp @@ -24,7 +24,6 @@ #include -using namespace std; using namespace solidity::yul; using namespace boost::test_tools; @@ -43,7 +42,7 @@ BOOST_AUTO_TEST_CASE(ChromosomeLengthMetric_evaluate_should_return_chromosome_le BOOST_AUTO_TEST_CASE(wholeChromosomeReplacement_should_replace_whole_chromosome_with_another) { - function mutation = wholeChromosomeReplacement(Chromosome("aaa")); + std::function mutation = wholeChromosomeReplacement(Chromosome("aaa")); BOOST_TEST(mutation(Chromosome("ccc")) == Chromosome("aaa")); } @@ -51,22 +50,22 @@ BOOST_AUTO_TEST_CASE(geneSubstitution_should_change_a_single_gene_at_a_given_ind { Chromosome chromosome("aaccff"); - function mutation1 = geneSubstitution(0, chromosome.optimisationSteps()[5]); + std::function mutation1 = geneSubstitution(0, chromosome.optimisationSteps()[5]); BOOST_TEST(mutation1(chromosome) == Chromosome("faccff")); - function mutation2 = geneSubstitution(5, chromosome.optimisationSteps()[0]); + std::function mutation2 = geneSubstitution(5, chromosome.optimisationSteps()[0]); BOOST_TEST(mutation2(chromosome) == Chromosome("aaccfa")); } BOOST_AUTO_TEST_CASE(chromosomeLengths_should_return_lengths_of_all_chromosomes_in_a_population) { - shared_ptr fitnessMetric = make_shared(); + std::shared_ptr fitnessMetric = std::make_shared(); Population population1(fitnessMetric, {Chromosome(), Chromosome("a"), Chromosome("aa"), Chromosome("aaa")}); - BOOST_TEST((chromosomeLengths(population1) == vector{0, 1, 2, 3})); + BOOST_TEST((chromosomeLengths(population1) == std::vector{0, 1, 2, 3})); Population population2(fitnessMetric); - BOOST_TEST((chromosomeLengths(population2) == vector{})); + BOOST_TEST((chromosomeLengths(population2) == std::vector{})); } BOOST_AUTO_TEST_CASE(countDifferences_should_return_zero_for_identical_chromosomes) @@ -99,11 +98,11 @@ BOOST_AUTO_TEST_CASE(countDifferences_should_count_missing_characters_as_differe BOOST_AUTO_TEST_CASE(enumerateOptimisationSteps_should_assing_indices_to_all_available_optimisation_steps) { - map stepsAndAbbreviations = OptimiserSuite::stepNameToAbbreviationMap(); - map stepsAndIndices = enumerateOptmisationSteps(); + std::map stepsAndAbbreviations = OptimiserSuite::stepNameToAbbreviationMap(); + std::map stepsAndIndices = enumerateOptmisationSteps(); BOOST_TEST(stepsAndIndices.size() == stepsAndAbbreviations.size()); - set stepsSoFar; + std::set stepsSoFar; for (auto& [name, index]: stepsAndIndices) { BOOST_TEST(index >= 0);