From e0737c56c1e384e05064a0c6e1ac46979371041b Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Wed, 19 Dec 2018 22:58:32 +0100 Subject: New upstream version 2.0.0+repack --- boost/libs/math/test/test_minima.cpp | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 boost/libs/math/test/test_minima.cpp (limited to 'boost/libs/math/test/test_minima.cpp') diff --git a/boost/libs/math/test/test_minima.cpp b/boost/libs/math/test/test_minima.cpp new file mode 100644 index 00000000..e2f8560b --- /dev/null +++ b/boost/libs/math/test/test_minima.cpp @@ -0,0 +1,64 @@ +// Copyright John Maddock 2006. +// Copyright Paul A. Bristow 2007. + +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include + +#include +#define BOOST_TEST_MAIN +#include +#include +#include +#include +#include + +template +struct poly_test +{ + // minima is at (3,4): + T operator()(const T& v) + { + T a = v - 3; + return 3 * a * a + 4; + } +}; + +template +void test_minima(T, const char* /* name */) +{ + std::pair m = boost::math::tools::brent_find_minima(poly_test(), T(-10), T(10), 50); + BOOST_CHECK_CLOSE(m.first, T(3), T(0.001)); + BOOST_CHECK_CLOSE(m.second, T(4), T(0.001)); + + T (*fp)(T); +#if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) + fp = boost::math::lgamma; +#else + fp = boost::math::lgamma; +#endif + + m = boost::math::tools::brent_find_minima(fp, T(0.5), T(10), 50); + BOOST_CHECK_CLOSE(m.first, T(1.461632), T(0.1)); +#if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS) + fp = boost::math::tgamma; +#else + fp = boost::math::tgamma; +#endif + m = boost::math::tools::brent_find_minima(fp, T(0.5), T(10), 50); + BOOST_CHECK_CLOSE(m.first, T(1.461632), T(0.1)); +} + +BOOST_AUTO_TEST_CASE( test_main ) +{ + test_minima(0.1f, "float"); + test_minima(0.1, "double"); +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS + test_minima(0.1L, "long double"); +#endif + +} + + -- cgit v1.2.3