TRIQS/nda 2.0.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
Testing tools

Detailed Description

Convenient tools for checking nda::basic_array and nda::basic_array_view objects with googletest.

Macros

#define EXPECT_ARRAY_EQ(X, Y)
 Macro that expects array_are_equal to return true.
#define EXPECT_ARRAY_NEAR(X, ...)
 Macro that expects array_are_close to return true.
#define EXPECT_ARRAY_REL_NEAR(X, ...)
 Macro that expects array_are_rel_close to return true.
#define EXPECT_ARRAY_ZERO(X)
 Macro that expects array_almost_zero to return true.
#define EXPECT_CLOSE(X, Y)
 Macro that expects generic_are_near to return true.
#define EXPECT_COMPLEX_NEAR(X, ...)
 Macro that expects complex_are_close to return true.
#define EXPECT_EQ_ARRAY(X, Y)
 Macro that expects array_are_equal to return true.

Functions

template<typename X>
::testing::AssertionResult array_almost_zero (X const &x)
 Check that an array/view is close to zero, i.e. that its largest absolute element is less than 1e-10.
template<typename X, typename Y>
::testing::AssertionResult array_are_close (X const &x, Y const &y, double precision=1.e-10)
 Check that two arrays/views are close, i.e. that they have the same shape and that the largest element of their absolute difference is less than a given precision.
template<typename X, typename Y>
::testing::AssertionResult array_are_equal (X const &x, Y const &y)
 Check that two arrays/views are equal, i.e. that they have the same shape and the same elements.
template<nda::MemoryArray X, nda::MemoryArray Y>
::testing::AssertionResult array_are_rel_close (X const &x, Y const &y, double precision=1.e-10)
 Check that two arrays/views are close in a relative sense, i.e. that they have the same shape and that the largest elementwise relative difference is less than a given precision.
template<typename X, typename Y>
::testing::AssertionResult complex_are_close (X const &x, Y const &y, double precision=1.e-10)
 Check the absolute difference of two (complex) numbers.
template<typename X, typename Y>
::testing::AssertionResult generic_are_near (X const &x, Y const &y)
 Check that that two generic objects are close, i.e. that their absolute difference is less than 1e-12.

Function Documentation

◆ array_almost_zero()

template<typename X>
::testing::AssertionResult array_almost_zero ( X const & x)

#include <nda/gtest_tools.hpp>

Check that an array/view is close to zero, i.e. that its largest absolute element is less than 1e-10.

Template Parameters
XType of the array/view.
Parameters
xArray/View.
Returns
::testing::AssertionSuccess() if the absolute value of every element is less than 1e-10. ::testing::AssertionFailure() otherwise.

Definition at line 169 of file gtest_tools.hpp.

◆ array_are_close()

template<typename X, typename Y>
::testing::AssertionResult array_are_close ( X const & x,
Y const & y,
double precision = 1.e-10 )

#include <nda/gtest_tools.hpp>

Check that two arrays/views are close, i.e. that they have the same shape and that the largest element of their absolute difference is less than a given precision.

Template Parameters
XType of the first array/view.
YType of the second array/view.
Parameters
xFirst array/view.
ySecond array/view.
precisionRequired precision for the comparison to be considered successful.
Returns
::testing::AssertionSuccess() if the arrays/view have the same shape and largest element of their absolute difference is less than a given precision. ::testing::AssertionFailure() otherwise.

Definition at line 93 of file gtest_tools.hpp.

◆ array_are_equal()

template<typename X, typename Y>
::testing::AssertionResult array_are_equal ( X const & x,
Y const & y )

#include <nda/gtest_tools.hpp>

Check that two arrays/views are equal, i.e. that they have the same shape and the same elements.

Template Parameters
XType of the first array/view.
YType of the second array/view.
Parameters
xFirst array/view.
ySecond array/view.
Returns
::testing::AssertionSuccess() if the arrays/view have the same shape and the same elements, ::testing::AssertionFailure() otherwise.

Definition at line 64 of file gtest_tools.hpp.

◆ array_are_rel_close()

::testing::AssertionResult array_are_rel_close ( X const & x,
Y const & y,
double precision = 1.e-10 )

#include <nda/gtest_tools.hpp>

Check that two arrays/views are close in a relative sense, i.e. that they have the same shape and that the largest elementwise relative difference is less than a given precision.

The relative difference of two elements is defined as \( |x - y| / \max(|x|, |y|) \), with the convention that two vanishing elements have zero relative difference. Unlike array_are_close, this is meaningful when the elements span several orders of magnitude, where a single absolute tolerance would be dominated by the largest elements and blind to errors in the smallest ones.

Template Parameters
Xnda::MemoryArray type of the first array/view.
Ynda::MemoryArray type of the second array/view.
Parameters
xFirst array/view.
ySecond array/view.
precisionRequired relative precision for the comparison to be considered successful.
Returns
::testing::AssertionSuccess() if the arrays/view have the same shape and largest elementwise relative difference is less than the given precision. ::testing::AssertionFailure() otherwise.

Definition at line 134 of file gtest_tools.hpp.

◆ complex_are_close()

template<typename X, typename Y>
::testing::AssertionResult complex_are_close ( X const & x,
Y const & y,
double precision = 1.e-10 )

#include <nda/gtest_tools.hpp>

Check the absolute difference of two (complex) numbers.

Template Parameters
XType of the first number.
YType of the second number.
Parameters
xFirst number.
ySecond number.
precisionRequired precision for the comparison to be considered successful.
Returns
::testing::AssertionSuccess() if the absolute difference is less than the given precision, ::testing::AssertionFailure() otherwise.

Definition at line 42 of file gtest_tools.hpp.

◆ generic_are_near()

template<typename X, typename Y>
::testing::AssertionResult generic_are_near ( X const & x,
Y const & y )

#include <nda/gtest_tools.hpp>

Check that that two generic objects are close, i.e. that their absolute difference is less than 1e-12.

Template Parameters
XType of the first object.
YType of the second object.
Parameters
xFirst object.
ySecond object.
Returns
::testing::AssertionSuccess() if the absolute value of their difference is less than 1e-12. ::testing::AssertionFailure() otherwise.

Definition at line 194 of file gtest_tools.hpp.