11#include "gtest/gtest.h"
13#include <unordered_map>
14#include <unordered_set>
25 int GetStationId(uint16_t address)
const {
return (0xF0 & address) >> 4; }
83 template<
class Visitor>
86 kLooper.ForEachValue(
this, std::forward<Visitor>(visitor));
92 template<
class Visitor>
95 kLooper.ForEachValue(
this, std::forward<Visitor>(visitor));
101 template<
class Visitor>
104 kLooper.ForEachVariable(
this, std::forward<Visitor>(visitor));
110 template<
class Visitor>
113 kLooper.ForEachVariable(
this, std::forward<Visitor>(visitor));
127 template<
class Class>
130 if constexpr (std::is_same_v<Class, A>) {
133 else if constexpr (std::is_same_v<Class, B>) {
141 std::vector<uint16_t>
a;
142 std::vector<uint16_t>
b;
143 std::vector<uint16_t>
c;
153 if (var.has_value()) ++res;
163 c.
ForEachValue([number](
auto&& val) { val.SetProperty(number); });
170 c.
ForEachValue([&res](
const auto& val) { res +=
static_cast<int>(val.GetProperty()); });
181 using Value_t =
typename std::remove_const_t<std::remove_reference_t<
decltype(val)>>;
182 std::unordered_set<int> uniqueStationIds;
183 for (uint16_t address :
hits.GetHitsFor<Value_t>())
184 uniqueStationIds.insert(val.GetStationId(address));
185 nTotSt += uniqueStationIds.size();
192 .a = std::move(std::vector<uint16_t>{0x100, 0x200, 0x320, 0x110, 0x200, 0x300, 0x130, 0x220, 0x320}),
193 .b = std::move(std::vector<uint16_t>{0x051, 0x141, 0x491, 0x241, 0x551, 0x821, 0x131, 0x951, 0x241}),
194 .c = std::move(std::vector<uint16_t>{0x012, 0x022, 0x032, 0x032, 0x012, 0x012, 0x022, 0x012, 0x022})
199 .fB = std::move(
B(std::move(std::vector<int>({1, 1, 1, 1, 3, 3, 3, 3, 2, 2, 0, 0, 0, 0, 2, 2})))),
200 .fC = std::move(
C(std::move(std::unordered_map<uint16_t, int>({{0x12, 0}, {0x22, 0}, {0x32, 1}}))))};
205 .fC = std::move(
C(std::move(std::unordered_map<uint16_t, int>({{0x12, 0}, {0x22, 0}, {0x32, 1}}))))};
207TEST(_GTestStructLooper, StructLooper_FullyDefinedComposite_LoopOverVariables)
210 SCOPED_TRACE(
"StructLooper_FullyDefinedComposite_LoopOverVariables");
214TEST(_GTestStructLooper, StructLooper_FullyDefinedComposite_LoopOverValues_1)
217 SCOPED_TRACE(
"StructLooper_FullyDefinedComposite_LoopOverValues_1");
222TEST(_GTestStructLooper, StructLooper_FullyDefinedComposite_LoopOverValues_2)
225 SCOPED_TRACE(
"StructLooper_FullyDefinedComposite_LoopOverValues_2");
229TEST(_GTestStructLooper, StructLooper_PartiallyDefinedComposite_LoopOverVariables)
232 SCOPED_TRACE(
"StructLooper_PartiallyDefinedComposite_LoopOverVariables");
236TEST(_GTestStructLooper, StructLooper_PartiallyDefinedComposite_LoopOverValues_1)
239 SCOPED_TRACE(
"StructLooper_PartiallyDefinedComposite_LoopOverValues_1");
244TEST(_GTestStructLooper, StructLooper_PartiallyDefinedComposite_LoopOverValues_2)
247 SCOPED_TRACE(
"StructLooper_PartiallyDefinedComposite_LoopOverValues_2");
A generic looper over selected variables of a struct/class.
static vector< vector< QAHit > > hits
TEST(_GTestStructLooper, StructLooper_FullyDefinedComposite_LoopOverVariables)
int GetStationId(uint16_t address) const
Maps an address of A component to a station of component.
Property_t GetProperty() const
void SetProperty(Property_t property)
Property_t GetProperty() const
B(std::vector< int > &&stMap)
std::vector< int > fModuleStationMap
int GetStationId(uint16_t address) const
Maps an address of B component to a station of component.
void SetProperty(Property_t property)
std::unordered_map< uint16_t, int > fModuleStationMap
Property_t GetProperty() const
void SetProperty(Property_t property)
int GetStationId(uint16_t address) const
Maps an address of A component to a station of component.
C(std::unordered_map< uint16_t, int > &&stMap)
An utility, which allows to apply a callable to selected variables of a class in a loop.
An application for a Composite object.
static int GetPropertySum(const Composite &c)
Gets a sum of the properties of all non-null components.
static int GetNumberOfStationsWithHits(const Composite &c, const Hits &hits)
Counts number of stations, which have a hit with a given address.
static int GetNofNonNullopt(const Composite &c)
Calculates number of non-nullopt variables.
static void SetProperty(Composite &c, double number)
Sets a common number as a property.
A composite of optional A, B and C.
static constexpr auto kLooper
void ForEachValue(Visitor &&visitor) const
A for-each method, which is applied to each VARIABLE.
void ForEachVariable(Visitor &&visitor)
A for-each method, which is applied to a VALUE stored in each variable.
void ForEachVariable(Visitor &&visitor) const
A for-each method, which is applied to a VALUE stored in each variable.
void ForEachValue(Visitor &&visitor)
A for-each method, which is applied to each VARIABLE.
A class, which emulates hit containers for different components.
std::vector< uint16_t > a
std::vector< uint16_t > c
const auto & GetHitsFor() const
std::vector< uint16_t > b