mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
yul-phaser: A few more tweaks to ensure that signedness conversions do not cause warnings
- Don't cast booleans to int when the result gets assigned to an unsigned type. Relace them with ifs. - Use unsigned initializer for a variable declared in a lambda capture. - Unsigned abs() of a difference of unsigned values.
This commit is contained in:
parent
a49a127627
commit
9b3d1c11ff
@ -179,8 +179,8 @@ BOOST_AUTO_TEST_CASE(alternativeMutations_should_choose_between_mutations_with_g
|
||||
for (size_t i = 0; i < 10; ++i)
|
||||
{
|
||||
Chromosome mutatedChromosome = mutation(chromosome);
|
||||
cCount += static_cast<int>(mutatedChromosome == Chromosome("c"));
|
||||
fCount += static_cast<int>(mutatedChromosome == Chromosome("f"));
|
||||
cCount += (mutatedChromosome == Chromosome("c") ? 1 : 0);
|
||||
fCount += (mutatedChromosome == Chromosome("f") ? 1 : 0);
|
||||
}
|
||||
|
||||
// This particular seed results in 7 "c"s out of 10 which looks plausible given the 80% chance.
|
||||
|
@ -135,7 +135,7 @@ BOOST_FIXTURE_TEST_CASE(makeRandom_should_get_chromosome_lengths_from_specified_
|
||||
size_t maxLength = 5;
|
||||
assert(chromosomeCount % maxLength == 0);
|
||||
|
||||
auto nextLength = [counter = 0, maxLength]() mutable { return counter++ % maxLength; };
|
||||
auto nextLength = [counter = 0ul, maxLength]() mutable { return counter++ % maxLength; };
|
||||
auto population = Population::makeRandom(m_fitnessMetric, chromosomeCount, nextLength);
|
||||
|
||||
// We can't rely on the order since the population sorts its chromosomes immediately but
|
||||
|
@ -72,9 +72,13 @@ size_t phaser::test::countDifferences(Chromosome const& _chromosome1, Chromosome
|
||||
{
|
||||
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]);
|
||||
if (_chromosome1.optimisationSteps()[i] != _chromosome2.optimisationSteps()[i])
|
||||
++count;
|
||||
|
||||
return count + abs(static_cast<int>(_chromosome1.length() - _chromosome2.length()));
|
||||
return count + static_cast<size_t>(abs(
|
||||
static_cast<long>(_chromosome1.length()) -
|
||||
static_cast<long>(_chromosome2.length())
|
||||
));
|
||||
}
|
||||
|
||||
TemporaryDirectory::TemporaryDirectory(std::string const& _prefix):
|
||||
|
Loading…
Reference in New Issue
Block a user