Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-18 07:37:09

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 "ActsPlugins/Root/TGeoAxes.hpp"
0012 
0013 #include <stdexcept>
0014 #include <string_view>
0015 
0016 using ActsPlugins::TGeoAxes;
0017 
0018 // Compile-time construction of valid axes — if these declarations compile,
0019 // the consteval validation accepted them.
0020 constexpr TGeoAxes kXYZ{"XYZ"};
0021 constexpr TGeoAxes kXZY{"XZY"};
0022 constexpr TGeoAxes kYXZ{"YXZ"};
0023 constexpr TGeoAxes kYZX{"YZX"};
0024 constexpr TGeoAxes kZXY{"ZXY"};
0025 constexpr TGeoAxes kZYX{"ZYX"};
0026 // Lowercase (negative direction) variants
0027 constexpr TGeoAxes kxYZ{"xYZ"};
0028 constexpr TGeoAxes kXyZ{"XyZ"};
0029 constexpr TGeoAxes kXYz{"XYz"};
0030 constexpr TGeoAxes kxyz{"xyz"};
0031 constexpr TGeoAxes kXzY{"XzY"};
0032 
0033 // The following lines must NOT compile. Uncomment to verify:
0034 // repeated axis
0035 // constexpr TGeoAxes bad_repeated{"XXY"};
0036 // same axis, different case
0037 // constexpr TGeoAxes bad_repeated2{"xXY"};
0038 // invalid character
0039 // constexpr TGeoAxes bad_char{"ABZ"};
0040 // digit not allowed
0041 // constexpr TGeoAxes bad_char2{"X1Z"};
0042 // type error: const char[3] != const char[4]
0043 // constexpr TGeoAxes bad_short{"XY"};
0044 // type error: const char[5] != const char[4]
0045 // constexpr TGeoAxes bad_long{"XYZW"};
0046 
0047 namespace ActsTests {
0048 
0049 BOOST_AUTO_TEST_SUITE(RootSuite)
0050 
0051 BOOST_AUTO_TEST_CASE(CompileTime_ValidLiterals) {
0052   // Verify value() round-trips correctly for the module-level constexpr
0053   // objects.
0054   BOOST_CHECK_EQUAL(kXYZ.value(), "XYZ");
0055   BOOST_CHECK_EQUAL(kXZY.value(), "XZY");
0056   BOOST_CHECK_EQUAL(kYXZ.value(), "YXZ");
0057   BOOST_CHECK_EQUAL(kYZX.value(), "YZX");
0058   BOOST_CHECK_EQUAL(kZXY.value(), "ZXY");
0059   BOOST_CHECK_EQUAL(kZYX.value(), "ZYX");
0060 }
0061 
0062 BOOST_AUTO_TEST_CASE(CompileTime_CaseVariants) {
0063   // Lowercase letters (negative direction) are valid.
0064   BOOST_CHECK_EQUAL(kxYZ.value(), "xYZ");
0065   BOOST_CHECK_EQUAL(kXyZ.value(), "XyZ");
0066   BOOST_CHECK_EQUAL(kXYz.value(), "XYz");
0067   BOOST_CHECK_EQUAL(kxyz.value(), "xyz");
0068   BOOST_CHECK_EQUAL(kXzY.value(), "XzY");
0069 }
0070 
0071 BOOST_AUTO_TEST_CASE(Parse_Valid) {
0072   // All 6 axis orderings should parse successfully.
0073   BOOST_CHECK_EQUAL(TGeoAxes::parse("XYZ").value(), "XYZ");
0074   BOOST_CHECK_EQUAL(TGeoAxes::parse("XZY").value(), "XZY");
0075   BOOST_CHECK_EQUAL(TGeoAxes::parse("YXZ").value(), "YXZ");
0076   BOOST_CHECK_EQUAL(TGeoAxes::parse("YZX").value(), "YZX");
0077   BOOST_CHECK_EQUAL(TGeoAxes::parse("ZXY").value(), "ZXY");
0078   BOOST_CHECK_EQUAL(TGeoAxes::parse("ZYX").value(), "ZYX");
0079   // Mixed case
0080   BOOST_CHECK_EQUAL(TGeoAxes::parse("xYZ").value(), "xYZ");
0081   BOOST_CHECK_EQUAL(TGeoAxes::parse("XzY").value(), "XzY");
0082   BOOST_CHECK_EQUAL(TGeoAxes::parse("xyz").value(), "xyz");
0083 }
0084 
0085 BOOST_AUTO_TEST_CASE(Parse_WrongLength) {
0086   BOOST_CHECK_THROW(TGeoAxes::parse("XY"), std::invalid_argument);
0087   BOOST_CHECK_THROW(TGeoAxes::parse("XYZW"), std::invalid_argument);
0088   BOOST_CHECK_THROW(TGeoAxes::parse(""), std::invalid_argument);
0089   BOOST_CHECK_THROW(TGeoAxes::parse("X"), std::invalid_argument);
0090 }
0091 
0092 BOOST_AUTO_TEST_CASE(Parse_BadChars) {
0093   BOOST_CHECK_THROW(TGeoAxes::parse("ABZ"), std::invalid_argument);
0094   BOOST_CHECK_THROW(TGeoAxes::parse("X1Z"), std::invalid_argument);
0095   BOOST_CHECK_THROW(TGeoAxes::parse("XY "),
0096                     std::invalid_argument);  // trailing space
0097   BOOST_CHECK_THROW(TGeoAxes::parse("XYW"), std::invalid_argument);
0098 }
0099 
0100 BOOST_AUTO_TEST_CASE(Parse_RepeatedAxis) {
0101   // Same axis letter repeated
0102   BOOST_CHECK_THROW(TGeoAxes::parse("XXY"), std::invalid_argument);
0103   BOOST_CHECK_THROW(TGeoAxes::parse("XYY"), std::invalid_argument);
0104   BOOST_CHECK_THROW(TGeoAxes::parse("ZZX"), std::invalid_argument);
0105   // Same axis, different case (x and X are the same axis)
0106   BOOST_CHECK_THROW(TGeoAxes::parse("xXY"), std::invalid_argument);
0107   BOOST_CHECK_THROW(TGeoAxes::parse("XyY"), std::invalid_argument);
0108   BOOST_CHECK_THROW(TGeoAxes::parse("zZX"), std::invalid_argument);
0109 }
0110 
0111 BOOST_AUTO_TEST_SUITE_END()
0112 
0113 }  // namespace ActsTests