File indexing completed on 2025-01-18 09:13:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Plugins/Json/SurfaceBoundsJsonConverter.hpp"
0013 #include "Acts/Surfaces/RectangleBounds.hpp"
0014
0015 #include <algorithm>
0016 #include <fstream>
0017 #include <memory>
0018 #include <string>
0019 #include <vector>
0020
0021 #include <nlohmann/json.hpp>
0022
0023 using namespace Acts;
0024
0025 BOOST_AUTO_TEST_SUITE(SurfaceBoundsJsonConversion)
0026
0027 BOOST_AUTO_TEST_CASE(SurfaceBoundsRoundTripTests) {
0028 std::ofstream out;
0029
0030
0031
0032
0033 auto rectangeRef = std::make_shared<const RectangleBounds>(4., 6.);
0034 nlohmann::json rectangleOut =
0035 SurfaceBoundsJsonConverter::toJson(*rectangeRef);
0036 out.open("RectangleBounds.json");
0037 out << rectangleOut.dump(2);
0038 out.close();
0039
0040 auto in = std::ifstream("RectangleBounds.json",
0041 std::ifstream::in | std::ifstream::binary);
0042 BOOST_CHECK(in.good());
0043 nlohmann::json rectangleIn;
0044 in >> rectangleIn;
0045 in.close();
0046
0047 auto rectangleTest =
0048 SurfaceBoundsJsonConverter::fromJson<RectangleBounds>(rectangleIn);
0049
0050 BOOST_CHECK(rectangeRef->values() == rectangleTest->values());
0051 }
0052
0053 BOOST_AUTO_TEST_CASE(SurfaceBoundsDetrayConversion) {
0054 auto rectangeRef = std::make_shared<const RectangleBounds>(4., 6.);
0055 nlohmann::json rectangleOutDetray =
0056 SurfaceBoundsJsonConverter::toJsonDetray(*rectangeRef);
0057
0058 std::vector<double> boundariesRef = {4, 6};
0059 BOOST_CHECK_EQUAL(rectangleOutDetray["shape"].get<unsigned int>(), 5u);
0060 BOOST_CHECK(rectangleOutDetray["boundaries"].get<std::vector<double>>() ==
0061 boundariesRef);
0062 }
0063
0064 BOOST_AUTO_TEST_SUITE_END()