mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'origin/develop' into breaking
This commit is contained in:
+2
-2
@@ -300,7 +300,7 @@ h160 EVMHost::convertFromEVMC(evmc::address const& _addr)
|
||||
evmc::address EVMHost::convertToEVMC(h160 const& _addr)
|
||||
{
|
||||
evmc::address a;
|
||||
for (size_t i = 0; i < 20; ++i)
|
||||
for (unsigned i = 0; i < 20; ++i)
|
||||
a.bytes[i] = _addr[i];
|
||||
return a;
|
||||
}
|
||||
@@ -313,7 +313,7 @@ h256 EVMHost::convertFromEVMC(evmc::bytes32 const& _data)
|
||||
evmc::bytes32 EVMHost::convertToEVMC(h256 const& _data)
|
||||
{
|
||||
evmc::bytes32 d;
|
||||
for (size_t i = 0; i < 32; ++i)
|
||||
for (unsigned i = 0; i < 32; ++i)
|
||||
d.bytes[i] = _data[i];
|
||||
return d;
|
||||
}
|
||||
|
||||
+3
-3
@@ -34,7 +34,7 @@ namespace solidity::test
|
||||
|
||||
bytes onlyMetadata(bytes const& _bytecode)
|
||||
{
|
||||
unsigned size = _bytecode.size();
|
||||
size_t size = _bytecode.size();
|
||||
if (size < 5)
|
||||
return bytes{};
|
||||
size_t metadataSize = (static_cast<size_t>(_bytecode[size - 2]) << 8ul) + static_cast<size_t>(_bytecode[size - 1]);
|
||||
@@ -49,10 +49,10 @@ bytes onlyMetadata(bytes const& _bytecode)
|
||||
|
||||
bytes bytecodeSansMetadata(bytes const& _bytecode)
|
||||
{
|
||||
unsigned metadataSize = onlyMetadata(_bytecode).size();
|
||||
size_t metadataSize = onlyMetadata(_bytecode).size();
|
||||
if (metadataSize == 0)
|
||||
return bytes{};
|
||||
return bytes(_bytecode.begin(), _bytecode.end() - metadataSize - 2);
|
||||
return bytes(_bytecode.begin(), _bytecode.end() - static_cast<ptrdiff_t>(metadataSize) - 2);
|
||||
}
|
||||
|
||||
string bytecodeSansMetadata(string const& _bytecode)
|
||||
|
||||
@@ -1282,7 +1282,7 @@ BOOST_AUTO_TEST_CASE(cse_remove_redundant_shift_masking)
|
||||
if (!solidity::test::CommonOptions::get().evmVersion().hasBitwiseShifting())
|
||||
return;
|
||||
|
||||
for (size_t i = 1; i < 256; i++)
|
||||
for (unsigned i = 1; i < 256; i++)
|
||||
{
|
||||
checkCSE({
|
||||
u256(boost::multiprecision::pow(u256(2), i) - 1),
|
||||
@@ -1310,7 +1310,7 @@ BOOST_AUTO_TEST_CASE(cse_remove_redundant_shift_masking)
|
||||
}
|
||||
|
||||
// Check that opt. does NOT trigger
|
||||
for (size_t i = 1; i < 255; i++)
|
||||
for (unsigned i = 1; i < 255; i++)
|
||||
{
|
||||
checkCSE({
|
||||
u256(boost::multiprecision::pow(u256(2), i) - 1),
|
||||
|
||||
@@ -133,7 +133,7 @@ TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefi
|
||||
for (size_t i = 0; i < m_sources.size(); i++)
|
||||
{
|
||||
sources[m_sources[i].first] = m_sources[i].second;
|
||||
sourceIndices[m_sources[i].first] = i + 1;
|
||||
sourceIndices[m_sources[i].first] = static_cast<unsigned>(i + 1);
|
||||
}
|
||||
c.setSources(sources);
|
||||
c.setEVMVersion(solidity::test::CommonOptions::get().evmVersion());
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
@@ -82,7 +83,7 @@ struct SolidityEndToEndTestExecutionFramework: public SolidityExecutionFramework
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(SolidityEndToEndTest, SolidityEndToEndTestExecutionFramework)
|
||||
|
||||
int constexpr roundTo32(int _num)
|
||||
unsigned constexpr roundTo32(unsigned _num)
|
||||
{
|
||||
return (_num + 31) / 32 * 32;
|
||||
}
|
||||
@@ -2126,8 +2127,7 @@ BOOST_AUTO_TEST_CASE(event_indexed_string)
|
||||
BOOST_REQUIRE_EQUAL(numLogs(), 1);
|
||||
BOOST_CHECK_EQUAL(logAddress(0), m_contractAddress);
|
||||
string dynx(90, 0);
|
||||
for (size_t i = 0; i < dynx.size(); ++i)
|
||||
dynx[i] = i;
|
||||
std::iota(dynx.begin(), dynx.end(), 0);
|
||||
BOOST_CHECK(logData(0) == bytes());
|
||||
BOOST_REQUIRE_EQUAL(numLogTopics(0), 3);
|
||||
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(dynx));
|
||||
@@ -3362,7 +3362,7 @@ BOOST_AUTO_TEST_CASE(nested_string_as_public_mapping_key)
|
||||
ABI_CHECK(callContractFunction(
|
||||
"set(string,string,uint256)",
|
||||
u256(0x60),
|
||||
u256(roundTo32(0x80 + strings[i].size())),
|
||||
u256(roundTo32(static_cast<unsigned>(0x80 + strings[i].size()))),
|
||||
u256(7 + i),
|
||||
u256(strings[i].size()),
|
||||
strings[i],
|
||||
@@ -3373,7 +3373,7 @@ BOOST_AUTO_TEST_CASE(nested_string_as_public_mapping_key)
|
||||
ABI_CHECK(callContractFunction(
|
||||
"data(string,string)",
|
||||
u256(0x40),
|
||||
u256(roundTo32(0x60 + strings[i].size())),
|
||||
u256(roundTo32(static_cast<unsigned>(0x60 + strings[i].size()))),
|
||||
u256(strings[i].size()),
|
||||
strings[i],
|
||||
u256(strings[i+1].size()),
|
||||
@@ -3426,7 +3426,7 @@ BOOST_AUTO_TEST_CASE(nested_mixed_string_as_public_mapping_key)
|
||||
u256(0xA0),
|
||||
u256(data[i].s2),
|
||||
u256(data[i].s3),
|
||||
u256(roundTo32(0xC0 + data[i].s1.size())),
|
||||
u256(roundTo32(static_cast<unsigned>(0xC0 + data[i].s1.size()))),
|
||||
u256(i - 3),
|
||||
u256(data[i].s1.size()),
|
||||
data[i].s1,
|
||||
@@ -3439,7 +3439,7 @@ BOOST_AUTO_TEST_CASE(nested_mixed_string_as_public_mapping_key)
|
||||
u256(0x80),
|
||||
u256(data[i].s2),
|
||||
u256(data[i].s3),
|
||||
u256(roundTo32(0xA0 + data[i].s1.size())),
|
||||
u256(roundTo32(static_cast<unsigned>(0xA0 + data[i].s1.size()))),
|
||||
u256(data[i].s1.size()),
|
||||
data[i].s1,
|
||||
u256(data[i].s4.size()),
|
||||
|
||||
@@ -149,7 +149,7 @@ bytes compileFirstExpression(
|
||||
for (vector<string> const& variable: _localVariables)
|
||||
context.addVariable(
|
||||
dynamic_cast<VariableDeclaration const&>(resolveDeclaration(*sourceUnit, variable, resolver)),
|
||||
parametersSize--
|
||||
static_cast<unsigned>(parametersSize--)
|
||||
);
|
||||
|
||||
ExpressionCompiler(
|
||||
|
||||
@@ -495,7 +495,7 @@ BOOST_AUTO_TEST_CASE(constant_optimization_early_exit)
|
||||
maxDuration = numeric_limits<size_t>::max();
|
||||
BOOST_TEST_MESSAGE("Disabled constant optimizer run time check for address sanitizer build.");
|
||||
#endif
|
||||
BOOST_CHECK_MESSAGE(duration <= maxDuration, "Compilation of constants took longer than 20 seconds.");
|
||||
BOOST_CHECK_MESSAGE(duration <= double(maxDuration), "Compilation of constants took longer than 20 seconds.");
|
||||
compareVersions("hexEncodeTest(address)", u256(0x123456789));
|
||||
}
|
||||
|
||||
|
||||
@@ -262,13 +262,6 @@ BOOST_AUTO_TEST_CASE(helper_bool_result)
|
||||
r5.merge(r6, logical_and<bool>());
|
||||
BOOST_REQUIRE_EQUAL(r5.get(), true);
|
||||
BOOST_REQUIRE_EQUAL(r5.message(), "");
|
||||
|
||||
BoolResult r7{true};
|
||||
// Attention: this will implicitly convert to bool.
|
||||
BoolResult r8("true"); // We cannot use {} initializer here because this does not allow narrowing conversion (at least MSVC breaks)
|
||||
r7.merge(r8, logical_and<bool>());
|
||||
BOOST_REQUIRE_EQUAL(r7.get(), true);
|
||||
BOOST_REQUIRE_EQUAL(r7.message(), "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(helper_string_result)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
contract A {
|
||||
constructor(uint) {}
|
||||
}
|
||||
contract B {
|
||||
constructor(uint) {}
|
||||
}
|
||||
contract C {
|
||||
constructor(uint) {}
|
||||
}
|
||||
contract D {
|
||||
constructor(uint) {}
|
||||
}
|
||||
contract X is D, C, B, A {
|
||||
uint[] x;
|
||||
function f(uint _x) internal returns (uint) {
|
||||
x.push(_x);
|
||||
}
|
||||
function g() public view returns (uint[] memory) { return x; }
|
||||
constructor() A(f(1)) C(f(2)) B(f(3)) D(f(4)) {}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// g() -> 0x20, 4, 1, 3, 2, 4
|
||||
@@ -264,13 +264,13 @@ string BytesUtils::formatBytes(
|
||||
{
|
||||
auto entropy = [](std::string const& str) -> double {
|
||||
double result = 0;
|
||||
map<char, int> frequencies;
|
||||
map<char, double> frequencies;
|
||||
for (char c: str)
|
||||
frequencies[c]++;
|
||||
for (auto p: frequencies)
|
||||
{
|
||||
double freq = static_cast<double>(p.second) / str.length();
|
||||
result -= freq * (log(freq) / log(2));
|
||||
double freq = p.second / double(str.length());
|
||||
result -= freq * (log(freq) / log(2.0));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -682,11 +682,12 @@ string TestFileParser::Scanner::scanString()
|
||||
return str;
|
||||
}
|
||||
|
||||
// TODO: use fromHex() from CommonData
|
||||
char TestFileParser::Scanner::scanHexPart()
|
||||
{
|
||||
advance(); // skip 'x'
|
||||
|
||||
char value{};
|
||||
int value{};
|
||||
if (isdigit(current()))
|
||||
value = current() - '0';
|
||||
else if (tolower(current()) >= 'a' && tolower(current()) <= 'f')
|
||||
@@ -696,7 +697,7 @@ char TestFileParser::Scanner::scanHexPart()
|
||||
|
||||
advance();
|
||||
if (current() == '"')
|
||||
return value;
|
||||
return static_cast<char>(value);
|
||||
|
||||
value <<= 4;
|
||||
if (isdigit(current()))
|
||||
@@ -706,5 +707,5 @@ char TestFileParser::Scanner::scanHexPart()
|
||||
|
||||
advance();
|
||||
|
||||
return value;
|
||||
return static_cast<char>(value);
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ string ProtoConverter::visit(TestFunction const& _x, string const& _storageVarDe
|
||||
("functionDeclReturndata", functionDeclReturndata)
|
||||
("storageVarDefs", _storageVarDefs)
|
||||
("localVarDefs", localVarDefs)
|
||||
("calldataTestCode", testCallDataFunction(_x.invalid_encoding_length()))
|
||||
("calldataTestCode", testCallDataFunction(static_cast<unsigned>(_x.invalid_encoding_length())))
|
||||
("returndataTestCode", testReturnDataFunction())
|
||||
("return_types", m_types.str())
|
||||
("return_values", m_argsCoder.str())
|
||||
|
||||
@@ -37,7 +37,7 @@ struct SolRandomNumGenerator
|
||||
/// @returns a pseudo random unsigned integer
|
||||
unsigned operator()()
|
||||
{
|
||||
return m_random();
|
||||
return static_cast<unsigned>(m_random());
|
||||
}
|
||||
|
||||
RandomEngine m_random;
|
||||
|
||||
@@ -182,9 +182,9 @@ bool ProtoConverter::functionCallNotPossible(FunctionCall_Returns _type)
|
||||
unsigned ProtoConverter::numVarsInScope()
|
||||
{
|
||||
if (m_inFunctionDef)
|
||||
return m_currentFuncVars.size();
|
||||
return static_cast<unsigned>(m_currentFuncVars.size());
|
||||
else
|
||||
return m_currentGlobalVars.size();
|
||||
return static_cast<unsigned>(m_currentGlobalVars.size());
|
||||
}
|
||||
|
||||
void ProtoConverter::visit(VarRef const& _x)
|
||||
@@ -1344,12 +1344,12 @@ void ProtoConverter::visit(UnaryOpData const& _x)
|
||||
{
|
||||
case UnaryOpData::SIZE:
|
||||
m_output << Whiskers(R"(datasize("<id>"))")
|
||||
("id", getObjectIdentifier(_x.identifier()))
|
||||
("id", getObjectIdentifier(static_cast<unsigned>(_x.identifier())))
|
||||
.render();
|
||||
break;
|
||||
case UnaryOpData::OFFSET:
|
||||
m_output << Whiskers(R"(dataoffset("<id>"))")
|
||||
("id", getObjectIdentifier(_x.identifier()))
|
||||
("id", getObjectIdentifier(static_cast<unsigned>(_x.identifier())))
|
||||
.render();
|
||||
break;
|
||||
}
|
||||
@@ -1473,7 +1473,7 @@ void ProtoConverter::openFunctionScope(vector<string> const& _funcParams)
|
||||
|
||||
void ProtoConverter::updateFunctionMaps(string const& _var)
|
||||
{
|
||||
unsigned erased = m_functionSigMap.erase(_var);
|
||||
size_t erased = m_functionSigMap.erase(_var);
|
||||
|
||||
for (auto const& i: m_functionDefMap)
|
||||
if (i.second == _var)
|
||||
@@ -1491,7 +1491,7 @@ void ProtoConverter::closeBlockScope()
|
||||
// out of scope from the global function map.
|
||||
for (auto const& f: m_scopeFuncs.back())
|
||||
{
|
||||
unsigned numFuncsRemoved = m_functions.size();
|
||||
size_t numFuncsRemoved = m_functions.size();
|
||||
m_functions.erase(remove(m_functions.begin(), m_functions.end(), f), m_functions.end());
|
||||
numFuncsRemoved -= m_functions.size();
|
||||
yulAssert(
|
||||
@@ -1908,7 +1908,7 @@ void ProtoConverter::buildObjectScopeTree(Object const& _x)
|
||||
void ProtoConverter::visit(Program const& _x)
|
||||
{
|
||||
// Initialize input size
|
||||
m_inputSize = _x.ByteSizeLong();
|
||||
m_inputSize = static_cast<unsigned>(_x.ByteSizeLong());
|
||||
|
||||
// Record EVM Version
|
||||
m_evmVersion = evmVersionMapping(_x.ver());
|
||||
|
||||
@@ -38,7 +38,7 @@ struct YulRandomNumGenerator
|
||||
|
||||
unsigned operator()()
|
||||
{
|
||||
return m_random();
|
||||
return static_cast<unsigned>(m_random());
|
||||
}
|
||||
|
||||
RandomEngine m_random;
|
||||
|
||||
@@ -40,7 +40,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
FuzzerUtil::testCompiler(sourceCode, /*optimize=*/false, /*_rand=*/_size);
|
||||
FuzzerUtil::testCompiler(sourceCode, /*optimize=*/false, /*_rand=*/static_cast<unsigned>(_size));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
FuzzerUtil::testCompiler(sourceCode, /*optimize=*/true, /*rand=*/_size);
|
||||
FuzzerUtil::testCompiler(sourceCode, /*optimize=*/true, /*rand=*/static_cast<unsigned>(_size));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -451,7 +451,8 @@ u256 EVMInstructionInterpreter::evalBuiltin(
|
||||
else
|
||||
{
|
||||
// Force different value than for datasize
|
||||
arg[31] += 2;
|
||||
arg[31]++;
|
||||
arg[31]++;
|
||||
return u256(keccak256(arg)) & 0xfff;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,9 @@ u256 EwasmBuiltinInterpreter::evalBuiltin(
|
||||
return u256(util::keccak256(arg)) & 0xfff;
|
||||
else if (fun == "dataoffset")
|
||||
{
|
||||
arg[31] += 2;
|
||||
// Force different value than for datasize
|
||||
arg[31]++;
|
||||
arg[31]++;
|
||||
return u256(util::keccak256(arg)) & 0xfff;
|
||||
}
|
||||
}
|
||||
@@ -198,7 +200,7 @@ u256 EwasmBuiltinInterpreter::evalBuiltin(
|
||||
else if (fun == "i32.store")
|
||||
{
|
||||
accessMemory(arg[0], 4);
|
||||
writeMemoryHalfWord(arg[0], arg[1]);
|
||||
writeMemoryHalfWord(arg[0], static_cast<uint32_t>(arg[1]));
|
||||
return 0;
|
||||
}
|
||||
else if (fun == "i32.load")
|
||||
@@ -453,7 +455,7 @@ u256 EwasmBuiltinInterpreter::evalEthBuiltin(string const& _fun, vector<uint64_t
|
||||
readBytes32(arg[5]);
|
||||
if (numberOfTopics > 3)
|
||||
readBytes32(arg[6]);
|
||||
logTrace(evmasm::logInstruction(numberOfTopics), {});
|
||||
logTrace(evmasm::logInstruction(static_cast<unsigned>(numberOfTopics)), {});
|
||||
return 0;
|
||||
}
|
||||
else if (_fun == "getBlockNumber")
|
||||
@@ -538,7 +540,7 @@ uint32_t EwasmBuiltinInterpreter::readMemoryHalfWord(uint64_t _offset)
|
||||
{
|
||||
uint32_t r = 0;
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
r |= uint64_t(m_state.memory[_offset + i]) << (i * 8);
|
||||
r |= uint32_t(m_state.memory[_offset + i]) << (i * 8);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ public:
|
||||
auto printPair = [&](auto const& optionAndDescription)
|
||||
{
|
||||
cout << optionAndDescription.first << ": ";
|
||||
cout << setw(longestDescriptionLength) << setiosflags(ios::left);
|
||||
cout << setw(static_cast<int>(longestDescriptionLength)) << setiosflags(ios::left);
|
||||
cout << optionAndDescription.second << " ";
|
||||
|
||||
++index;
|
||||
@@ -165,8 +165,9 @@ public:
|
||||
printUsageBanner(abbreviationMap, extraOptions, 4);
|
||||
cout << "? ";
|
||||
cout.flush();
|
||||
int option = readStandardInputChar();
|
||||
cout << ' ' << char(option) << endl;
|
||||
// TODO: handle EOF properly.
|
||||
char option = static_cast<char>(readStandardInputChar());
|
||||
cout << ' ' << option << endl;
|
||||
|
||||
OptimiserStepContext context{m_dialect, *m_nameDispenser, reservedIdentifiers};
|
||||
|
||||
|
||||
@@ -83,8 +83,8 @@ BOOST_AUTO_TEST_CASE(makeRandom_should_use_every_possible_step_with_the_same_pro
|
||||
for (auto& step: chromosome.optimisationSteps())
|
||||
samples.push_back(stepIndices.at(step));
|
||||
|
||||
const double expectedValue = (stepIndices.size() - 1) / 2.0;
|
||||
const double variance = (stepIndices.size() * stepIndices.size() - 1) / 12.0;
|
||||
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);
|
||||
@@ -157,8 +157,8 @@ BOOST_AUTO_TEST_CASE(randomOptimisationStep_should_return_each_step_with_same_pr
|
||||
for (size_t i = 0; i <= stepIndices.size() * samplesPerStep; ++i)
|
||||
samples.push_back(stepIndices.at(Chromosome::randomOptimisationStep()));
|
||||
|
||||
const double expectedValue = (stepIndices.size() - 1) / 2.0;
|
||||
const double variance = (stepIndices.size() * stepIndices.size() - 1) / 12.0;
|
||||
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);
|
||||
|
||||
@@ -183,7 +183,7 @@ BOOST_FIXTURE_TEST_CASE(evaluate_should_compute_the_size_ratio_between_optimised
|
||||
{
|
||||
BOOST_TEST(
|
||||
RelativeProgramSize(m_program, nullptr, 3, m_weights).evaluate(m_chromosome) ==
|
||||
round(1000.0 * m_optimisedProgram.codeSize(m_weights) / m_program.codeSize(m_weights))
|
||||
round(1000.0 * double(m_optimisedProgram.codeSize(m_weights)) / double(m_program.codeSize(m_weights)))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ BOOST_FIXTURE_TEST_CASE(evaluate_should_be_able_to_use_program_cache_if_availabl
|
||||
{
|
||||
BOOST_TEST(
|
||||
RelativeProgramSize(nullopt, m_programCache, 3, m_weights).evaluate(m_chromosome) ==
|
||||
round(1000.0 * m_optimisedProgram.codeSize(m_weights) / m_program.codeSize(m_weights))
|
||||
round(1000.0 * double(m_optimisedProgram.codeSize(m_weights)) / double(m_program.codeSize(m_weights)))
|
||||
);
|
||||
BOOST_TEST(m_programCache->size() == m_chromosome.length());
|
||||
}
|
||||
@@ -206,7 +206,7 @@ BOOST_FIXTURE_TEST_CASE(evaluate_should_repeat_the_optimisation_specified_number
|
||||
|
||||
BOOST_TEST(fitness != 1000);
|
||||
BOOST_TEST(fitness != RelativeProgramSize(programOptimisedTwice, nullptr, 3, m_weights, 1).evaluate(m_chromosome));
|
||||
BOOST_TEST(fitness == round(1000.0 * programOptimisedTwice.codeSize(m_weights) / m_program.codeSize(m_weights)));
|
||||
BOOST_TEST(fitness == round(1000.0 * double(programOptimisedTwice.codeSize(m_weights)) / double(m_program.codeSize(m_weights))));
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(evaluate_should_return_one_if_number_of_repetitions_is_zero, ProgramBasedMetricFixture)
|
||||
@@ -230,7 +230,7 @@ BOOST_FIXTURE_TEST_CASE(evaluate_should_return_one_if_the_original_program_size_
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(evaluate_should_multiply_the_result_by_scaling_factor, ProgramBasedMetricFixture)
|
||||
{
|
||||
double sizeRatio = static_cast<double>(m_optimisedProgram.codeSize(m_weights)) / m_program.codeSize(m_weights);
|
||||
double sizeRatio = double(m_optimisedProgram.codeSize(m_weights)) / double(m_program.codeSize(m_weights));
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 0, m_weights).evaluate(m_chromosome) == round(1.0 * sizeRatio));
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 1, m_weights).evaluate(m_chromosome) == round(10.0 * sizeRatio));
|
||||
BOOST_TEST(RelativeProgramSize(m_program, nullptr, 2, m_weights).evaluate(m_chromosome) == round(100.0 * sizeRatio));
|
||||
|
||||
@@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(geneRandomisation_should_iterate_over_genes_and_replace_the
|
||||
SimulationRNG::reset(1);
|
||||
for (size_t randomisationChancePercent = 20; randomisationChancePercent <= 100; randomisationChancePercent += 20)
|
||||
{
|
||||
double const randomisationChance = (randomisationChancePercent / 100.0);
|
||||
double const randomisationChance = double(randomisationChancePercent) / 100.0;
|
||||
|
||||
Chromosome output = geneRandomisation(randomisationChance)(input);
|
||||
string outputGenes = output.genes();
|
||||
@@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE(geneRandomisation_should_iterate_over_genes_and_replace_the
|
||||
|
||||
double const expectedValue = randomisationChance;
|
||||
double const variance = randomisationChance * (1 - randomisationChance);
|
||||
double const randomisedGeneCount = input.length() - static_cast<size_t>(count(outputGenes.begin(), outputGenes.end(), '.'));
|
||||
double const randomisedGeneCount = double(input.length() - static_cast<size_t>(count(outputGenes.begin(), outputGenes.end(), '.')));
|
||||
double const squaredError =
|
||||
(inputLength - randomisedGeneCount) * expectedValue * expectedValue +
|
||||
randomisedGeneCount * (1 - expectedValue) * (1 - expectedValue);
|
||||
@@ -91,7 +91,7 @@ BOOST_AUTO_TEST_CASE(geneDeletion_should_iterate_over_genes_and_delete_them_with
|
||||
SimulationRNG::reset(1);
|
||||
for (size_t deletionChancePercent = 20; deletionChancePercent < 100; deletionChancePercent += 20)
|
||||
{
|
||||
double const deletionChance = (deletionChancePercent / 100.0);
|
||||
double const deletionChance = double(deletionChancePercent) / 100.0;
|
||||
|
||||
Chromosome output = geneDeletion(deletionChance)(input);
|
||||
string outputGenes = output.genes();
|
||||
@@ -99,14 +99,14 @@ BOOST_AUTO_TEST_CASE(geneDeletion_should_iterate_over_genes_and_delete_them_with
|
||||
BOOST_REQUIRE(static_cast<size_t>(count(outputGenes.begin(), outputGenes.end(), '.')) == output.length());
|
||||
|
||||
double const expectedValue = deletionChance;
|
||||
double const variance = deletionChance * (1 - deletionChance);
|
||||
double const deletedGeneCount = input.length() - output.length();
|
||||
double const variance = deletionChance * (1.0 - deletionChance);
|
||||
double const deletedGeneCount = double(input.length() - output.length());
|
||||
double const squaredError =
|
||||
(inputLength - deletedGeneCount) * expectedValue * expectedValue +
|
||||
deletedGeneCount * (1 - expectedValue) * (1 - expectedValue);
|
||||
(double(inputLength) - deletedGeneCount) * expectedValue * expectedValue +
|
||||
deletedGeneCount * (1.0 - expectedValue) * (1.0 - expectedValue);
|
||||
|
||||
BOOST_TEST(abs(deletedGeneCount / inputLength - expectedValue) < tolerance);
|
||||
BOOST_TEST(abs(squaredError / inputLength - variance) < tolerance);
|
||||
BOOST_TEST(abs(deletedGeneCount / double(inputLength) - expectedValue) < tolerance);
|
||||
BOOST_TEST(abs(squaredError / double(inputLength) - variance) < tolerance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(geneAddition_should_iterate_over_gene_positions_and_insert_
|
||||
SimulationRNG::reset(1);
|
||||
for (size_t additionChancePercent = 20; additionChancePercent < 100; additionChancePercent += 20)
|
||||
{
|
||||
double const additionChance = (additionChancePercent / 100.0);
|
||||
double const additionChance = double(additionChancePercent) / 100.0;
|
||||
|
||||
Chromosome output = geneAddition(additionChance)(input);
|
||||
BOOST_REQUIRE(output.length() >= input.length());
|
||||
@@ -150,14 +150,14 @@ BOOST_AUTO_TEST_CASE(geneAddition_should_iterate_over_gene_positions_and_insert_
|
||||
BOOST_REQUIRE(preservedGeneCount == input.length());
|
||||
|
||||
double const expectedValue = additionChance;
|
||||
double const variance = additionChance * (1 - additionChance);
|
||||
double const addedGeneCount = (output.length() - preservedGeneCount);
|
||||
double const variance = additionChance * (1.0 - additionChance);
|
||||
double const addedGeneCount = double(output.length() - preservedGeneCount);
|
||||
double const squaredError =
|
||||
(maxAdditions - addedGeneCount) * expectedValue * expectedValue +
|
||||
addedGeneCount * (1 - expectedValue) * (1 - expectedValue);
|
||||
(double(maxAdditions) - addedGeneCount) * expectedValue * expectedValue +
|
||||
addedGeneCount * (1.0 - expectedValue) * (1.0 - expectedValue);
|
||||
|
||||
BOOST_TEST(abs(addedGeneCount / maxAdditions - expectedValue) < tolerance);
|
||||
BOOST_TEST(abs(squaredError / maxAdditions - variance) < tolerance);
|
||||
BOOST_TEST(abs(addedGeneCount / double(maxAdditions) - expectedValue) < tolerance);
|
||||
BOOST_TEST(abs(squaredError / double(maxAdditions) - variance) < tolerance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -194,8 +194,8 @@ BOOST_FIXTURE_TEST_CASE(makeRandom_should_return_population_with_random_chromoso
|
||||
for (auto& step: individual.chromosome.optimisationSteps())
|
||||
samples.push_back(stepIndices.at(step));
|
||||
|
||||
const double expectedValue = (stepIndices.size() - 1) / 2.0;
|
||||
const double variance = (stepIndices.size() * stepIndices.size() - 1) / 12.0;
|
||||
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);
|
||||
|
||||
@@ -218,7 +218,7 @@ BOOST_AUTO_TEST_CASE(materialise_should_return_random_values_with_equal_probabil
|
||||
|
||||
vector<double> bernoulliTrials(collectionSize);
|
||||
for (size_t i = 0; i < collectionSize; ++i)
|
||||
bernoulliTrials[i] = indices.count(i);
|
||||
bernoulliTrials[i] = double(indices.count(i));
|
||||
|
||||
BOOST_TEST(abs(mean(bernoulliTrials) - expectedValue) < expectedValue * relativeTolerance);
|
||||
BOOST_TEST(abs(meanSquaredError(bernoulliTrials, expectedValue) - variance) < variance * relativeTolerance);
|
||||
|
||||
@@ -95,7 +95,7 @@ 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<uint32_t> samples;
|
||||
vector<size_t> samples;
|
||||
for (uint32_t i = 0; i < numSamples; ++i)
|
||||
samples.push_back(SimulationRNG::uniformInt(minValue, maxValue));
|
||||
|
||||
@@ -110,21 +110,21 @@ BOOST_AUTO_TEST_CASE(uniformInt_can_be_reset)
|
||||
constexpr uint32_t maxValue = 80;
|
||||
|
||||
SimulationRNG::reset(1);
|
||||
vector<uint32_t> samples1;
|
||||
vector<size_t> samples1;
|
||||
for (uint32_t i = 0; i < numSamples; ++i)
|
||||
samples1.push_back(SimulationRNG::uniformInt(minValue, maxValue));
|
||||
|
||||
vector<uint32_t> samples2;
|
||||
vector<size_t> samples2;
|
||||
for (uint32_t i = 0; i < numSamples; ++i)
|
||||
samples2.push_back(SimulationRNG::uniformInt(minValue, maxValue));
|
||||
|
||||
SimulationRNG::reset(1);
|
||||
vector<uint32_t> samples3;
|
||||
vector<size_t> samples3;
|
||||
for (uint32_t i = 0; i < numSamples; ++i)
|
||||
samples3.push_back(SimulationRNG::uniformInt(minValue, maxValue));
|
||||
|
||||
SimulationRNG::reset(2);
|
||||
vector<uint32_t> samples4;
|
||||
vector<size_t> samples4;
|
||||
for (uint32_t i = 0; i < numSamples; ++i)
|
||||
samples4.push_back(SimulationRNG::uniformInt(minValue, maxValue));
|
||||
|
||||
@@ -148,7 +148,7 @@ 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<uint32_t> samples;
|
||||
vector<size_t> samples;
|
||||
for (uint32_t i = 0; i < numSamples; ++i)
|
||||
samples.push_back(SimulationRNG::binomialInt(numTrials, successProbability));
|
||||
|
||||
@@ -163,21 +163,21 @@ BOOST_AUTO_TEST_CASE(binomialInt_can_be_reset)
|
||||
constexpr double successProbability = 0.6;
|
||||
|
||||
SimulationRNG::reset(1);
|
||||
vector<uint32_t> samples1;
|
||||
vector<size_t> samples1;
|
||||
for (uint32_t i = 0; i < numSamples; ++i)
|
||||
samples1.push_back(SimulationRNG::binomialInt(numTrials, successProbability));
|
||||
|
||||
vector<uint32_t> samples2;
|
||||
vector<size_t> samples2;
|
||||
for (uint32_t i = 0; i < numSamples; ++i)
|
||||
samples2.push_back(SimulationRNG::binomialInt(numTrials, successProbability));
|
||||
|
||||
SimulationRNG::reset(1);
|
||||
vector<uint32_t> samples3;
|
||||
vector<size_t> samples3;
|
||||
for (uint32_t i = 0; i < numSamples; ++i)
|
||||
samples3.push_back(SimulationRNG::binomialInt(numTrials, successProbability));
|
||||
|
||||
SimulationRNG::reset(2);
|
||||
vector<uint32_t> samples4;
|
||||
vector<size_t> samples4;
|
||||
for (uint32_t i = 0; i < numSamples; ++i)
|
||||
samples4.push_back(SimulationRNG::binomialInt(numTrials, successProbability));
|
||||
|
||||
|
||||
@@ -158,9 +158,9 @@ double mean(std::vector<T> const& _samples)
|
||||
|
||||
double sum = 0;
|
||||
for (T const& sample: _samples)
|
||||
sum += static_cast<double>(sample);
|
||||
sum += double(sample);
|
||||
|
||||
return sum / _samples.size();
|
||||
return sum / double(_samples.size());
|
||||
}
|
||||
|
||||
/// Calculates the sum of squared differences between @a _expectedValue and the values of a series
|
||||
@@ -179,9 +179,9 @@ double meanSquaredError(std::vector<T> const& _samples, double _expectedValue)
|
||||
|
||||
double sumOfSquaredDifferences = 0;
|
||||
for (T const& sample: _samples)
|
||||
sumOfSquaredDifferences += (sample - _expectedValue) * (sample - _expectedValue);
|
||||
sumOfSquaredDifferences += (double(sample) - _expectedValue) * (double(sample) - _expectedValue);
|
||||
|
||||
return sumOfSquaredDifferences / _samples.size();
|
||||
return sumOfSquaredDifferences / double(_samples.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user