8#include <framework/dataobjects/EventMetaData.h>
9#include <framework/dataobjects/ProfileInfo.h>
10#include <framework/datastore/RelationArray.h>
11#include <framework/datastore/StoreArray.h>
13#include <gtest/gtest.h>
20 class RelationConsolidateTest :
public ::testing::Test {
28 evtData->registerInDataStore();
29 profileData->registerInDataStore();
30 evtData->registerRelationTo(*profileData);
33 for (
int i = 0; i < 10; ++i) {
35 profileData->appendNew();
39 relArray->add(0, 0, 1.0);
40 relArray->add(0, 1, 2.0);
41 relArray->add(0, 1, 3.0);
42 relArray->add(1, 0, 1.0);
43 relArray->add(1, 1, 2.0);
44 relArray->add(1, 2, 3.0);
48 void TearDown()
override
62 TEST_F(RelationConsolidateTest, RelationConsolidateDefault)
67 EXPECT_EQ(relation[0].getSize(), 2u);
68 EXPECT_EQ(relation[0].getWeight(0), 1.0);
69 EXPECT_EQ(relation[0].getWeight(1), 5.0);
70 EXPECT_EQ(relation[1].getSize(), 3u);
71 EXPECT_EQ(relation[1].getWeight(0), 1.0);
72 EXPECT_EQ(relation[1].getWeight(1), 2.0);
73 EXPECT_EQ(relation[1].getWeight(2), 3.0);
75 std::map<unsigned int, std::pair<unsigned int, bool> > replace;
76 replace[0] = std::make_pair(1,
true);
77 replace[2] = std::make_pair(3,
false);
81 EXPECT_EQ(relation[0].getSize(), 2u);
82 EXPECT_EQ(relation[0].getWeight(0), 9.0);
83 EXPECT_EQ(relation[0].getWeight(1), 3.0);
84 EXPECT_EQ(relation[0].getFromIndex(), 1u);
85 EXPECT_EQ(relation[0].getToIndex(0), 1u);
86 EXPECT_EQ(relation[0].getToIndex(1), 3u);
90 TEST_F(RelationConsolidateTest, RelationConsolidateZero)
93 std::map<unsigned int, std::pair<unsigned int, bool> > replace;
94 replace[0] = std::make_pair(1,
true);
95 replace[2] = std::make_pair(3,
false);
99 EXPECT_EQ(relation[0].getSize(), 2u);
100 EXPECT_EQ(relation[0].getWeight(0), 2.0);
101 EXPECT_EQ(relation[0].getWeight(1), 3.0);
102 EXPECT_EQ(relation[0].getFromIndex(), 1u);
103 EXPECT_EQ(relation[0].getToIndex(0), 1u);
104 EXPECT_EQ(relation[0].getToIndex(1), 3u);
107 std::map<unsigned int, std::pair<unsigned int, bool> > replace2;
108 replace2[3] = std::make_pair(2,
true);
112 EXPECT_EQ(relation[0].getSize(), 2u);
113 EXPECT_EQ(relation[0].getWeight(0), 2.0);
114 EXPECT_EQ(relation[0].getWeight(1), 0.0);
115 EXPECT_EQ(relation[0].getFromIndex(), 1u);
116 EXPECT_EQ(relation[0].getToIndex(0), 1u);
117 EXPECT_EQ(relation[0].getToIndex(1), 2u);
121 TEST_F(RelationConsolidateTest, RelationConsolidateNegative)
124 std::map<unsigned int, std::pair<unsigned int, bool> > replace;
125 replace[0] = std::make_pair(1,
true);
126 replace[2] = std::make_pair(3,
false);
130 EXPECT_EQ(relation[0].getSize(), 2u);
132 EXPECT_EQ(relation[0].getWeight(0), -5.0);
133 EXPECT_EQ(relation[0].getWeight(1), 3.0);
134 EXPECT_EQ(relation[0].getFromIndex(), 1u);
135 EXPECT_EQ(relation[0].getToIndex(0), 1u);
136 EXPECT_EQ(relation[0].getToIndex(1), 3u);
139 std::map<unsigned int, std::pair<unsigned int, bool> > replace2;
140 replace2[1] = std::make_pair(1,
true);
141 replace2[3] = std::make_pair(2,
true);
145 EXPECT_EQ(relation[0].getSize(), 2u);
146 EXPECT_EQ(relation[0].getWeight(0), -5.0);
147 EXPECT_EQ(relation[0].getWeight(1), -3.0);
148 EXPECT_EQ(relation[0].getFromIndex(), 1u);
149 EXPECT_EQ(relation[0].getToIndex(0), 1u);
150 EXPECT_EQ(relation[0].getToIndex(1), 2u);
154 TEST_F(RelationConsolidateTest, RelationConsolidateDelete)
157 std::map<unsigned int, std::pair<unsigned int, bool> > replace;
158 replace[0] = std::make_pair(1,
true);
159 replace[2] = std::make_pair(3,
false);
163 EXPECT_EQ(relation[0].getSize(), 2u);
164 EXPECT_EQ(relation[0].getWeight(0), 2.0);
165 EXPECT_EQ(relation[0].getWeight(1), 3.0);
166 EXPECT_EQ(relation[0].getFromIndex(), 1u);
167 EXPECT_EQ(relation[0].getToIndex(0), 1u);
168 EXPECT_EQ(relation[0].getToIndex(1), 3u);
171 std::map<unsigned int, std::pair<unsigned int, bool> > replace2;
172 replace2[3] = std::make_pair(3,
true);
176 EXPECT_EQ(relation[0].getSize(), 1u);
177 EXPECT_EQ(relation[0].getWeight(0), 2.0);
178 EXPECT_EQ(relation[0].getFromIndex(), 1u);
179 EXPECT_EQ(relation[0].getToIndex(0), 1u);
182 std::map<unsigned int, std::pair<unsigned int, bool> > replace3;
183 replace3[1] = std::make_pair(2,
true);
static DataStore & Instance()
Instance of singleton Store.
void setInitializeActive(bool active)
Setter for m_initializeActive.
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
Struct to replace indices based on a map-like container.
Low-level class to create/modify relations between StoreArrays.
void consolidate()
Consolidate Relation Elements.
@ c_negativeWeight
Flip the sign of the weight to become negative if the original element got re-attributed.
@ c_zeroWeight
Set the weight of the relation to 0 if the original element got re-attributed.
@ c_deleteElement
Delete the whole relation element if the original element got re-attributed.
int getEntries() const
Get the number of elements.
Accessor to arrays stored in the data store.
Abstract base class for different kinds of events.