source: LinearAlgebra/src/unittests/VectorContentUnitTest.cpp@ 92bc5c

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 92bc5c was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 5.8 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-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 * VectorContentUnittest.cpp
25 *
26 * Created on: Jan 8, 2010
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35using namespace std;
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41// include headers that implement a archive in simple text format
42#include <boost/archive/text_oarchive.hpp>
43#include <boost/archive/text_iarchive.hpp>
44
45#include "VectorContentUnitTest.hpp"
46
47#ifdef HAVE_TESTRUNNER
48#include "UnitTestMain.hpp"
49#endif /*HAVE_TESTRUNNER*/
50
51/********************************************** Test classes **************************************/
52
53// Registers the fixture into the 'registry'
54CPPUNIT_TEST_SUITE_REGISTRATION( VectorContentTest );
55
56
57void VectorContentTest::setUp()
58{
59 v = new VectorContent(3);
60};
61
62void VectorContentTest::tearDown()
63{
64 delete(v);
65};
66
67/** Unit test for accessing elements in the vector.
68 *
69 */
70void VectorContentTest::AccessTest()
71{
72 // set
73 for (int i=0;i<3;i++)
74 v->at(i) = (double)i;
75
76 // and check
77 double *ptr = NULL;
78 for (int i=0;i<3;i++) {
79 CPPUNIT_ASSERT_EQUAL( (double)i, v->at(i) );
80 ptr = v->Pointer(i);
81 CPPUNIT_ASSERT_EQUAL( (double)i, *ptr );
82 }
83
84 // out of bounds
85 //CPPUNIT_ASSERT_EQUAL(0., v->at(3) );
86 //CPPUNIT_ASSERT_EQUAL(0., v->at(-1) );
87};
88
89
90/** Unit test for initializing the vector.
91 *
92 */
93void VectorContentTest::InitializaionTest()
94{
95 // set zero
96 v->setZero();
97 for (int i=0;i<3;i++)
98 CPPUNIT_ASSERT_EQUAL( 0., v->at(i) );
99
100 // set basis
101 for (int i=0;i<3;i++) {
102 v->setBasis(i);
103 for (int j=0;j<3;j++)
104 CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , v->at(j) );
105 }
106
107 // set all
108 v->setValue(1.5);
109 for (int i=0;i<3;i++)
110 CPPUNIT_ASSERT_EQUAL( 1.5, v->at(i) );
111};
112
113/** Unit test for copying vectors.
114 *
115 */
116void VectorContentTest::CopyTest()
117{
118 // set basis
119 VectorContent *dest = NULL;
120 for (int i=0;i<3;i++) {
121 v->setBasis(i);
122 dest = new VectorContent(v);
123 for (int j=0;j<3;j++)
124 CPPUNIT_ASSERT_EQUAL( v->at(j) , dest->at(j) );
125
126 delete(dest);
127 }
128};
129
130/** Unit test for exchanging elements of a vector.
131 *
132 */
133void VectorContentTest::ExchangeTest()
134{
135 // set basis
136 for (int i=0;i<3;i++) {
137 v->setBasis(i);
138 v->SwapElements((i)%3,(i+1)%3);
139 for (int j=0;j<3;j++)
140 CPPUNIT_ASSERT_EQUAL( (i+1)%3 == j ? 1. : 0. , v->at(j) );
141 }
142
143 // set to 1,2,3 and reverse
144 for (int i=0;i<3;i++)
145 v->at(i) = (double)(i+1);
146 v->Reverse();
147 for (int j=0;j<3;j++)
148 CPPUNIT_ASSERT_EQUAL( (double)(3-j), v->at(j) );
149};
150
151/** UnitTest for operators.
152 */
153void VectorContentTest::OperatorIsTest()
154{
155 VectorContent zero(3);
156 VectorContent unit(3);
157 zero.setZero();
158 unit.setZero();
159 unit[1] = 1.;
160 // summation and scaling
161 CPPUNIT_ASSERT_EQUAL( true, unit.IsOne() );
162 CPPUNIT_ASSERT_EQUAL( false, zero.IsOne() );
163 CPPUNIT_ASSERT_EQUAL( false, unit.IsZero() );
164 CPPUNIT_ASSERT_EQUAL( true, zero.IsZero() );
165};
166
167/** UnitTest for operators.
168 */
169void VectorContentTest::OperatorAlgebraTest()
170{
171 VectorContent zero(3);
172 VectorContent unit(3);
173 zero.setZero();
174 unit.setZero();
175 unit[1] = 1.;
176 // summation and scaling
177 CPPUNIT_ASSERT_EQUAL( true, (zero+unit).IsOne() );
178 CPPUNIT_ASSERT_EQUAL( true, (zero+unit).IsOne() );
179 CPPUNIT_ASSERT_EQUAL( true, (zero-unit).IsOne() );
180 CPPUNIT_ASSERT_EQUAL( false, (zero-unit).IsZero() );
181 CPPUNIT_ASSERT_EQUAL( true, (zero+zero).IsZero() );
182 CPPUNIT_ASSERT_EQUAL( false, (unit*0.98).IsOne() );
183 CPPUNIT_ASSERT_EQUAL( false, (0.98*unit).IsOne() );
184 CPPUNIT_ASSERT_EQUAL( true, (unit*1.).IsOne() );
185 CPPUNIT_ASSERT_EQUAL( true, (1.*unit).IsOne() );
186
187 CPPUNIT_ASSERT_EQUAL( unit, (zero+unit) );
188 CPPUNIT_ASSERT_EQUAL( zero, (zero+zero) );
189 CPPUNIT_ASSERT_EQUAL( unit, (unit+zero) );
190
191 unit += zero;
192 CPPUNIT_ASSERT_EQUAL( true, unit.IsOne() );
193 unit *= 1.;
194 CPPUNIT_ASSERT_EQUAL( true, unit.IsOne() );
195};
196
197/** Unit test for reading from and writing vector to stream
198 *
199 */
200void VectorContentTest::ReadWriteTest()
201{
202 // set up matrix
203 VectorContent v((size_t)3);
204 for (size_t i=0; i<3;++i)
205 v.at(i) = i+1.;
206
207 // write to stream
208 std::stringstream vectorstream;
209 v.write(vectorstream);
210
211 // parse in dimensions and check
212 size_t vectordimension = VectorContent::preparseVectorDimensions(vectorstream);
213 CPPUNIT_ASSERT_EQUAL( (size_t)3, vectordimension );
214 // parse in vector and check
215 VectorContent w(3, vectorstream);
216 CPPUNIT_ASSERT_EQUAL( v, w );
217}
218
219/** UnitTest for serialization.
220 */
221void VectorContentTest::SerializationTest()
222{
223 v->setZero();
224 (*v)[0] = 0.;
225 (*v)[1] = 1.;
226 (*v)[2] = 2.;
227 // write element to stream
228 std::stringstream stream;
229 boost::archive::text_oarchive oa(stream);
230 oa << v;
231
232 //std::cout << "Contents of archive is " << stream.str() << std::endl;
233
234 // create and open an archive for input
235 boost::archive::text_iarchive ia(stream);
236 // read class state from archive
237 VectorContent *newv;
238
239 ia >> newv;
240
241 CPPUNIT_ASSERT (*v == *newv);
242}
Note: See TracBrowser for help on using the repository browser.