[yul-phaser] Common: Add enumerateOptimisationSteps()

This commit is contained in:
Kamil Śliwak 2020-02-14 19:37:43 +01:00
parent 957ca00588
commit 46d69d0941
3 changed files with 48 additions and 0 deletions

View File

@ -16,3 +16,19 @@
*/
#include <test/yulPhaser/Common.h>
#include <libyul/optimiser/Suite.h>
using namespace std;
using namespace solidity;
using namespace solidity::yul;
map<string, size_t> phaser::test::enumerateOptmisationSteps()
{
map<string, size_t> stepIndices;
size_t i = 0;
for (auto const& nameAndAbbreviation: OptimiserSuite::stepNameToAbbreviationMap())
stepIndices.insert({nameAndAbbreviation.first, i++});
return stepIndices;
}

View File

@ -29,11 +29,19 @@
#pragma once
#include <cassert>
#include <map>
#include <string>
#include <vector>
namespace solidity::phaser::test
{
// CHROMOSOME AND POPULATION HELPERS
/// 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.
std::map<std::string, size_t> enumerateOptmisationSteps();
// STATISTICAL UTILITIES
/// Calculates the mean value of a series of samples given in a vector.

View File

@ -17,8 +17,14 @@
#include <test/yulPhaser/Common.h>
#include <libyul/optimiser/Suite.h>
#include <boost/test/unit_test.hpp>
#include <set>
using namespace std;
using namespace solidity::yul;
using namespace boost::test_tools;
namespace solidity::phaser::test
@ -27,6 +33,24 @@ namespace solidity::phaser::test
BOOST_AUTO_TEST_SUITE(Phaser)
BOOST_AUTO_TEST_SUITE(CommonTest)
BOOST_AUTO_TEST_CASE(enumerateOptimisationSteps_should_assing_indices_to_all_available_optimisation_steps)
{
map<string, char> stepsAndAbbreviations = OptimiserSuite::stepNameToAbbreviationMap();
map<string, size_t> stepsAndIndices = enumerateOptmisationSteps();
BOOST_TEST(stepsAndIndices.size() == stepsAndAbbreviations.size());
set<string> stepsSoFar;
for (auto& [name, index]: stepsAndIndices)
{
BOOST_TEST(index >= 0);
BOOST_TEST(index <= stepsAndAbbreviations.size());
BOOST_TEST(stepsAndAbbreviations.count(name) == 1);
BOOST_TEST(stepsSoFar.count(name) == 0);
stepsSoFar.insert(name);
}
}
BOOST_AUTO_TEST_CASE(mean_should_calculate_statistical_mean)
{
BOOST_TEST(mean<int>({0}) == 0.0);