File indexing completed on 2025-08-06 08:11:23
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Material/MaterialComposition.hpp"
0012 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0013
0014 #include <vector>
0015
0016 namespace Acts {
0017 namespace Test {
0018
0019 BOOST_AUTO_TEST_SUITE(material_composition)
0020
0021 constexpr float eps = 1.0f / 255u;
0022
0023 BOOST_AUTO_TEST_CASE(construct_element_fraction) {
0024
0025 unsigned int carbonZ = 12u;
0026
0027 unsigned int carbonWeight = 46u;
0028 float carbonFraction = float(carbonWeight) / 255u;
0029
0030 ElementFraction a(carbonZ, carbonFraction);
0031 BOOST_CHECK_EQUAL(a.element(), carbonZ);
0032 CHECK_CLOSE_REL(a.fraction(), carbonFraction, eps);
0033
0034 ElementFraction b(carbonZ, carbonWeight);
0035 BOOST_CHECK_EQUAL(b.element(), carbonZ);
0036 CHECK_CLOSE_REL(b.fraction(), carbonFraction, eps);
0037 }
0038
0039 BOOST_AUTO_TEST_CASE(construct_with_fractions) {
0040 ElementFraction carbon(12u, 0.45f);
0041 ElementFraction silicon(14u, 0.125f);
0042 ElementFraction titanium(22u, 0.25f);
0043 ElementFraction copper(29u, 0.175f);
0044
0045 MaterialComposition compound({silicon, carbon, titanium, copper});
0046 BOOST_CHECK(!!compound);
0047 BOOST_CHECK_EQUAL(compound.size(), 4u);
0048
0049 float totalFraction = 0.0f;
0050 for (const auto& eFraction : compound) {
0051 totalFraction += eFraction.fraction();
0052 }
0053
0054 CHECK_CLOSE_REL(totalFraction, 1.0f, compound.size() * eps);
0055
0056
0057 MaterialComposition shuffled({carbon, silicon, titanium, copper});
0058
0059 BOOST_CHECK_EQUAL(compound.size(), shuffled.size());
0060 BOOST_CHECK_EQUAL(compound, shuffled);
0061 }
0062
0063 BOOST_AUTO_TEST_CASE(construct_with_weights) {
0064 ElementFraction carbon(12u, 128u);
0065 ElementFraction silicon(14u, 64u);
0066 ElementFraction titanium(22u, 32u);
0067 ElementFraction copper(29u, 31u);
0068
0069 MaterialComposition compound({silicon, carbon, titanium, copper});
0070 BOOST_CHECK(!!compound);
0071 BOOST_CHECK_EQUAL(compound.size(), 4u);
0072
0073 float totalFraction = 0.0f;
0074 for (const auto& eFraction : compound) {
0075 totalFraction += eFraction.fraction();
0076 }
0077
0078 CHECK_CLOSE_REL(totalFraction, 1.0f, compound.size() * eps);
0079 }
0080
0081 BOOST_AUTO_TEST_SUITE_END()
0082
0083 }
0084 }