Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:22:23

0001 /**
0002  * TRACCC library, part of the ACTS project (R&D line)
0003  *
0004  * (c) 2021-2022 CERN for the benefit of the ACTS project
0005  *
0006  * Mozilla Public License Version 2.0
0007  */
0008 
0009 // Project include(s).
0010 #include "traccc/definitions/primitives.hpp"
0011 #include "traccc/geometry/module_map.hpp"
0012 #include "traccc/io/utils.hpp"
0013 
0014 // GTest include(s).
0015 #include <gtest/gtest.h>
0016 
0017 // System include(s).
0018 #include <map>
0019 #include <string>
0020 
0021 /*
0022  * Simple test of this map using integers and strings.
0023  */
0024 TEST(geometry, module_map_simple) {
0025   std::map<std::size_t, std::string> inp{{0, "zero"},    {1, "one"},
0026                                          {2, "two"},     {5, "five"},
0027                                          {11, "eleven"}, {21, "twenty-one"}};
0028 
0029   /*
0030    * Convert the old-style map to a module map.
0031    */
0032   traccc::module_map<std::size_t, std::string> map(inp);
0033 
0034   /*
0035    * Check whether the two maps are the same size!
0036    */
0037   ASSERT_EQ(map.size(), inp.size());
0038 
0039   ASSERT_EQ(map.at(0), "zero");
0040   ASSERT_EQ(map.at(1), "one");
0041   ASSERT_EQ(map.at(2), "two");
0042   ASSERT_EQ(map.at(5), "five");
0043   ASSERT_EQ(map.at(11), "eleven");
0044   ASSERT_EQ(map.at(21), "twenty-one");
0045 }
0046 
0047 /*
0048  * Ensure at and operator[] do the same thing.
0049  */
0050 TEST(geometry, module_map_operator_eq) {
0051   std::map<std::size_t, std::string> inp{{0, "zero"},    {1, "one"},
0052                                          {2, "two"},     {5, "five"},
0053                                          {11, "eleven"}, {21, "twenty-one"}};
0054 
0055   /*
0056    * Convert the old-style map to a module map.
0057    */
0058   traccc::module_map<std::size_t, std::string> map(inp);
0059 
0060   /*
0061    * Check if these are all the same.
0062    */
0063   ASSERT_EQ(map.at(0), map[0]);
0064   ASSERT_EQ(map.at(1), map[1]);
0065   ASSERT_EQ(map.at(2), map[2]);
0066   ASSERT_EQ(map.at(5), map[5]);
0067   ASSERT_EQ(map.at(11), map[11]);
0068   ASSERT_EQ(map.at(21), map[21]);
0069 }
0070 
0071 /*
0072  * Sanity check for the empty method.
0073  */
0074 TEST(geometry, module_map_empty) {
0075   std::map<std::size_t, std::string> inp{{0, "zero"},    {1, "one"},
0076                                          {2, "two"},     {5, "five"},
0077                                          {11, "eleven"}, {21, "twenty-one"}};
0078 
0079   /*
0080    * Convert the old-style map to a module map.
0081    */
0082   traccc::module_map<std::size_t, std::string> map(inp);
0083 
0084   ASSERT_FALSE(map.empty());
0085 }
0086 
0087 /*
0088  * Check whether the contains method works.
0089  */
0090 TEST(geometry, module_map_contains) {
0091   std::map<std::size_t, std::string> inp{{0, "zero"},    {1, "one"},
0092                                          {2, "two"},     {5, "five"},
0093                                          {11, "eleven"}, {21, "twenty-one"}};
0094 
0095   /*
0096    * Convert the old-style map to a module map.
0097    */
0098   traccc::module_map<std::size_t, std::string> map(inp);
0099 
0100   ASSERT_TRUE(map.contains(0));
0101   ASSERT_TRUE(map.contains(1));
0102   ASSERT_TRUE(map.contains(2));
0103   ASSERT_TRUE(map.contains(5));
0104   ASSERT_TRUE(map.contains(11));
0105   ASSERT_TRUE(map.contains(21));
0106   ASSERT_FALSE(map.contains(3));
0107   ASSERT_FALSE(map.contains(4));
0108   ASSERT_FALSE(map.contains(6));
0109   ASSERT_FALSE(map.contains(15));
0110   ASSERT_FALSE(map.contains(510482));
0111 }
0112 
0113 /*
0114  * Check if the map fails correctly.
0115  */
0116 TEST(geometry, module_map_failure) {
0117   std::map<std::size_t, std::string> inp{{0, "zero"}, {1, "one"}, {2, "two"}};
0118 
0119   /*
0120    * Convert the old-style map to a module map.
0121    */
0122   traccc::module_map<std::size_t, std::string> map(inp);
0123 
0124   /*
0125    * This value is not in the map, so it should throw.
0126    */
0127   ASSERT_THROW(map.at(100), std::out_of_range);
0128 }