Skip to content

Commit

Permalink
Use test-suite namespaces to avoid ambiguities.
Browse files Browse the repository at this point in the history
BOOST_AUTO_TEST_SUITE defines a namespace, so utilities
in test files don't need to be in a namespace (anonymous
or otherwise) to avoid ambiguities, even in unity builds.
  • Loading branch information
lballabio committed Dec 14, 2023
1 parent 540a575 commit b0160d0
Show file tree
Hide file tree
Showing 169 changed files with 863 additions and 1,626 deletions.
10 changes: 5 additions & 5 deletions test-suite/americanoption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
using namespace QuantLib;
using namespace boost::unit_test_framework;

BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(AmericanOptionTests)

#undef REPORT_FAILURE
#define REPORT_FAILURE(greekName, payoff, exercise, s, q, r, today, \
v, expected, calculated, error, tolerance) \
Expand Down Expand Up @@ -83,10 +87,6 @@ namespace {

}

BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(AmericanOptionTest)

BOOST_AUTO_TEST_CASE(testBaroneAdesiWhaleyValues) {

BOOST_TEST_MESSAGE("Testing Barone-Adesi and Whaley approximation "
Expand Down Expand Up @@ -2243,4 +2243,4 @@ BOOST_AUTO_TEST_CASE(testSingleBjerksundStenslandGreeks) {

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
4 changes: 2 additions & 2 deletions test-suite/amortizingbond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
using namespace QuantLib;
using namespace boost::unit_test_framework;

BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture)
BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(AmortizingBondTest)
BOOST_AUTO_TEST_SUITE(AmortizingBondTests)

BOOST_AUTO_TEST_CASE(testAmortizingFixedRateBond) {
BOOST_TEST_MESSAGE("Testing amortizing fixed rate bond...");
Expand Down
30 changes: 5 additions & 25 deletions test-suite/andreasenhugevolatilityinterpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
using namespace QuantLib;
using namespace boost::unit_test_framework;

namespace andreasen_huge_volatility_interpl_test {
BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(AndreasenHugeVolatilityInterplTests)

namespace {

struct CalibrationData {
const Handle<Quote> spot;
Expand Down Expand Up @@ -387,17 +391,11 @@ namespace andreasen_huge_volatility_interpl_test {
}


BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(AndreasenHugeVolatilityInterplTest)

BOOST_AUTO_TEST_CASE(testAndreasenHugePut, *precondition(if_speed(Fast))) {

BOOST_TEST_MESSAGE(
"Testing Andreasen-Huge example with Put calibration...");

using namespace andreasen_huge_volatility_interpl_test;

const CalibrationData data = AndreasenHugeExampleData();

const CalibrationResults expected = {
Expand All @@ -415,8 +413,6 @@ BOOST_AUTO_TEST_CASE(testAndreasenHugeCall) {
BOOST_TEST_MESSAGE(
"Testing Andreasen-Huge example with Call calibration...");

using namespace andreasen_huge_volatility_interpl_test;

const CalibrationData data = AndreasenHugeExampleData();

const CalibrationResults expected = {
Expand All @@ -435,8 +431,6 @@ BOOST_AUTO_TEST_CASE(testAndreasenHugeCallPut, *precondition(if_speed(Fast))) {
"Testing Andreasen-Huge example with instantaneous "
"Call and Put calibration...");

using namespace andreasen_huge_volatility_interpl_test;

const CalibrationData data = AndreasenHugeExampleData();

const CalibrationResults expected = {
Expand All @@ -453,8 +447,6 @@ BOOST_AUTO_TEST_CASE(testLinearInterpolation, *precondition(if_speed(Fast))) {
BOOST_TEST_MESSAGE(
"Testing Andreasen-Huge example with linear interpolation...");

using namespace andreasen_huge_volatility_interpl_test;

const CalibrationData data = AndreasenHugeExampleData();

const CalibrationResults expected = {
Expand All @@ -471,8 +463,6 @@ BOOST_AUTO_TEST_CASE(testPiecewiseConstantInterpolation, *precondition(if_speed(
BOOST_TEST_MESSAGE(
"Testing Andreasen-Huge example with piecewise constant interpolation...");

using namespace andreasen_huge_volatility_interpl_test;

const CalibrationData data = AndreasenHugeExampleData();

const CalibrationResults expected = {
Expand All @@ -491,8 +481,6 @@ BOOST_AUTO_TEST_CASE(testTimeDependentInterestRates, *precondition(if_speed(Fast
"Testing Andreasen-Huge volatility interpolation with "
"time dependent interest rates and dividend yield...");

using namespace andreasen_huge_volatility_interpl_test;

const CalibrationData data = AndreasenHugeExampleData();

const DayCounter dc = data.rTS->dayCounter();
Expand Down Expand Up @@ -635,8 +623,6 @@ BOOST_AUTO_TEST_CASE(testArbitrageFree) {
"Testing Andreasen-Huge volatility interpolation gives "
"arbitrage free prices...");

using namespace andreasen_huge_volatility_interpl_test;

CalibrationData data[] = { BorovkovaExampleData(), arbitrageData() };;

for (auto& i : data) {
Expand Down Expand Up @@ -829,8 +815,6 @@ BOOST_AUTO_TEST_CASE(testPeterAndFabiensExample) {

// http://chasethedevil.github.io/post/andreasen-huge-extrapolation/

using namespace andreasen_huge_volatility_interpl_test;

const std::pair<CalibrationData, std::vector<Real> > sd = sabrData();
const CalibrationData& data = sd.first;
const std::vector<Real>& parameter = sd.second;
Expand Down Expand Up @@ -876,8 +860,6 @@ BOOST_AUTO_TEST_CASE(testDifferentOptimizers) {
"Testing different optimizer for Andreasen-Huge "
"volatility interpolation...");

using namespace andreasen_huge_volatility_interpl_test;

const CalibrationData& data = sabrData().first;

const ext::shared_ptr<OptimizationMethod> optimizationMethods[] = {
Expand Down Expand Up @@ -981,8 +963,6 @@ BOOST_AUTO_TEST_CASE(testFlatVolCalibration) {
BOOST_TEST_MESSAGE(
"Testing Andreasen-Huge example with flat volatility surface...");

using namespace andreasen_huge_volatility_interpl_test;

const Date ref(1, November, 2019);
const DayCounter dc = Actual365Fixed();
Settings::instance().evaluationDate() = ref;
Expand Down
12 changes: 5 additions & 7 deletions test-suite/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,21 @@
using namespace QuantLib;
using namespace boost::unit_test_framework;

namespace array_test {
BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(ArrayTests)

namespace {
class FSquared {
public:
Real operator()(Real x) const { return x*x; }
};
}

BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(ArrayTest)

BOOST_AUTO_TEST_CASE(testConstruction) {

BOOST_TEST_MESSAGE("Testing array construction...");

using namespace array_test;

// empty array
Array a1;
if (!a1.empty())
Expand Down
10 changes: 5 additions & 5 deletions test-suite/asianoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
using namespace QuantLib;
using namespace boost::unit_test_framework;

BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(AsianOptionTests)

#undef REPORT_FAILURE
#define REPORT_FAILURE(greekName, averageType, \
runningAccumulator, pastFixings, \
Expand Down Expand Up @@ -142,10 +146,6 @@ namespace {
};
}

BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(AsianOptionTest)

BOOST_AUTO_TEST_CASE(testAnalyticContinuousGeometricAveragePrice) {

BOOST_TEST_MESSAGE(
Expand Down Expand Up @@ -2241,7 +2241,7 @@ BOOST_AUTO_TEST_CASE(testAnalyticDiscreteGeometricAveragePriceHeston) {
ext::shared_ptr<AnalyticDiscreteGeometricAveragePriceAsianHestonEngine> engine(new
AnalyticDiscreteGeometricAveragePriceAsianHestonEngine(hestonProcess));

AsianOptionTest::testDiscreteGeometricAveragePriceHeston(engine, tol);
AsianOptionTests::testDiscreteGeometricAveragePriceHeston(engine, tol);
}

BOOST_AUTO_TEST_CASE(testDiscreteGeometricAveragePriceHestonPastFixings) {
Expand Down
30 changes: 6 additions & 24 deletions test-suite/assetswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@
using namespace QuantLib;
using namespace boost::unit_test_framework;

namespace asset_swap_test {
BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(AssetSwapTests)

namespace {

struct CommonVars {
// common data
Expand Down Expand Up @@ -113,16 +117,10 @@ namespace asset_swap_test {
}


BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture) // fails with QL_USE_INDEXED_COUPON

BOOST_AUTO_TEST_SUITE(AssetSwapTest)

BOOST_AUTO_TEST_CASE(testConsistency) {
BOOST_TEST_MESSAGE(
"Testing consistency between fair price and fair spread...");

using namespace asset_swap_test;

CommonVars vars;

Calendar bondCalendar = TARGET();
Expand Down Expand Up @@ -509,8 +507,6 @@ BOOST_AUTO_TEST_CASE(testImpliedValue) {
BOOST_TEST_MESSAGE("Testing implied bond value against asset-swap fair"
" price with null spread...");

using namespace asset_swap_test;

bool usingAtParCoupons = IborCoupon::Settings::instance().usingAtParCoupons();

CommonVars vars;
Expand Down Expand Up @@ -877,8 +873,6 @@ BOOST_AUTO_TEST_CASE(testMarketASWSpread) {
BOOST_TEST_MESSAGE("Testing relationship between market asset swap"
" and par asset swap...");

using namespace asset_swap_test;

bool usingAtParCoupons = IborCoupon::Settings::instance().usingAtParCoupons();

CommonVars vars;
Expand Down Expand Up @@ -1317,8 +1311,6 @@ BOOST_AUTO_TEST_CASE(testZSpread) {
BOOST_TEST_MESSAGE("Testing clean and dirty price with null Z-spread "
"against theoretical prices...");

using namespace asset_swap_test;

CommonVars vars;

Calendar bondCalendar = TARGET();
Expand Down Expand Up @@ -1639,8 +1631,6 @@ BOOST_AUTO_TEST_CASE(testGenericBondImplied) {
BOOST_TEST_MESSAGE("Testing implied generic-bond value against"
" asset-swap fair price with null spread...");

using namespace asset_swap_test;

bool usingAtParCoupons = IborCoupon::Settings::instance().usingAtParCoupons();

CommonVars vars;
Expand Down Expand Up @@ -2029,8 +2019,6 @@ BOOST_AUTO_TEST_CASE(testMASWWithGenericBond) {
BOOST_TEST_MESSAGE("Testing market asset swap against par asset swap "
"with generic bond...");

using namespace asset_swap_test;

bool usingAtParCoupons = IborCoupon::Settings::instance().usingAtParCoupons();

CommonVars vars;
Expand Down Expand Up @@ -2504,8 +2492,6 @@ BOOST_AUTO_TEST_CASE(testZSpreadWithGenericBond) {
BOOST_TEST_MESSAGE("Testing clean and dirty price with null Z-spread "
"against theoretical prices...");

using namespace asset_swap_test;

CommonVars vars;

Calendar bondCalendar = TARGET();
Expand Down Expand Up @@ -2870,8 +2856,6 @@ BOOST_AUTO_TEST_CASE(testSpecializedBondVsGenericBond) {
BOOST_TEST_MESSAGE("Testing clean and dirty prices for specialized bond"
" against equivalent generic bond...");

using namespace asset_swap_test;

CommonVars vars;

Calendar bondCalendar = TARGET();
Expand Down Expand Up @@ -3431,8 +3415,6 @@ BOOST_AUTO_TEST_CASE(testSpecializedBondVsGenericBondUsingAsw) {
BOOST_TEST_MESSAGE("Testing asset-swap prices and spreads for specialized"
" bond against equivalent generic bond...");

using namespace asset_swap_test;

CommonVars vars;

Calendar bondCalendar = TARGET();
Expand Down Expand Up @@ -4257,4 +4239,4 @@ BOOST_AUTO_TEST_CASE(testSpecializedBondVsGenericBondUsingAsw) {

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
6 changes: 3 additions & 3 deletions test-suite/autocovariances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
using namespace QuantLib;
using namespace boost::unit_test_framework;

BOOST_FIXTURE_TEST_SUITE(QuantLibTest, TopLevelFixture)
BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(AutocovariancesTest)
BOOST_AUTO_TEST_SUITE(AutocovariancesTests)

BOOST_AUTO_TEST_CASE(testConvolutions) {
BOOST_TEST_MESSAGE("Testing convolutions...");
Expand Down Expand Up @@ -89,4 +89,4 @@ BOOST_AUTO_TEST_CASE(testAutoCorrelations) {

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
Loading

0 comments on commit b0160d0

Please sign in to comment.