[yul-phaser] Common: Add wholeChromosomeReplacement() mutation and countDifferences()

This commit is contained in:
Kamil Śliwak
2020-03-09 13:21:48 +01:00
parent f9f2bdb5f7
commit 643a5f2035
3 changed files with 61 additions and 0 deletions
+15
View File
@@ -24,6 +24,12 @@
using namespace std;
using namespace solidity;
using namespace solidity::yul;
using namespace solidity::phaser;
function<Mutation> phaser::test::wholeChromosomeReplacement(Chromosome _newChromosome)
{
return [_newChromosome = move(_newChromosome)](Chromosome const&) { return _newChromosome; };
}
vector<size_t> phaser::test::chromosomeLengths(Population const& _population)
{
@@ -44,6 +50,15 @@ map<string, size_t> phaser::test::enumerateOptmisationSteps()
return stepIndices;
}
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)
count += static_cast<int>(_chromosome1.optimisationSteps()[i] != _chromosome2.optimisationSteps()[i]);
return count + abs(static_cast<int>(_chromosome1.length() - _chromosome2.length()));
}
string phaser::test::stripWhitespace(string const& input)
{
regex whitespaceRegex("\\s+");