|
TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
|
GoogleTest-based helpers for writing TRIQS C++ unit tests.
The Test tools module is a header-only collection of helpers, built on top of GoogleTest, that the TRIQS C++ test suite uses to compare its core data structures and to set up test executables.
It provides various macros and helper functions to simplify writing unit tests involving TRIQS components.
Macros | |
| #define | ASSERT_PRINT(X, Y) |
| Check that streaming Y into an output stream produces the string X. | |
| #define | EXPECT_BLOCK2_GF_NEAR(X, ...) |
| Non-fatal GoogleTest assertion that two Block2 Green's functions are close (see test_block2_gfs_are_close). | |
| #define | EXPECT_BLOCK_GF_NEAR(X, ...) |
| Non-fatal GoogleTest assertion that two block Green's functions are close (see test_block_gfs_are_close). | |
| #define | EXPECT_GF_NEAR(X, ...) |
| Non-fatal GoogleTest assertion that two Green's functions are close (see test_gfs_are_close). | |
| #define | EXPECT_OPERATOR_NEAR(X, ...) |
| Non-fatal GoogleTest assertion that two many-body operators are close (see test_operators_are_close). | |
| #define | EXPECT_PRINT(X, Y) |
| Check that streaming Y into an output stream produces the string X. | |
| #define | EXPECT_TAIL_NEAR(X, ...) |
| Non-fatal GoogleTest assertion that two tails are close (see test_tails_are_close). | |
| #define | MAKE_MAIN |
| Define a main function that runs all registered GoogleTest tests. | |
Functions | |
| template<typename X, typename Y> | |
| void | triqs::gfs::assert_block2_gfs_are_close (X const &x, Y const &y, double precision) |
| Assert that two doubly-indexed block Green's functions are numerically close. | |
| template<typename X, typename Y> | |
| void | triqs::gfs::assert_block_gfs_are_close (X const &x, Y const &y, double precision) |
| Assert that two block Green's functions are numerically close. | |
| template<typename X, typename Y> | |
| void | triqs::gfs::assert_gfs_are_close (X const &x, Y const &y, double precision) |
| Assert that two Green's functions are numerically close. | |
| template<typename T> | |
| T | rw_h5 (T const &x, std::string filename="ess", std::string name="x") |
| Write an object to an HDF5 file and read it back. | |
| template<typename X, typename Y> | |
| ::testing::AssertionResult | test_block2_gfs_are_close (X const &x, Y const &y, double precision=1.e-6) |
| Check that two block-of-block (Block2) Green's functions are element-wise close. | |
| template<typename X, typename Y> | |
| ::testing::AssertionResult | test_block_gfs_are_close (X const &x, Y const &y, double precision=1.e-6) |
| Check that two block Green's functions are element-wise close. | |
| template<typename X, typename Y> | |
| ::testing::AssertionResult | test_gfs_are_close (X const &x, Y const &y, double precision=1.e-6) |
| Check that two Green's functions are element-wise close. | |
| template<typename X, typename Y> | |
| ::testing::AssertionResult | test_operators_are_close (X const &x, Y const &y, double precision=1e-6) |
| Check that two many-body operators are term-wise equal up to a given precision. | |
| template<typename X, typename Y> | |
| ::testing::AssertionResult | test_tails_are_close (X const &x, Y const &y, double precision=1.e-6) |
| Check that the high-frequency tails of two Green's functions are element-wise close. | |
| #define ASSERT_PRINT | ( | X, | |
| Y ) |
#include <triqs/test_tools/arrays.hpp>
Check that streaming Y into an output stream produces the string X.
Like EXPECT_PRINT but uses ASSERT_EQ, i.e. a fatal GoogleTest assertion that aborts the current test on failure.
| X | Expected string. |
| Y | Object to be streamed via operator<<. |
Definition at line 76 of file arrays.hpp.
| #define EXPECT_PRINT | ( | X, | |
| Y ) |
#include <triqs/test_tools/arrays.hpp>
Check that streaming Y into an output stream produces the string X.
Streams Y into a std::stringstream and compares the result to X with EXPECT_EQ, i.e. a non-fatal GoogleTest assertion that lets the test continue on failure.
| X | Expected string. |
| Y | Object to be streamed via operator<<. |
Definition at line 60 of file arrays.hpp.
| #define MAKE_MAIN |
#include <triqs/test_tools/arrays.hpp>
Define a main function that runs all registered GoogleTest tests.
Initializes GoogleTest and runs all tests. When TRIQS is built with MPI support, an mpi::environment is set up so that MPI-aware tests run under a valid communicator.
Definition at line 89 of file arrays.hpp.
| void triqs::gfs::assert_block2_gfs_are_close | ( | X const & | x, |
| Y const & | y, | ||
| double | precision ) |
#include <triqs/gfs/gf_tests.hpp>
Assert that two doubly-indexed block Green's functions are numerically close.
Throws a runtime error if the number of blocks or the block names differ, then checks each \( (i, j) \) block pair with assert_gfs_are_close().
| X | The type of the first block2 Green's function. |
| Y | The type of the second block2 Green's function. |
| x | The first block2 Green's function. |
| y | The second block2 Green's function. |
| precision | The maximum allowed element-wise absolute difference per block. |
Definition at line 87 of file gf_tests.hpp.
| void triqs::gfs::assert_block_gfs_are_close | ( | X const & | x, |
| Y const & | y, | ||
| double | precision ) |
#include <triqs/gfs/gf_tests.hpp>
Assert that two block Green's functions are numerically close.
Throws a runtime error if the number of blocks or the block names differ, then checks each block pair with assert_gfs_are_close().
| X | The type of the first block Green's function. |
| Y | The type of the second block Green's function. |
| x | The first block Green's function. |
| y | The second block Green's function. |
| precision | The maximum allowed element-wise absolute difference per block. |
Definition at line 68 of file gf_tests.hpp.
| void triqs::gfs::assert_gfs_are_close | ( | X const & | x, |
| Y const & | y, | ||
| double | precision ) |
#include <triqs/gfs/gf_tests.hpp>
Assert that two Green's functions are numerically close.
Throws a runtime error if the meshes of the two Green's functions differ, or if the maximum element-wise absolute difference of their data exceeds precision.
| X | The type of the first Green's function. |
| Y | The type of the second Green's function. |
| x | The first Green's function. |
| y | The second Green's function. |
| precision | The maximum allowed element-wise absolute difference. |
Definition at line 48 of file gf_tests.hpp.
| T rw_h5 | ( | T const & | x, |
| std::string | filename = "ess", | ||
| std::string | name = "x" ) |
#include <triqs/test_tools/arrays.hpp>
Write an object to an HDF5 file and read it back.
Serializes x to an HDF5 file, reads it back into a freshly default-constructed object and returns it. Useful for testing that a type's HDF5 read/write round-trip preserves its value.
| T | Type of the object. Must be default-constructible and h5-serializable. |
| x | Object to write to file. |
| filename | Base name of the HDF5 file (the .h5 extension is appended). |
| name | Name of the dataset inside the file. |
Definition at line 112 of file arrays.hpp.
| ::testing::AssertionResult test_block2_gfs_are_close | ( | X const & | x, |
| Y const & | y, | ||
| double | precision = 1.e-6 ) |
#include <triqs/test_tools/gfs.hpp>
Check that two block-of-block (Block2) Green's functions are element-wise close.
Wraps triqs::gfs::assert_block2_gfs_are_close and turns a thrown triqs::exception into a GoogleTest AssertionFailure carrying the exception message.
| X | Type of the first Block2 Green's function. |
| Y | Type of the second Block2 Green's function. |
| x | First Block2 Green's function. |
| y | Second Block2 Green's function. |
| precision | Absolute tolerance used for the comparison. |
| ::testing::AssertionResult test_block_gfs_are_close | ( | X const & | x, |
| Y const & | y, | ||
| double | precision = 1.e-6 ) |
#include <triqs/test_tools/gfs.hpp>
Check that two block Green's functions are element-wise close.
Wraps triqs::gfs::assert_block_gfs_are_close and turns a thrown triqs::exception into a GoogleTest AssertionFailure carrying the exception message.
| X | Type of the first block Green's function. |
| Y | Type of the second block Green's function. |
| x | First block Green's function. |
| y | Second block Green's function. |
| precision | Absolute tolerance used for the comparison. |
| ::testing::AssertionResult test_gfs_are_close | ( | X const & | x, |
| Y const & | y, | ||
| double | precision = 1.e-6 ) |
#include <triqs/test_tools/gfs.hpp>
Check that two Green's functions are element-wise close.
Wraps triqs::gfs::assert_gfs_are_close and turns a thrown triqs::exception into a GoogleTest AssertionFailure carrying the exception message.
| X | Type of the first Green's function. |
| Y | Type of the second Green's function. |
| x | First Green's function. |
| y | Second Green's function. |
| precision | Absolute tolerance used for the comparison. |
| ::testing::AssertionResult test_operators_are_close | ( | X const & | x, |
| Y const & | y, | ||
| double | precision = 1e-6 ) |
#include <triqs/test_tools/many_body_operator.hpp>
Check that two many-body operators are term-wise equal up to a given precision.
Wraps triqs::operators::assert_operators_are_close and turns a thrown triqs::exception into a GoogleTest AssertionFailure carrying the exception message.
| X | Type of the first operator. |
| Y | Type of the second operator. |
| x | First operator. |
| y | Second operator. |
| precision | Absolute tolerance used for the term-wise comparison. |
Definition at line 48 of file many_body_operator.hpp.
| ::testing::AssertionResult test_tails_are_close | ( | X const & | x, |
| Y const & | y, | ||
| double | precision = 1.e-6 ) |
#include <triqs/test_tools/gfs.hpp>
Check that the high-frequency tails of two Green's functions are element-wise close.
Wraps triqs::gfs::assert_tails_are_close and turns a thrown triqs::exception into a GoogleTest AssertionFailure carrying the exception message.
| X | Type of the first tail. |
| Y | Type of the second tail. |
| x | First tail. |
| y | Second tail. |
| precision | Absolute tolerance used for the comparison. |