diff --git a/test/yulPhaser/Common.cpp b/test/yulPhaser/Common.cpp index c3653eaec..38c6e445b 100644 --- a/test/yulPhaser/Common.cpp +++ b/test/yulPhaser/Common.cpp @@ -25,6 +25,15 @@ using namespace std; using namespace solidity; using namespace solidity::yul; +vector phaser::test::chromosomeLengths(Population const& _population) +{ + vector lengths; + for (auto const& individual: _population.individuals()) + lengths.push_back(individual.chromosome.length()); + + return lengths; +} + map phaser::test::enumerateOptmisationSteps() { map stepIndices; diff --git a/test/yulPhaser/Common.h b/test/yulPhaser/Common.h index 3dcf63288..c4da6c99c 100644 --- a/test/yulPhaser/Common.h +++ b/test/yulPhaser/Common.h @@ -28,6 +28,8 @@ #pragma once +#include + #include #include #include @@ -37,6 +39,10 @@ namespace solidity::phaser::test { // CHROMOSOME AND POPULATION HELPERS + +/// Returns a vector containing lengths of all chromosomes in the population (in the same order). +std::vector chromosomeLengths(Population const& _population); + /// Assigns indices from 0 to N to all optimisation steps available in the OptimiserSuite. /// This is a convenience helper to make it easier to test their distribution with tools made for /// integers. diff --git a/test/yulPhaser/CommonTest.cpp b/test/yulPhaser/CommonTest.cpp index cdcba6f53..be686446f 100644 --- a/test/yulPhaser/CommonTest.cpp +++ b/test/yulPhaser/CommonTest.cpp @@ -19,11 +19,14 @@ #include +#include + #include #include using namespace std; +using namespace solidity::langutil; using namespace solidity::yul; using namespace boost::test_tools; @@ -33,6 +36,18 @@ namespace solidity::phaser::test BOOST_AUTO_TEST_SUITE(Phaser) BOOST_AUTO_TEST_SUITE(CommonTest) +BOOST_AUTO_TEST_CASE(chromosomeLengths_should_return_lengths_of_all_chromosomes_in_a_population) +{ + CharStream sourceStream("{}", ""); + auto program = Program::load(sourceStream); + + Population population1(program, {Chromosome(), Chromosome("a"), Chromosome("aa"), Chromosome("aaa")}); + BOOST_TEST((chromosomeLengths(population1) == vector{0, 1, 2, 3})); + + Population population2(program); + BOOST_TEST((chromosomeLengths(population2) == vector{})); +} + BOOST_AUTO_TEST_CASE(enumerateOptimisationSteps_should_assing_indices_to_all_available_optimisation_steps) { map stepsAndAbbreviations = OptimiserSuite::stepNameToAbbreviationMap();