All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
isValidLibraryData_test.cc
Go to the documentation of this file.
1 /**
2  * @file isValidLibraryData_test.cc
3  * @brief Unit test for `phot::isValidLibraryData()`.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date March 29, 2019
6  * @see `larsim/PhotonPropagation/LibraryMappingTools/OpDetVisibilityData.h`
7  */
8 
9 // Boost libraries
10 #define BOOST_TEST_MODULE ( isValidLibraryData_test )
11 #include "boost/test/unit_test.hpp"
12 
13 // LArSoft libraries
15 
16 // C/C++ standard libraries
17 #include <array>
18 #include <vector>
19 #include <memory> // std::unique_ptr<>
20 
21 //------------------------------------------------------------------------------
23  protected:
24  std::size_t fSize = 0U;
25 
26  public:
27  SizedContainer(std::size_t size = 0U): fSize(size) {}
28 
29 }; // SizedContainer
30 
33 
34  std::size_t size() const { return fSize; }
35 
36 }; // ContainerWith_size
37 
40 
41  bool empty() const { return fSize == 0U; }
42 
43 }; // ContainerWith_empty
44 
47 
48  bool isValid() const { return fSize > 0U; }
49 
50 }; // ContainerWith_isValid
51 
54 
55  bool is_valid() const { return fSize > 0U; }
56 
57 }; // ContainerWith_is_valid
58 
59 
60 //------------------------------------------------------------------------------
62 
63  std::vector<float> valid_vector(4U, 1.0);
64  std::vector<float> invalid_vector;
65 
66  std::array<float, 4U> valid_STLarray;
67  // all STL arrays are valid to us
68 
69  float valid_array[4U] = { 1.0, 2.0, 3.0, 4.0 };
70  // all C arrays are valid to us
71 
72  float const* valid_cptr = valid_array;
73  float const* invalid_cptr = nullptr;
74 
75  float const* const valid_cptrc = valid_array;
76  float const* const invalid_cptrc = nullptr;
77 
78  std::unique_ptr<float> valid_uptr { new float[4U] };
79  std::unique_ptr<float> invalid_uptr;
80 
81  ContainerWith_size valid_with_size { 4U };
82  ContainerWith_size invalid_with_size ;
83 
84  ContainerWith_empty valid_with_empty { 4U };
85  ContainerWith_empty invalid_with_empty ;
86 
87  ContainerWith_is_valid valid_with_is_valid{ 4U };
88  ContainerWith_is_valid invalid_with_is_valid;
89 
90  ContainerWith_isValid valid_with_isValid { 4U };
91  ContainerWith_isValid invalid_with_isValid ;
92 
93  BOOST_TEST( phot::isValidLibraryData( valid_vector));
94  BOOST_TEST(!phot::isValidLibraryData(invalid_vector));
95 
96  BOOST_TEST( phot::isValidLibraryData( valid_STLarray));
97 
98  BOOST_TEST( phot::isValidLibraryData( valid_array));
99 
100  BOOST_TEST( phot::isValidLibraryData( valid_cptr));
101  BOOST_TEST(!phot::isValidLibraryData(invalid_cptr));
102 
103  BOOST_TEST( phot::isValidLibraryData( valid_cptrc));
104  BOOST_TEST(!phot::isValidLibraryData(invalid_cptrc));
105 
106  BOOST_TEST( phot::isValidLibraryData( valid_uptr));
107  BOOST_TEST(!phot::isValidLibraryData(invalid_uptr));
108 
109  BOOST_TEST( phot::isValidLibraryData( valid_with_size ));
110  BOOST_TEST(!phot::isValidLibraryData(invalid_with_size ));
111 
112  BOOST_TEST( phot::isValidLibraryData( valid_with_empty ));
113  BOOST_TEST(!phot::isValidLibraryData(invalid_with_empty ));
114 
115  BOOST_TEST( phot::isValidLibraryData( valid_with_is_valid));
116  BOOST_TEST(!phot::isValidLibraryData(invalid_with_is_valid));
117 
118  BOOST_TEST( phot::isValidLibraryData( valid_with_isValid ));
119  BOOST_TEST(!phot::isValidLibraryData(invalid_with_isValid ));
120 
121 } // isValidLibraryData_test()
122 
123 
124 //------------------------------------------------------------------------------
125 
126 BOOST_AUTO_TEST_CASE(isValidLibraryData_TestCase) {
128 } // BOOST_AUTO_TEST_CASE(isValidLibraryData_TestCase)
129 
130 //------------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(AllTests)
Data container for use with photon visibility libraries.
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
void isValidLibraryData_test()
std::size_t size() const
SizedContainer(std::size_t size=0U)
bool isValidLibraryData(Cont &&cont)
Returns the validity of content of library data in the container.