| [c92c0d] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2012 University of Bonn. All rights reserved.
 | 
|---|
 | 5 |  * 
 | 
|---|
 | 6 |  *
 | 
|---|
 | 7 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 8 |  *
 | 
|---|
 | 9 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 10 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 11 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 12 |  *    (at your option) any later version.
 | 
|---|
 | 13 |  *
 | 
|---|
 | 14 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 15 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 16 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 17 |  *    GNU General Public License for more details.
 | 
|---|
 | 18 |  *
 | 
|---|
 | 19 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 20 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
 | 21 |  */
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | /*
 | 
|---|
 | 24 |  * PairPotential_AngleUnitTest.cpp
 | 
|---|
 | 25 |  *
 | 
|---|
 | 26 |  *  Created on: Oct 16, 2012
 | 
|---|
 | 27 |  *      Author: heber
 | 
|---|
 | 28 |  */
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | // include config.h
 | 
|---|
 | 31 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 32 | #include <config.h>
 | 
|---|
 | 33 | #endif
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | using namespace std;
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 | #include <cppunit/CompilerOutputter.h>
 | 
|---|
 | 38 | #include <cppunit/extensions/TestFactoryRegistry.h>
 | 
|---|
 | 39 | #include <cppunit/ui/text/TestRunner.h>
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 | #include "PairPotential_AngleUnitTest.hpp"
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 | #include <boost/assign.hpp>
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 | #include "CodePatterns/Assert.hpp"
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 | #include "FunctionApproximation/FunctionArgument.hpp"
 | 
|---|
 | 48 | #include "Potentials/Specifics/PairPotential_Angle.hpp"
 | 
|---|
 | 49 | #include "Potentials/helpers.hpp"
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | using namespace boost::assign;
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 | #ifdef HAVE_TESTRUNNER
 | 
|---|
 | 54 | #include "UnitTestMain.hpp"
 | 
|---|
 | 55 | #endif /*HAVE_TESTRUNNER*/
 | 
|---|
 | 56 | 
 | 
|---|
 | 57 | /********************************************** Test classes **************************************/
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 | // Registers the fixture into the 'registry'
 | 
|---|
 | 60 | CPPUNIT_TEST_SUITE_REGISTRATION( PairPotential_AngleTest );
 | 
|---|
 | 61 | 
 | 
|---|
 | 62 | 
 | 
|---|
 | 63 | void PairPotential_AngleTest::setUp()
 | 
|---|
 | 64 | {
 | 
|---|
 | 65 |   // failing asserts should be thrown
 | 
|---|
 | 66 |   ASSERT_DO(Assert::Throw);
 | 
|---|
 | 67 | 
 | 
|---|
 | 68 |   // create three distances to have the desired angle
 | 
|---|
 | 69 |   typedef std::vector<double> angles_t;
 | 
|---|
 | 70 |   angles_t angles;
 | 
|---|
 | 71 |   angles += -0.5, -.4, -.3, -.2, -.1, 0., .1, .2, .3, .4, .5;
 | 
|---|
 | 72 |   FunctionModel::arguments_t tempvector(3);
 | 
|---|
| [55fe788] | 73 |   tempvector[0] = argument_t( std::make_pair(0,1), std::make_pair(0,1), 1.);
 | 
|---|
 | 74 |   tempvector[1] = argument_t( std::make_pair(0,2), std::make_pair(0,1), 1.);
 | 
|---|
| [691be4] | 75 |   tempvector[2] = argument_t( std::make_pair(1,2), std::make_pair(1,1), 0.);
 | 
|---|
| [c92c0d] | 76 |   for (angles_t::const_iterator iter = angles.begin(); iter != angles.end(); ++iter) {
 | 
|---|
 | 77 |     tempvector[2].distance = sqrt(-(2.*(*iter)-2.));//1.+1.-x/(2.*1.*1.)
 | 
|---|
 | 78 |     input += tempvector;
 | 
|---|
 | 79 |   }
 | 
|---|
 | 80 |   output +=
 | 
|---|
 | 81 |       .5*0.25+.1,
 | 
|---|
 | 82 |       .5*0.16+.1,
 | 
|---|
 | 83 |       .5*0.09+.1,
 | 
|---|
 | 84 |       .5*0.04+.1,
 | 
|---|
 | 85 |       .5*0.01+.1,
 | 
|---|
 | 86 |       .5*0.+.1,
 | 
|---|
 | 87 |       .5*0.01+.1,
 | 
|---|
 | 88 |       .5*0.04+.1,
 | 
|---|
 | 89 |       .5*0.09+.1,
 | 
|---|
 | 90 |       .5*0.16+.1,
 | 
|---|
 | 91 |       .5*0.25+.1;
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 |   CPPUNIT_ASSERT_EQUAL( input.size(), output.size() );
 | 
|---|
 | 94 | }
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | 
 | 
|---|
 | 97 | void PairPotential_AngleTest::tearDown()
 | 
