Unit test for NumericUtils functions.
More...
#include <boost/test/unit_test.hpp>
#include "larcorealg/CoreUtils/MetaUtils.h"
#include "larcorealg/CoreUtils/NumericUtils.h"
#include <limits>
#include <type_traits>
Go to the source code of this file.
Unit test for NumericUtils functions.
- Author
- Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
- Date
- March 30, 2018
- See Also
- NumericUtils.h
Definition in file NumericUtils_test.cc.
#define BOOST_TEST_MODULE ( NumericUtils_test ) |
BOOST_AUTO_TEST_CASE |
( |
absDiffTestCase |
| ) |
|
Definition at line 88 of file NumericUtils_test.cc.
90 BOOST_TEST_INFO(
"Testing <int,int>");
91 test_absDiff<int, int>();
92 test_constexpr_absDiff<int, int>();
94 BOOST_TEST_INFO(
"Testing <unsigned int,unsigned int>");
95 test_absDiff<unsigned int, unsigned int>();
96 test_constexpr_absDiff<unsigned int, unsigned int>();
template<typename A , typename B , typename D = A>
Definition at line 24 of file NumericUtils_test.cc.
26 static_assert(std::is_same<
27 decltype(std::declval<A>() - std::declval<B>()),
28 decltype(std::declval<B>() - std::declval<A>())
29 >(),
"Difference between types is asymmetric."
38 static_assert(std::is_same<decltype(absDeltaAB), decltype(absDeltaBA)>(),
39 "Results of |a-b| and |b-a| have different type!");
41 static_assert(std::is_same<decltype(absDeltaAB), D>(),
42 "Results of |a-b| has unexpected type!");
44 BOOST_TEST(absDeltaAB == D(1));
45 BOOST_TEST(absDeltaBA == D(1));
49 B
const m = std::numeric_limits<B>::max() - b;
54 BOOST_TEST(absDeltaAM > D(2*(a + b)));
55 BOOST_TEST(absDeltaMA > D(2*(a + b)));
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
constexpr auto absDiff(A const &a, B const &b)
Returns the absolute value of the difference between two values.
template<typename A , typename B , typename D = std::add_const_t<A>>
void test_constexpr_absDiff |
( |
| ) |
|
Definition at line 61 of file NumericUtils_test.cc.
63 static_assert(std::is_same<
64 decltype(std::declval<A>() - std::declval<B>()),
65 decltype(std::declval<B>() - std::declval<A>())
66 >(),
"Difference between types is asymmetric."
75 static_assert(std::is_same<decltype(absDeltaAB), decltype(absDeltaBA)>(),
76 "Results of |a-b| and |b-a| have different type!");
78 static_assert(std::is_same<decltype(absDeltaAB), D>(),
79 "Results of |a-b| has unexpected type!");
81 static_assert(absDeltaAB == 1,
"|5-6| != 1?!?");
82 static_assert(absDeltaBA == 1,
"|6-5| != 1?!?");
constexpr auto absDiff(A const &a, B const &b)
Returns the absolute value of the difference between two values.