File indexing completed on 2025-01-18 09:12:38
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Geometry/GeometryHierarchyMap.hpp"
0012 #include "Acts/Geometry/GeometryIdentifier.hpp"
0013
0014 #include <iterator>
0015 #include <stdexcept>
0016 #include <utility>
0017 #include <vector>
0018
0019 namespace {
0020
0021 using Acts::GeometryIdentifier;
0022
0023
0024 GeometryIdentifier makeId(int volume = 0, int layer = 0, int sensitive = 0) {
0025 return GeometryIdentifier().setVolume(volume).setLayer(layer).setSensitive(
0026 sensitive);
0027 }
0028
0029
0030 struct Thing {
0031 double value = 1.0;
0032 };
0033
0034 using Container = Acts::GeometryHierarchyMap<Thing>;
0035
0036 }
0037
0038
0039 #define CHECK_ENTRY(container, query, compare) \
0040 do { \
0041 auto ret = container.find(query); \
0042 BOOST_CHECK_NE(ret, container.end()); \
0043 if (ret != container.end()) { \
0044 auto idx = std::distance(container.begin(), ret); \
0045 BOOST_CHECK_EQUAL(container.idAt(idx), compare); \
0046 } \
0047 } while (false)
0048
0049 BOOST_TEST_DONT_PRINT_LOG_VALUE(Container::Iterator)
0050 BOOST_TEST_DONT_PRINT_LOG_VALUE(Thing)
0051
0052 BOOST_AUTO_TEST_SUITE(GeometryHierarchyMap)
0053
0054 BOOST_AUTO_TEST_CASE(ConstructDefault) {
0055 Container c;
0056 BOOST_CHECK_EQUAL(c.begin(), c.end());
0057 BOOST_CHECK(c.empty());
0058 BOOST_CHECK_EQUAL(c.size(), 0u);
0059 }
0060
0061 BOOST_AUTO_TEST_CASE(ConstructNonUnique) {
0062 std::vector<std::pair<GeometryIdentifier, Thing>> entries = {
0063 {makeId(2, 4, 6), {1.0}},
0064 {makeId(3, 5), {1.0}},
0065 {makeId(3), {1.0}},
0066
0067 {makeId(2, 4, 6), {2.0}},
0068 };
0069 BOOST_CHECK_THROW(Container(std::move(entries)), std::invalid_argument);
0070
0071 std::vector<std::pair<GeometryIdentifier, Thing>> defaults = {
0072 {makeId(), {1.0}},
0073
0074 {makeId(), {2.0}},
0075 };
0076 BOOST_CHECK_THROW(Container(std::move(defaults)), std::invalid_argument);
0077 }
0078
0079 BOOST_AUTO_TEST_CASE(ConstructInitializerList) {
0080 Container c = {
0081 {makeId(0, 1, 2), {1.0}},
0082 {makeId(3, 4), {3.0}},
0083 {makeId(2), {2.0}},
0084 {makeId(), {23.0}},
0085 };
0086 BOOST_CHECK_EQUAL(std::next(c.begin(), 4), c.end());
0087 BOOST_CHECK(!c.empty());
0088 BOOST_CHECK_EQUAL(c.size(), 4u);
0089
0090 CHECK_ENTRY(c, makeId(0, 1, 2), makeId(0, 1, 2));
0091 CHECK_ENTRY(c, makeId(2), makeId(2));
0092 CHECK_ENTRY(c, makeId(3, 4), makeId(3, 4));
0093 }
0094
0095 BOOST_AUTO_TEST_CASE(IndexBasedAccess) {
0096 Container c({
0097 {makeId(1, 2, 3), {2.0}},
0098 {makeId(3, 4, 5), {2.5}},
0099 {makeId(3, 5), {3.0}},
0100 {makeId(4, 5, 7), {4.0}},
0101 });
0102
0103 BOOST_CHECK(!c.empty());
0104 BOOST_CHECK_EQUAL(c.size(), 4u);
0105
0106
0107 for (auto i = c.size(); 0 < i--;) {
0108
0109 BOOST_CHECK_NE(c.idAt(i), GeometryIdentifier());
0110
0111 BOOST_CHECK_NE(c.valueAt(i).value, Thing().value);
0112 }
0113
0114 BOOST_CHECK_THROW(c.idAt(c.size()), std::out_of_range);
0115 BOOST_CHECK_THROW(c.valueAt(c.size()), std::out_of_range);
0116 }
0117
0118 BOOST_AUTO_TEST_CASE(Find) {
0119 Container c = {
0120
0121 {makeId(2, 4, 6), {-23.0}},
0122
0123 {makeId(2, 8), {5.0}},
0124
0125 {makeId(2), {1.0}},
0126
0127
0128 {makeId(12, 16), {-1.0}},
0129 };
0130
0131
0132 BOOST_CHECK_EQUAL(std::next(c.begin(), 4u), c.end());
0133 BOOST_CHECK(!c.empty());
0134 BOOST_CHECK_EQUAL(c.size(), 4u);
0135
0136
0137 CHECK_ENTRY(c, makeId(2, 4, 6), makeId(2, 4, 6));
0138
0139 CHECK_ENTRY(c, makeId(2, 8), makeId(2, 8));
0140
0141 CHECK_ENTRY(c, makeId(2), makeId(2));
0142
0143 CHECK_ENTRY(c, makeId(12, 16), makeId(12, 16));
0144
0145
0146 CHECK_ENTRY(c, makeId(2, 4, 7), makeId(2));
0147
0148 CHECK_ENTRY(c, makeId(2, 13), makeId(2));
0149
0150 CHECK_ENTRY(c, makeId(2, 8, 13), makeId(2, 8));
0151
0152 CHECK_ENTRY(c, makeId(12, 16, 20), makeId(12, 16));
0153
0154
0155 BOOST_CHECK_EQUAL(c.find(makeId(3, 5, 7)), c.end());
0156
0157 BOOST_CHECK_EQUAL(c.find(makeId(3, 5)), c.end());
0158
0159 BOOST_CHECK_EQUAL(c.find(makeId(3)), c.end());
0160
0161 BOOST_CHECK_EQUAL(c.find(makeId(12)), c.end());
0162 }
0163
0164 BOOST_AUTO_TEST_CASE(FindWithGlobalDefault) {
0165 Container c = {
0166
0167 {makeId(), {1.0}},
0168
0169 {makeId(2, 3), {2.0}},
0170
0171 {makeId(4), {4.0}},
0172 };
0173
0174
0175 BOOST_CHECK_EQUAL(std::next(c.begin(), 3u), c.end());
0176 BOOST_CHECK(!c.empty());
0177 BOOST_CHECK_EQUAL(c.size(), 3u);
0178
0179
0180 CHECK_ENTRY(c, makeId(), makeId());
0181 CHECK_ENTRY(c, makeId(2, 3), makeId(2, 3));
0182 CHECK_ENTRY(c, makeId(4), makeId(4));
0183
0184
0185 CHECK_ENTRY(c, makeId(2, 3, 4), makeId(2, 3));
0186
0187 CHECK_ENTRY(c, makeId(4, 5), makeId(4));
0188
0189
0190 CHECK_ENTRY(c, makeId(2, 4, 5), makeId());
0191
0192 CHECK_ENTRY(c, makeId(2, 4), makeId());
0193
0194 CHECK_ENTRY(c, makeId(5), makeId());
0195 }
0196
0197 BOOST_AUTO_TEST_SUITE_END()