[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);
|
---|
[691be4] | 73 | tempvector[0] = argument_t( std::make_pair(0,1), std::make_pair(1,1), 1.);
|
---|
| 74 | tempvector[1] = argument_t( std::make_pair(0,2), std::make_pair(1,1), 1.);
|
---|
| 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 | {
|
---|
| 105 | PairPotential_Angle angle(.5,0.,.1);
|
---|
| 106 | for (size_t index = 0; index < input.size(); ++index) {
|
---|
| 107 | CPPUNIT_ASSERT(
|
---|
| 108 | Helpers::isEqual(
|
---|
| 109 | output[index],
|
---|
| 110 | angle( input[index] )[0]
|
---|
| 111 | )
|
---|
| 112 | );
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | /** UnitTest for derivative()
|
---|
| 117 | */
|
---|
| 118 | void PairPotential_AngleTest::derivativeTest()
|
---|
| 119 | {
|
---|
| 120 | PairPotential_Angle angle(.5,0.,.1);
|
---|
| 121 | CPPUNIT_ASSERT(
|
---|
| 122 | Helpers::isEqual(
|
---|
| 123 | 0.,
|
---|
| 124 | angle.derivative(
|
---|
| 125 | input[5]
|
---|
| 126 | )[0],
|
---|
| 127 | 10.
|
---|
| 128 | )
|
---|
| 129 | );
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 | /** UnitTest for parameter_derivative()
|
---|
| 134 | */
|
---|
| 135 | void PairPotential_AngleTest::parameter_derivativeTest()
|
---|
| 136 | {
|
---|
| 137 | PairPotential_Angle angle(.5,0.,.1);
|
---|
| 138 | CPPUNIT_ASSERT(
|
---|
| 139 | Helpers::isEqual(
|
---|
| 140 | 0.,
|
---|
| 141 | angle.parameter_derivative(
|
---|
| 142 | input[5],
|
---|
| 143 | 0
|
---|
| 144 | )[0],
|
---|
| 145 | 10.
|
---|
| 146 | )
|
---|
| 147 | );
|
---|
| 148 | CPPUNIT_ASSERT(
|
---|
| 149 | Helpers::isEqual(
|
---|
| 150 | 0.,
|
---|
| 151 | angle.parameter_derivative(
|
---|
| 152 | input[5],
|
---|
| 153 | 1
|
---|
| 154 | )[0],
|
---|
| 155 | 10.
|
---|
| 156 | )
|
---|
| 157 | );
|
---|
| 158 | CPPUNIT_ASSERT(
|
---|
| 159 | Helpers::isEqual(
|
---|
| 160 | 1.,
|
---|
| 161 | angle.parameter_derivative(
|
---|
| 162 | input[5],
|
---|
| 163 | 2
|
---|
| 164 | )[0],
|
---|
| 165 | 10.
|
---|
| 166 | )
|
---|
| 167 | );
|
---|
| 168 | }
|
---|