29 #define BOOST_TEST_MODULE ( CountersMap_test )
30 #include "boost/test/unit_test.hpp"
59 constexpr
unsigned int NPoints = 1000;
60 constexpr
unsigned int NAngles = 10800;
61 constexpr
unsigned int NDist = 2500;
63 typedef std::map<int, int> BaseMap_t;
66 typedef std::vector<BaseMap_t> MapVectorI_t;
67 MapVectorI_t stl_image(NAngles);
70 std::vector<lar::CountersMap<int, int, 8>> cm_image(NAngles);
74 static std::default_random_engine random_engine(
RandomSeed);
75 std::uniform_real_distribution<float> uniform(-1., 1.);
77 for (
unsigned int iPoint = 0; iPoint != NPoints; ++iPoint) {
80 const float offset = uniform(random_engine) * NDist;
81 const float slope = uniform(random_engine);
83 for (
size_t iAngle = 0; iAngle < NAngles; ++iAngle) {
85 ++(stl_image[iAngle][int(d)]);
86 cm_image[iAngle].increment(
int(d));
89 while (d >= (
float) NDist) d -= 2*NDist;
90 while (d < 0) d += 2*NDist;
94 std::cout <<
"Filling complete, now checking." << std::endl;
98 unsigned int nExtraKeys = 0, nMismatchValue = 0, nMissingKeys = 0;
99 auto stl_begin = stl_image.cbegin();
100 unsigned int iMap = 0;
101 for (
const auto& cm_map: cm_image) {
103 const MapVectorI_t::value_type& stl_map = *(stl_begin++);
105 std::cout <<
"Map #" << iMap <<
" (" << cm_map.n_counters()
106 <<
" counters, " << stl_map.size() <<
" real)"
113 MapVectorI_t::value_type::const_iterator stl_iter = stl_map.begin(),
114 stl_end = stl_map.end();
115 for (
auto p: cm_map) {
117 if (stl_iter != stl_end) {
120 while (
p.first > stl_iter->first) {
122 std::cout <<
"ERROR missing key " << stl_iter->first << std::endl;
123 if (++stl_iter == stl_end)
break;
127 if (stl_iter != stl_end) {
128 if (
p.first == stl_iter->first) {
131 if (stl_iter->second !=
p.second) {
132 std::cout <<
"ERROR wrong counter value " <<
p.second
133 <<
", expected " << stl_iter->second << std::endl;
138 else if (
p.first < stl_iter->first) {
142 std::cout <<
"ERROR extra key " <<
p.first <<
" (" <<
p.second <<
")"
155 std::cout <<
"ERROR extra key " <<
p.first <<
" (" <<
p.second <<
")"
161 BOOST_TEST(cm_map.is_equal(stl_map));
164 const_cast<MapVectorI_t::value_type&
>(stl_map)[NDist / 2]++;
165 BOOST_TEST(!cm_map.is_equal(stl_map));
170 BOOST_TEST(nMismatchValue == 0U);
171 BOOST_TEST(nMissingKeys == 0U);
172 BOOST_TEST(nExtraKeys == 0U);
BEGIN_PROLOG TPC Trig offset(g4 rise time) ProjectToHeight
constexpr unsigned int RandomSeed
The seed for the default random engine.
void RunHoughTransformTreeTest()
Tests bulk allocator with a vector of maps (Hough transfort use case)
Map of counters, stored compactly.
BEGIN_PROLOG could also be cout