/usr/include/mlpack/tests/test_tools.hpp is in libmlpack-dev 2.2.5-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | /**
* @file test_tools.hpp
* @author Ryan Curtin
*
* This file includes some useful macros for tests.
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_TESTS_TEST_TOOLS_HPP
#define MLPACK_TESTS_TEST_TOOLS_HPP
#include <boost/version.hpp>
// This is only necessary for pre-1.36 Boost.Test.
#if BOOST_VERSION < 103600
#include <boost/test/floating_point_comparison.hpp>
#include <boost/test/auto_unit_test.hpp>
// This depends on other macros. Probably not a great idea... but it works, and
// we only need it for ancient Boost versions.
#define BOOST_REQUIRE_GE( L, R ) \
BOOST_REQUIRE_EQUAL( (L >= R), true )
#define BOOST_REQUIRE_NE( L, R ) \
BOOST_REQUIRE_EQUAL( (L != R), true )
#define BOOST_REQUIRE_LE( L, R ) \
BOOST_REQUIRE_EQUAL( (L <= R), true )
#define BOOST_REQUIRE_LT( L, R ) \
BOOST_REQUIRE_EQUAL( (L < R), true )
#define BOOST_REQUIRE_GT( L, R ) \
BOOST_REQUIRE_EQUAL( (L > R), true )
#endif
// Require the approximation L to be within a relative error of E respect to the
// actual value R.
#define REQUIRE_RELATIVE_ERR( L, R, E ) \
BOOST_REQUIRE_LE( std::abs((R) - (L)), (E) * std::abs(R))
#include <mlpack/prereqs.hpp>
// Check the values of two matrices.
inline void CheckMatrices(const arma::mat& a, const arma::mat& b,
double tolerance = 1e-5)
{
BOOST_REQUIRE_EQUAL(a.n_rows, b.n_rows);
BOOST_REQUIRE_EQUAL(a.n_cols, b.n_cols);
for (size_t i = 0; i < a.n_elem; ++i)
{
if (std::abs(a[i]) < tolerance / 2)
BOOST_REQUIRE_SMALL(b[i], tolerance / 2);
else
BOOST_REQUIRE_CLOSE(a[i], b[i], tolerance);
}
}
// Check the values of two unsigned matrices.
inline void CheckMatrices(const arma::Mat<size_t>& a, const arma::Mat<size_t>& b)
{
BOOST_REQUIRE_EQUAL(a.n_rows, b.n_rows);
BOOST_REQUIRE_EQUAL(a.n_cols, b.n_cols);
for (size_t i = 0; i < a.n_elem; ++i)
BOOST_REQUIRE_EQUAL(a[i], b[i]);
}
#endif
|