|
| 1 | +/* pcmsolver_copyright_start */ |
| 2 | +/* |
| 3 | + * PCMSolver, an API for the Polarizable Continuum Model |
| 4 | + * Copyright (C) 2013 Roberto Di Remigio, Luca Frediani and contributors |
| 5 | + * |
| 6 | + * This file is part of PCMSolver. |
| 7 | + * |
| 8 | + * PCMSolver is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Lesser General Public License as published by |
| 10 | + * the Free Software Foundation, either version 3 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * PCMSolver is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Lesser General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Lesser General Public License |
| 19 | + * along with PCMSolver. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + * For information on the complete list of contributors to the |
| 22 | + * PCMSolver API, see: <http://pcmsolver.github.io/pcmsolver-doc> |
| 23 | + */ |
| 24 | +/* pcmsolver_copyright_end */ |
| 25 | + |
| 26 | +#define BOOST_TEST_MODULE SurfaceFunction |
| 27 | + |
| 28 | +#include <boost/test/unit_test.hpp> |
| 29 | +#include <boost/test/floating_point_comparison.hpp> |
| 30 | + |
| 31 | +#include "Config.hpp" |
| 32 | + |
| 33 | +#include <Eigen/Core> |
| 34 | + |
| 35 | +#include "SurfaceFunction.hpp" |
| 36 | + |
| 37 | +struct SurfaceFunctionTest { |
| 38 | + int nPoints; |
| 39 | + Eigen::VectorXd values1; |
| 40 | + Eigen::VectorXd values2; |
| 41 | + SurfaceFunction func1; |
| 42 | + SurfaceFunction func2; |
| 43 | + SurfaceFunctionTest() { SetUp(); } |
| 44 | + void SetUp() { |
| 45 | + nPoints = 1000; |
| 46 | + values1.resize(nPoints); |
| 47 | + values2.resize(nPoints); |
| 48 | + values1 = Eigen::VectorXd::Random(nPoints); |
| 49 | + values2 = Eigen::VectorXd::Random(nPoints); |
| 50 | + double * values1_ptr = values1.data(); |
| 51 | + double * values2_ptr = values2.data(); |
| 52 | + func1 = SurfaceFunction("TestFunction1", nPoints, values1_ptr); |
| 53 | + func2 = SurfaceFunction("TestFunction2", nPoints, values2_ptr); |
| 54 | + } |
| 55 | +}; |
| 56 | + |
| 57 | +/*! \class SurfaceFunction |
| 58 | + * \test \b SurfaceFunctionTest_addition tests addition of two SurfaceFunction |
| 59 | + */ |
| 60 | +BOOST_FIXTURE_TEST_CASE(addition, SurfaceFunctionTest) |
| 61 | +{ |
| 62 | + SurfaceFunction addition = func1 + func2; |
| 63 | + BOOST_REQUIRE_EQUAL(nPoints, addition.nPoints()); |
| 64 | + Eigen::VectorXd result(nPoints); |
| 65 | + result = values1 + values2; |
| 66 | + for (int i = 0; i < nPoints; ++i) { |
| 67 | + BOOST_REQUIRE_CLOSE(result(i), addition.value(i), 1.0e-12); |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +/*! \class SurfaceFunction |
| 72 | + * \test \b SurfaceFunctionTest_subtraction tests subtraction of two SurfaceFunction |
| 73 | + */ |
| 74 | +BOOST_FIXTURE_TEST_CASE(subtraction, SurfaceFunctionTest) |
| 75 | +{ |
| 76 | + SurfaceFunction subtraction = func1 - func2; |
| 77 | + BOOST_REQUIRE_EQUAL(nPoints, subtraction.nPoints()); |
| 78 | + Eigen::VectorXd result(nPoints); |
| 79 | + result = values1 - values2; |
| 80 | + for (int i = 0; i < nPoints; ++i) { |
| 81 | + BOOST_REQUIRE_CLOSE(result(i), subtraction.value(i), 1.0e-12); |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +/*! \class SurfaceFunction |
| 86 | + * \test \b SurfaceFunctionTest_multiply_by_scalar tests multiplication of a SurfaceFunction by a scalar |
| 87 | + */ |
| 88 | +BOOST_FIXTURE_TEST_CASE(multiply_by_scalar, SurfaceFunctionTest) |
| 89 | +{ |
| 90 | + SurfaceFunction scaled1 = 2.5 * func1; |
| 91 | + func2 *= 0.5; |
| 92 | + BOOST_REQUIRE_EQUAL(nPoints, scaled1.nPoints()); |
| 93 | + BOOST_REQUIRE_EQUAL(nPoints, func2.nPoints()); |
| 94 | + Eigen::VectorXd result1(nPoints), result2(nPoints); |
| 95 | + result1 = 2.5 * values1; |
| 96 | + result2 = 0.5 * values2; |
| 97 | + for (int i = 0; i < nPoints; ++i) { |
| 98 | + BOOST_REQUIRE_CLOSE(result1(i), scaled1.value(i), 1.0e-12); |
| 99 | + BOOST_REQUIRE_CLOSE(result2(i), func2.value(i), 1.0e-12); |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +/*! \class SurfaceFunction |
| 104 | + * \test \b SurfaceFunctionTest_multiply tests dot product of two SurfaceFunction |
| 105 | + */ |
| 106 | +BOOST_FIXTURE_TEST_CASE(multiply, SurfaceFunctionTest) |
| 107 | +{ |
| 108 | + double product = func1 * func2; |
| 109 | + double expected_product = values1.dot(values2); |
| 110 | + BOOST_REQUIRE_CLOSE(expected_product, product, 1.0e-12); |
| 111 | +} |
0 commit comments