|---|
 | 98 | {
 | 
|---|
 | 99 | }
 | 
|---|
 | 100 | 
 | 
|---|
 | 101 | /** UnitTest for operator()
 | 
|---|
 | 102 |  */
 | 
|---|
 | 103 | void PairPotential_AngleTest::operatorTest()
 | 
|---|
 | 104 | {
 | 
|---|
| [ed2551] | 105 |   PairPotential_Angle::ParticleTypes_t types =
 | 
|---|
 | 106 |       boost::assign::list_of<PairPotential_Angle::ParticleType_t>
 | 
|---|
 | 107 |         (0)(1)(1)
 | 
|---|
 | 108 |       ;
 | 
|---|
 | 109 |   PairPotential_Angle angle(types, .5,0.,.1);
 | 
|---|
| [c92c0d] | 110 |   for (size_t index = 0; index < input.size(); ++index) {
 | 
|---|
 | 111 |     CPPUNIT_ASSERT(
 | 
|---|
 | 112 |         Helpers::isEqual(
 | 
|---|
 | 113 |             output[index],
 | 
|---|
 | 114 |             angle( input[index] )[0]
 | 
|---|
 | 115 |         )
 | 
|---|
 | 116 |     );
 | 
|---|
 | 117 |   }
 | 
|---|
 | 118 | }
 | 
|---|
 | 119 | 
 | 
|---|
 | 120 | /** UnitTest for derivative()
 | 
|---|
 | 121 |  */
 | 
|---|
 | 122 | void PairPotential_AngleTest::derivativeTest()
 | 
|---|
 | 123 | {
 | 
|---|
| [ed2551] | 124 |   PairPotential_Angle::ParticleTypes_t types =
 | 
|---|
 | 125 |       boost::assign::list_of<PairPotential_Angle::ParticleType_t>
 | 
|---|
 | 126 |         (0)(1)(1)
 | 
|---|
 | 127 |       ;
 | 
|---|
 | 128 |   PairPotential_Angle angle(types, .5,0.,.1);
 | 
|---|
| [c92c0d] | 129 |   CPPUNIT_ASSERT(
 | 
|---|
 | 130 |       Helpers::isEqual(
 | 
|---|
 | 131 |           0.,
 | 
|---|
 | 132 |           angle.derivative(
 | 
|---|
 | 133 |               input[5]
 | 
|---|
 | 134 |           )[0],
 | 
|---|
 | 135 |           10.
 | 
|---|
 | 136 |       )
 | 
|---|
 | 137 |   );
 | 
|---|
 | 138 | }
 | 
|---|
 | 139 | 
 | 
|---|
 | 140 | 
 | 
|---|
 | 141 | /** UnitTest for parameter_derivative()
 | 
|---|
 | 142 |  */
 | 
|---|
 | 143 | void PairPotential_AngleTest::parameter_derivativeTest()
 | 
|---|
 | 144 | {
 | 
|---|
| [ed2551] | 145 |   PairPotential_Angle::ParticleTypes_t types =
 | 
|---|
 | 146 |       boost::assign::list_of<PairPotential_Angle::ParticleType_t>
 | 
|---|
 | 147 |         (0)(1)(1)
 | 
|---|
 | 148 |       ;
 | 
|---|
 | 149 |   PairPotential_Angle angle(types, .5,0.,.1);
 | 
|---|
| [c92c0d] | 150 |   CPPUNIT_ASSERT(
 | 
|---|
 | 151 |       Helpers::isEqual(
 | 
|---|
 | 152 |           0.,
 | 
|---|
 | 153 |           angle.parameter_derivative(
 | 
|---|
 | 154 |               input[5],
 | 
|---|
 | 155 |               0
 | 
|---|
 | 156 |           )[0],
 | 
|---|
 | 157 |           10.
 | 
|---|
 | 158 |       )
 | 
|---|
 | 159 |   );
 | 
|---|
 | 160 |   CPPUNIT_ASSERT(
 | 
|---|
 | 161 |       Helpers::isEqual(
 | 
|---|
 | 162 |           0.,
 | 
|---|
 | 163 |           angle.parameter_derivative(
 | 
|---|
 | 164 |               input[5],
 | 
|---|
 | 165 |               1
 | 
|---|
 | 166 |           )[0],
 | 
|---|
 | 167 |           10.
 | 
|---|
 | 168 |       )
 | 
|---|
 | 169 |   );
 | 
|---|
 | 170 |   CPPUNIT_ASSERT(
 | 
|---|
 | 171 |       Helpers::isEqual(
 | 
|---|
 | 172 |           1.,
 | 
|---|
 | 173 |           angle.parameter_derivative(
 | 
|---|
 | 174 |               input[5],
 | 
|---|
 | 175 |               2
 | 
|---|
 | 176 |           )[0],
 | 
|---|
 | 177 |           10.
 | 
|---|
 | 178 |       )
 | 
|---|
 | 179 |   );
 | 
|---|
 | 180 | }
 | 
|---|