/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2005 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ QuantLib is free software: you can redistribute it and/or modify it under the terms of the QuantLib license. You should have received a copy of the license along with this program; if not, please email . The license is also available online at . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ #include "array.hpp" #include "utilities.hpp" #include #include using namespace QuantLib; using namespace boost::unit_test_framework; class FSquared : std::unary_function { public: Real operator()(Real x) const { return x*x; } }; void ArrayTest::testConstruction() { BOOST_MESSAGE("Testing array construction..."); QL_TEST_BEGIN // empty array Array a1; if (!a1.empty()) BOOST_ERROR("default-initialized array is not empty " "(size = " << a1.size() << ")"); // sized array Size size = 5; Array a2(size); if (a2.size() != size) BOOST_ERROR("array not of the required size" << "\n required: " << size << "\n resulting: " << a2.size()); // sized array, constant values Real value = 42.0; Array a3(size, value); if (a3.size() != size) BOOST_ERROR("array not of the required size" << "\n required: " << size << "\n resulting: " << a3.size()); Size i; for (i=0; i temp2(temp1); if (temp2.size() != size || !temp1.empty()) BOOST_ERROR("array not correctly moved into disposable array" << "\n original size of source: " << size << "\n current size of source: " << temp1.size() << "\n current size of target: " << temp2.size()); for (i=0; i temp4(temp3); Array a9; a9 = temp4; if (a9.size() != size || !temp4.empty()) BOOST_ERROR("disposable array not correctly moved into array" << "\n original size of source: " << size << "\n current size of source: " << temp4.size() << "\n current size of target: " << a9.size()); for (i=0; i(i)); if (std::fabs(a10[i] - calculated) >= 1e-5) { BOOST_ERROR("Array transform test failed " << a10[i] << " " << calculated); } } QL_TEST_END } test_suite* ArrayTest::suite() { test_suite* suite = BOOST_TEST_SUITE("array tests"); suite->add(BOOST_TEST_CASE(&ArrayTest::testConstruction)); return suite; }