From ccc45918f6bdccbb8d62290f48eaabe43aa1ceea Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Tue, 16 Feb 2021 12:20:25 +0100 Subject: [PATCH] More lambdas --- test-suite/basketoption.cpp | 17 ++++----- test-suite/cdo.cpp | 16 ++++----- test-suite/fdmlinearop.cpp | 20 +++++------ test-suite/hybridhestonhullwhiteprocess.cpp | 6 +--- test-suite/marketmodel.cpp | 39 +++++++++++---------- test-suite/normalclvmodel.cpp | 5 ++- test-suite/nthorderderivativeop.cpp | 13 ++----- test-suite/paralleltestrunner.hpp | 6 ++-- test-suite/riskneutraldensitycalculator.cpp | 7 ++-- test-suite/squarerootclvmodel.cpp | 4 +-- 10 files changed, 53 insertions(+), 80 deletions(-) diff --git a/test-suite/basketoption.cpp b/test-suite/basketoption.cpp index a1192d8edac..cd7718d2578 100644 --- a/test-suite/basketoption.cpp +++ b/test-suite/basketoption.cpp @@ -36,8 +36,6 @@ #include #include #include -#include -#include using namespace QuantLib; using namespace boost::unit_test_framework; @@ -1066,15 +1064,12 @@ test_suite* BasketOptionTest::suite(SpeedLevel speed) { suite->add(QUANTLIB_TEST_CASE(&BasketOptionTest::test2DPDEGreeks)); if (speed <= Fast) { - #define N_TEST_CASES 5 - #define BOOST_PP_LOCAL_MACRO(n) \ - suite->add(QUANTLIB_TEST_CASE( \ - ext::bind(&BasketOptionTest::testOneDAmericanValues, \ - (n *LENGTH(oneDataValues))/N_TEST_CASES, \ - ((n+1)*LENGTH(oneDataValues))/N_TEST_CASES))); - - #define BOOST_PP_LOCAL_LIMITS (0, N_TEST_CASES-1) - #include BOOST_PP_LOCAL_ITERATE() + // unrolled to get different test names + suite->add(QUANTLIB_TEST_CASE([=](){ BasketOptionTest::testOneDAmericanValues( 0, 5); })); + suite->add(QUANTLIB_TEST_CASE([=](){ BasketOptionTest::testOneDAmericanValues( 5, 11); })); + suite->add(QUANTLIB_TEST_CASE([=](){ BasketOptionTest::testOneDAmericanValues(11, 17); })); + suite->add(QUANTLIB_TEST_CASE([=](){ BasketOptionTest::testOneDAmericanValues(17, 23); })); + suite->add(QUANTLIB_TEST_CASE([=](){ BasketOptionTest::testOneDAmericanValues(23, 29); })); } if (speed == Slow) { diff --git a/test-suite/cdo.cpp b/test-suite/cdo.cpp index bc9a75456e6..80721b82fce 100644 --- a/test-suite/cdo.cpp +++ b/test-suite/cdo.cpp @@ -34,8 +34,6 @@ #include #include #include -#include -#include #include #include @@ -369,13 +367,15 @@ void CdoTest::testHW(unsigned dataSet) { test_suite* CdoTest::suite(SpeedLevel speed) { auto* suite = BOOST_TEST_SUITE("CDO tests"); -#ifndef QL_PATCH_SOLARIS - if (speed == Slow) { - #define BOOST_PP_LOCAL_MACRO(n) \ - suite->add(QUANTLIB_TEST_CASE(ext::bind(&CdoTest::testHW, n))); - #define BOOST_PP_LOCAL_LIMITS (0, 4) - #include BOOST_PP_LOCAL_ITERATE() + #ifndef QL_PATCH_SOLARIS + if (speed == Slow) { + // unrolled to get different test names + suite->add(QUANTLIB_TEST_CASE([=](){ CdoTest::testHW(0); })); + suite->add(QUANTLIB_TEST_CASE([=](){ CdoTest::testHW(1); })); + suite->add(QUANTLIB_TEST_CASE([=](){ CdoTest::testHW(2); })); + suite->add(QUANTLIB_TEST_CASE([=](){ CdoTest::testHW(3); })); + suite->add(QUANTLIB_TEST_CASE([=](){ CdoTest::testHW(4); })); } #endif return suite; diff --git a/test-suite/fdmlinearop.cpp b/test-suite/fdmlinearop.cpp index ca4ab82d497..66414e52e57 100644 --- a/test-suite/fdmlinearop.cpp +++ b/test-suite/fdmlinearop.cpp @@ -1284,19 +1284,17 @@ void FdmLinearOpTest::testBiCGstab() { BOOST_TEST_MESSAGE( "Testing bi-conjugated gradient stabilized algorithm..."); - using namespace ext::placeholders; - const Size n=41, m=21; const Real theta = 1.0; const boost::numeric::ublas::compressed_matrix a = createTestMatrix(n, m, theta); - const ext::function(const Array&)> matmult( - ext::bind(&axpy, a, _1)); + const ext::function(const Array&)> matmult + = [&](const Array& _x) { return axpy(a, _x); }; SparseILUPreconditioner ilu(a, 4); - ext::function(const Array&)> precond( - ext::bind(&SparseILUPreconditioner::apply, &ilu, _1)); + ext::function(const Array&)> precond + = [&](const Array& _x) { return ilu.apply(_x); }; Array b(n*m); MersenneTwisterUniformRng rng(1234); @@ -1324,19 +1322,17 @@ void FdmLinearOpTest::testGMRES() { #if !defined(QL_NO_UBLAS_SUPPORT) BOOST_TEST_MESSAGE("Testing GMRES algorithm..."); - using namespace ext::placeholders; - const Size n=41, m=21; const Real theta = 1.0; const boost::numeric::ublas::compressed_matrix a = createTestMatrix(n, m, theta); - const ext::function(const Array&)> matmult( - ext::bind(&axpy, a, _1)); + const ext::function(const Array&)> matmult + = [&](const Array& _x) { return axpy(a, _x); }; SparseILUPreconditioner ilu(a, 4); - ext::function(const Array&)> precond( - ext::bind(&SparseILUPreconditioner::apply, &ilu, _1)); + ext::function(const Array&)> precond + = [&](const Array& _x) { return ilu.apply(_x); }; Array b(n*m); MersenneTwisterUniformRng rng(1234); diff --git a/test-suite/hybridhestonhullwhiteprocess.cpp b/test-suite/hybridhestonhullwhiteprocess.cpp index 4f3e070d02a..fa4b10db593 100644 --- a/test-suite/hybridhestonhullwhiteprocess.cpp +++ b/test-suite/hybridhestonhullwhiteprocess.cpp @@ -50,7 +50,6 @@ #include #include #include -#include #include using namespace QuantLib; @@ -628,8 +627,6 @@ void HybridHestonHullWhiteProcessTest::testAnalyticHestonHullWhitePricing() { void HybridHestonHullWhiteProcessTest::testCallableEquityPricing() { BOOST_TEST_MESSAGE("Testing the pricing of a callable equity product..."); - using namespace ext::placeholders; - SavedSettings backup; /* @@ -671,8 +668,7 @@ void HybridHestonHullWhiteProcessTest::testCallableEquityPricing() { std::vector