Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:12

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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   // As all SurfaceBounds have the same streaming API only a one is
0031   // tested here, all others are tests are identical
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()