Celeritas 0.7-develop+ddcb429
Loading...
Searching...
No Matches
Public Member Functions | List of all members
celeritas::test::RefComparer< T > Class Template Reference

Compare selected container fields of two reference-result objects and accumulate whether all comparisons succeed. More...

#include <RefComparer.hh>

Public Member Functions

 RefComparer (AssertionHelper &helper, T const &expected, T const &actual)
 Create a comparer for two results and an assertion helper.
 
template<class M >
bool is_soft_eq (char const *attr, M T::*member)
 Compare a member container using the default soft comparator.
 
template<class M , class Tol >
bool is_soft_eq (char const *attr, M T::*member, Tol &&tol)
 Compare a member container using an explicit soft-comparison tolerance.
 
template<class M >
bool is_eq (char const *attr, M T::*member)
 Compare a member container using exact element equality.
 
void record_result (bool success)
 Add a custom comparison result to the aggregate status.
 
 operator bool () const
 Whether all comparisons made by this comparer succeeded.
 

Detailed Description

template<class T>
class celeritas::test::RefComparer< T >

Compare selected container fields of two reference-result objects and accumulate whether all comparisons succeed.

The comparer stores references to the assertion helper and the expected and actual objects. Each comparison method takes a pointer to a member of the result type; the attribute name is used to identify failures in the assertion output. Exact comparison checks container elements for equality, while soft comparison uses the default soft comparator or a caller-supplied tolerance. The result of each comparison is also added to the aggregate status, which can be queried with the explicit bool conversion.

Example

Typically CELER_INVOKE_ATTR is used to reduce duplication.

AssertionHelper helper{"expected", "actual"};
RefComparer<MyResult> compare{helper, expected, actual};
compare.is_eq("track_id", &MyResult::track_id);
CELER_INVOKE_TYPE_ATTR(compare.is_eq, MyResult, track_id);
CELER_INVOKE_TYPE_ATTR(compare.is_soft_eq, MyResult, position);
CELER_INVOKE_TYPE_ATTR_TOL(compare.is_soft_eq, MyResult, energy, 1e-5);
#define CELER_INVOKE_TYPE_ATTR(func, type, attr)
Invoke an attribute comparison with an optional tolerance.
Definition TestMacros.hh:73
Store and update an assertion result.
Definition AssertionHelper.hh:38
Compare selected container fields of two reference-result objects and accumulate whether all comparis...
Definition RefComparer.hh:43
bool is_eq(char const *attr, M T::*member)
Compare a member container using exact element equality.
Definition RefComparer.hh:77

The documentation for this class was generated from the following file: