[e23075] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[6d608d] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[26249f] | 5 | * Copyright (C) 2013 Frederik Heber. All rights reserved.
|
---|
[94d5ac6] | 6 | *
|
---|
| 7 | *
|
---|
| 8 | * This file is part of MoleCuilder.
|
---|
| 9 | *
|
---|
| 10 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[e23075] | 22 | */
|
---|
| 23 |
|
---|
| 24 | /*
|
---|
| 25 | * VectorSetUnitTest.cpp
|
---|
| 26 | *
|
---|
| 27 | * Created on: Jan 06, 2012
|
---|
| 28 | * Author: heber
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | // include config.h
|
---|
| 32 | #ifdef HAVE_CONFIG_H
|
---|
| 33 | #include <config.h>
|
---|
| 34 | #endif
|
---|
| 35 |
|
---|
| 36 | using namespace std;
|
---|
| 37 |
|
---|
| 38 | #include <cppunit/CompilerOutputter.h>
|
---|
| 39 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 40 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 41 |
|
---|
| 42 | #include "VectorSetUnitTest.hpp"
|
---|
| 43 |
|
---|
[f6ad4d] | 44 | #include "RealSpaceMatrix.hpp"
|
---|
| 45 | #include "VectorSet.hpp"
|
---|
| 46 |
|
---|
[e23075] | 47 | #ifdef HAVE_TESTRUNNER
|
---|
| 48 | #include "UnitTestMain.hpp"
|
---|
| 49 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 50 |
|
---|
| 51 | #include <iostream>
|
---|
| 52 |
|
---|
| 53 | /********************************************** Test classes **************************************/
|
---|
| 54 |
|
---|
| 55 | // Registers the fixture into the 'registry'
|
---|
| 56 | CPPUNIT_TEST_SUITE_REGISTRATION( VectorSetTest );
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | void VectorSetTest::setUp()
|
---|
| 60 | {
|
---|
| 61 | list.push_back(Vector(0.,0.,0.));
|
---|
| 62 | list.push_back(Vector(1.,0.,0.));
|
---|
| 63 | list.push_back(Vector(0.,1.,0.));
|
---|
| 64 | list.push_back(Vector(0.,1.,1.));
|
---|
| 65 | list.push_back(Vector(2.,1.,0.));
|
---|
| 66 | list.push_back(Vector(1.,2.,3.));
|
---|
| 67 |
|
---|
| 68 | CPPUNIT_ASSERT_EQUAL( (size_t)6, list.size() );
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | void VectorSetTest::tearDown()
|
---|
| 73 | {
|
---|
| 74 | list.clear();
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[f6ad4d] | 77 | /** UnitTest for Cstor(Set &)
|
---|
| 78 | */
|
---|
| 79 | void VectorSetTest::copyConstructorTest()
|
---|
| 80 | {
|
---|
| 81 | VECTORSET(std::vector) worklist(list);
|
---|
| 82 | CPPUNIT_ASSERT_EQUAL( list.size(), worklist.size() );
|
---|
| 83 | std::vector<Vector>::const_iterator iter = list.begin();
|
---|
| 84 | VECTORSET(std::vector)::const_iterator workiter = worklist.begin();
|
---|
| 85 | for (;(iter != list.end()) && (workiter != worklist.end()); ++iter, ++workiter)
|
---|
| 86 | CPPUNIT_ASSERT( ((*iter)) == (*workiter) );
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 |
|
---|
[e23075] | 90 | /** UnitTest for translate()
|
---|
| 91 | */
|
---|
| 92 | void VectorSetTest::translateTest()
|
---|
| 93 | {
|
---|
| 94 | VECTORSET(std::vector) worklist(list);
|
---|
| 95 | Vector translater(1.,0.,0.);
|
---|
| 96 | worklist.translate(translater);
|
---|
| 97 | VECTORSET(std::vector)::const_iterator iter = list.begin();
|
---|
| 98 | VECTORSET(std::vector)::const_iterator workiter = worklist.begin();
|
---|
| 99 | for (;(iter != list.end()) && (workiter != worklist.end()); ++iter, ++workiter)
|
---|
| 100 | CPPUNIT_ASSERT( ((*iter)+(translater)) == (*workiter) );
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[f6ad4d] | 103 | /** UnitTest for transform()
|
---|
| 104 | */
|
---|
| 105 | void VectorSetTest::transformTest()
|
---|
| 106 | {
|
---|
| 107 | VECTORSET(std::vector) worklist(list);
|
---|
| 108 | RealSpaceMatrix M;
|
---|
| 109 | M.setIdentity();
|
---|
| 110 | M *= 2.;
|
---|
| 111 | worklist.transform(M);
|
---|
| 112 | VECTORSET(std::vector)::const_iterator iter = list.begin();
|
---|
| 113 | VECTORSET(std::vector)::const_iterator workiter = worklist.begin();
|
---|
| 114 | for (;(iter != list.end()) && (workiter != worklist.end()); ++iter, ++workiter)
|
---|
| 115 | CPPUNIT_ASSERT( (2.*(*iter)) == (*workiter) );
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[e23075] | 118 | /** UnitTest for minDistance()
|
---|
| 119 | */
|
---|
| 120 | void VectorSetTest::minDistanceTest()
|
---|
| 121 | {
|
---|
[f6ad4d] | 122 | VECTORSET(std::vector) worklist(list);
|
---|
[e23075] | 123 | {
|
---|
| 124 | VECTORSET(std::vector) somelist;
|
---|
| 125 | for (double x=1.;x<6.;++x)
|
---|
| 126 | somelist.push_back(Vector(x,0.,0.));
|
---|
| 127 | Vector center(0.,0.,0.);
|
---|
| 128 | Vector mindist = somelist.minDistance(center);
|
---|
| 129 | CPPUNIT_ASSERT_EQUAL (Vector(1., 0., 0.), mindist);
|
---|
[31021ab] | 130 | // check that vector has changed (by nothing)
|
---|
| 131 | for (size_t i=0;i<somelist.size();++i)
|
---|
| 132 | CPPUNIT_ASSERT_EQUAL (Vector(i+1.,0.,0.), somelist[i]);
|
---|
[e23075] | 133 | }
|
---|
| 134 | {
|
---|
| 135 | Vector center(5.,0.,0.);
|
---|
[31021ab] | 136 | VECTORSET(std::vector) somelist(worklist);
|
---|
| 137 | Vector mindist = somelist.minDistance(center);
|
---|
[e23075] | 138 | CPPUNIT_ASSERT_EQUAL (Vector(2., 1., 0.)-center, mindist);
|
---|
[31021ab] | 139 | // check that vector has changed
|
---|
| 140 | for (size_t i=0;i<somelist.size();++i)
|
---|
| 141 | CPPUNIT_ASSERT_EQUAL (somelist[i], worklist[i]-center);
|
---|
[e23075] | 142 | }
|
---|
| 143 | {
|
---|
[f6ad4d] | 144 | for (VECTORSET(std::vector)::const_iterator iter = worklist.begin();
|
---|
| 145 | iter != worklist.end(); ++iter) {
|
---|
[31021ab] | 146 | // copy list as we change it
|
---|
| 147 | VECTORSET(std::vector) somelist(worklist);
|
---|
| 148 | Vector mindist = somelist.minDistance(*iter);
|
---|
[e23075] | 149 | CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,0.), mindist );
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 |
|
---|