[go: up one dir, main page]

1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2005 Joseph Wang
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20#include "transformedgrid.hpp"
21#include "utilities.hpp"
22#include <ql/math/transformedgrid.hpp>
23#include <ql/utilities/dataformatters.hpp>
24#include <ql/grid.hpp>
25
26using namespace QuantLib;
27using namespace boost::unit_test_framework;
28
29class PlusOne {
30public:
31 Real operator()(Real x) const { return x+1;};
32};
33
34void TransformedGridTest::testConstruction() {
35
36 BOOST_TEST_MESSAGE("Testing transformed grid construction...");
37
38 PlusOne p1;
39 Array grid = BoundedGrid(xMin: 0, xMax: 100, steps: 100);
40 TransformedGrid tg(grid, p1);
41 if (std::fabs(x: tg.grid(i: 0) - 0.0) > 1e-5) {
42 BOOST_ERROR("grid creation failed");
43 }
44
45 if (std::fabs(x: tg.transformedGrid(i: 0) - 1.0) > 1e-5)
46 BOOST_ERROR("grid transformation failed");
47}
48
49test_suite* TransformedGridTest::suite() {
50 auto* suite = BOOST_TEST_SUITE("transformed grid");
51 suite->add(QUANTLIB_TEST_CASE(&TransformedGridTest::testConstruction));
52 return suite;
53}
54
55

source code of quantlib/test-suite/transformedgrid.cpp