mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[yul-phaser] Chromosome: Make randomOptimisationStep() public
- And add tests now that it's public.
This commit is contained in:
parent
46d69d0941
commit
4ee9174454
@ -15,7 +15,10 @@
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <test/yulPhaser/Common.h>
|
||||
|
||||
#include <tools/yulPhaser/Chromosome.h>
|
||||
#include <tools/yulPhaser/Random.h>
|
||||
|
||||
#include <libyul/optimiser/BlockFlattener.h>
|
||||
#include <libyul/optimiser/StructuralSimplifier.h>
|
||||
@ -95,6 +98,24 @@ BOOST_AUTO_TEST_CASE(output_operator_should_create_concise_and_unambiguous_strin
|
||||
BOOST_TEST(toString(chromosome) == "flcCUnDvejsxIOoighTLMrmVatud");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(randomOptimisationStep_should_return_each_step_with_same_probability)
|
||||
{
|
||||
SimulationRNG::reset(1);
|
||||
constexpr int samplesPerStep = 100;
|
||||
constexpr double relativeTolerance = 0.01;
|
||||
|
||||
map<string, size_t> stepIndices = enumerateOptmisationSteps();
|
||||
vector<size_t> samples;
|
||||
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;
|
||||
|
||||
BOOST_TEST(abs(mean(samples) - expectedValue) < expectedValue * relativeTolerance);
|
||||
BOOST_TEST(abs(meanSquaredError(samples, expectedValue) - variance) < variance * relativeTolerance);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
@ -52,9 +52,10 @@ public:
|
||||
bool operator==(Chromosome const& _other) const { return m_optimisationSteps == _other.m_optimisationSteps; }
|
||||
bool operator!=(Chromosome const& _other) const { return !(*this == _other); }
|
||||
|
||||
static std::string const& randomOptimisationStep();
|
||||
|
||||
private:
|
||||
static std::vector<std::string> allStepNames();
|
||||
static std::string const& randomOptimisationStep();
|
||||
|
||||
std::vector<std::string> m_optimisationSteps;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user