9 #include <boost/test/unit_test.hpp>
36 friend constexpr
bool operator==(
const Thing& lhs,
const Thing& rhs) {
37 return (lhs.x == rhs.x) and (lhs.y == rhs.y);
45 j =
json{{
"x", t.x}, {
"y", t.y}};
53 std::ostream&
operator<<(std::ostream& os,
const Thing& t) {
64 BOOST_TEST_DONT_PRINT_LOG_VALUE(Container::Iterator)
66 BOOST_AUTO_TEST_SUITE(GeometryHierarchyMapJsonConverter)
72 {
makeId(4, 5, 6), {7.25, -8}},
78 auto header = j.
find(
"acts-geometry-hierarchy-map");
79 BOOST_CHECK_NE(header, j.
end());
80 BOOST_CHECK(header->is_object());
81 BOOST_CHECK(header->at(
"format-version").is_number_integer());
82 BOOST_CHECK_EQUAL(header->at(
"format-version").get<
int>(), 0);
83 BOOST_CHECK(header->at(
"value-identifier").is_string());
84 BOOST_CHECK_EQUAL(header->at(
"value-identifier").get<std::string>(),
"thing");
86 auto entries = j.
find(
"entries");
87 BOOST_CHECK_NE(entries, j.
end());
88 BOOST_CHECK(entries->is_array());
89 BOOST_CHECK_EQUAL(entries->size(), 3
u);
95 "acts-geometry-hierarchy-map",
97 {
"format-version", 0},
98 {
"value-identifier",
"thing"},
107 {
"value", {{
"x", 4.0}, {
"y", 4}}},
113 {
"value", {{
"x", 3.0}, {
"y", 3}}},
120 BOOST_CHECK(not c.empty());
121 BOOST_CHECK_EQUAL(c.size(), 2);
124 BOOST_CHECK_NE(
it, c.end());
125 BOOST_CHECK_EQUAL(
it->x, 4.0);
126 BOOST_CHECK_EQUAL(
it->y, 4);
130 BOOST_CHECK_NE(
it, c.end());
131 BOOST_CHECK_EQUAL(
it->x, 3.0);
132 BOOST_CHECK_EQUAL(
it->y, 3);
140 BOOST_CHECK_THROW(
Converter(
"an-identifier").fromJson(j),
141 std::invalid_argument);
147 "acts-geometry-hierarchy-map",
149 {
"format-version", -1},
150 {
"value-identifier",
"an-identifier"},
155 BOOST_CHECK_THROW(
Converter(
"an-identifier").fromJson(j),
156 std::invalid_argument);
162 "acts-geometry-hierarchy-map",
164 {
"format-version", 0},
165 {
"value-identifier",
"an-identifier"},
170 BOOST_CHECK_THROW(
Converter(
"not-the-identifier").fromJson(j),
171 std::invalid_argument);
177 "acts-geometry-hierarchy-map",
179 {
"format-version", 0},
180 {
"value-identifier",
"an-identifier"},
184 BOOST_CHECK_THROW(
Converter(
"an-identifier").fromJson(j),
185 std::invalid_argument);
191 {
makeId(2, 3), {-4.5, 5}},
192 {
makeId(4, 5, 6), {7.25, -8}},
194 auto j =
Converter(
"the-identifier").toJson(c0);
197 BOOST_CHECK_EQUAL(c0.size(),
c1.size());
198 for (
auto i =
std::min(c0.size(),
c1.size()); 0 < i--;) {
199 BOOST_CHECK_EQUAL(c0.idAt(i),
c1.idAt(i));
200 BOOST_CHECK_EQUAL(c0.valueAt(i),
c1.valueAt(i));
208 BOOST_CHECK(
file.good());
211 BOOST_CHECK(
file.good());
215 BOOST_CHECK(not c.empty());
216 BOOST_CHECK_EQUAL(c.size(), 4);
217 BOOST_CHECK_NE(c.find(
makeId()), c.end());
218 BOOST_CHECK_NE(c.find(
makeId(1, 2)), c.end());
219 BOOST_CHECK_NE(c.find(
makeId(3)), c.end());
220 BOOST_CHECK_NE(c.find(
makeId(3, 4)), c.end());
223 BOOST_AUTO_TEST_SUITE_END()