Line data Source code
1 : // *****************************************************************************
2 : /*!
3 : \file src/UnitTest/TUTUtil.hpp
4 : \copyright 2012-2015 J. Bakosi,
5 : 2016-2018 Los Alamos National Security, LLC.,
6 : 2019-2021 Triad National Security, LLC.,
7 : 2022-2025 J. Bakosi
8 : All rights reserved. See the LICENSE file for details.
9 : \brief Utilities for unit testing with the Template Unit Test library
10 : \details Utilities for unit testing with the Template Unit Test library.
11 : */
12 : // *****************************************************************************
13 : #ifndef TUTUtil_h
14 : #define TUTUtil_h
15 :
16 : #include <limits>
17 : #include <algorithm>
18 :
19 : #include "NoWarning/tut.hpp"
20 :
21 : namespace unittest {
22 :
23 : #if defined(STRICT_GNUC)
24 : #pragma GCC diagnostic push
25 : #pragma GCC diagnostic ignored "-Wunused-result"
26 : #endif
27 :
28 : //! \brief Ensure equality of all element of a vector of Ts (e.g., floating
29 : //! point numbers) up to some precision
30 : //! \param[in] msg Message to output if the vectors are not equal
31 : //! \param[in] a First vector to compare
32 : //! \param[in] b Second vector to compare
33 : //! \param[in] prec Optional precision
34 : template< typename T >
35 247 : void veceq( const std::string& msg,
36 : const std::vector< T >& a,
37 : const std::vector< T >& b,
38 : tk::real prec = std::numeric_limits< T >::epsilon() )
39 : {
40 247 : std::equal( a.cbegin(), a.cend(), b.cbegin(),
41 2203 : [ &msg, &prec ]( T s, T d )
42 2203 : { tut::ensure_equals( msg, s, d, prec ); return true; } );
43 247 : }
44 :
45 : //! \brief Ensure equality of all element of a array of Ts (e.g., floating
46 : //! point numbers) up to some precision
47 : //! \param[in] msg Message to output if the arrays are not equal
48 : //! \param[in] a First array to compare
49 : //! \param[in] b Second array to compare
50 : //! \param[in] prec Optional precision
51 : template< typename T, std::size_t N >
52 4 : void veceq( const std::string& msg,
53 : const std::array< T, N >& a,
54 : const std::array< T, N >& b,
55 : tk::real prec = std::numeric_limits< T >::epsilon() )
56 : {
57 4 : std::equal( a.cbegin(), a.cend(), b.cbegin(),
58 16 : [ &msg, &prec ]( T s, T d )
59 16 : { tut::ensure_equals( msg, s, d, prec ); return true; } );
60 4 : }
61 :
62 : #if defined(STRICT_GNUC)
63 : #pragma GCC diagnostic pop
64 : #endif
65 :
66 : } // unittest::
67 :
68 : #endif // TUTUtil_h
|