Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:25:35

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/Surfaces/RectangleBounds.hpp"
0013 #include "ActsPlugins/Json/SurfaceBoundsJsonConverter.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 namespace ActsTests {
0026 
0027 BOOST_AUTO_TEST_SUITE(JsonSuite)
0028 
0029 BOOST_AUTO_TEST_CASE(SurfaceBoundsRoundTripTests) {
0030   std::ofstream out;
0031 
0032   // As all SurfaceBounds have the same streaming API only a one is
0033   // tested here, all others are tests are identical
0034 
0035   auto rectangeRef = std::make_shared<const RectangleBounds>(4., 6.);
0036   nlohmann::json rectangleOut =
0037       SurfaceBoundsJsonConverter::toJson(*rectangeRef);
0038   out.open("RectangleBounds.json");
0039   out << rectangleOut.dump(2);
0040   out.close();
0041 
0042   auto in = std::ifstream("RectangleBounds.json",
0043                           std::ifstream::in | std::ifstream::binary);
0044   BOOST_CHECK(in.good());
0045   nlohmann::json rectangleIn;
0046   in >> rectangleIn;
0047   in.close();
0048 
0049   auto rectangleTest =
0050       SurfaceBoundsJsonConverter::fromJson<RectangleBounds>(rectangleIn);
0051 
0052   BOOST_CHECK(rectangeRef->values() == rectangleTest->values());
0053 }
0054 
0055 BOOST_AUTO_TEST_CASE(SurfaceBoundsDetrayConversion) {
0056   auto rectangeRef = std::make_shared<const RectangleBounds>(4., 6.);
0057   nlohmann::json rectangleOutDetray =
0058       SurfaceBoundsJsonConverter::toJsonDetray(*rectangeRef);
0059 
0060   std::vector<double> boundariesRef = {4, 6};
0061   BOOST_CHECK_EQUAL(rectangleOutDetray["shape"].get<unsigned int>(), 5u);
0062   BOOST_CHECK(rectangleOutDetray["boundaries"].get<std::vector<double>>() ==
0063               boundariesRef);
0064 }
0065 
0066 BOOST_AUTO_TEST_SUITE_END()
0067 
0068 }  // namespace ActsTests