source: src/unittests/VectorContentUnittest.cpp@ 4c1230

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing 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_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 4c1230 was bbf1bd, checked in by Frederik Heber <heber@…>, 14 years ago

Extended VectorContent class.

  • VectorContent formerly has been just a structure to contain the gsl_vector due to forward declaration reasons.
  • now VectorContent is a true wrapper to gsl_vector, i.e. all functionality that is now specific to 3 dimensions has been shifted from GSLVector over to VectorContent.
  • VectorContentView is preserved to allow for VectorContent as a view on a row or column of a matrix.
  • changed and renamed unit test gslvectorunittest -> VectorContentUnitTest
  • GSLVector is not used anymore anywhere
  • one long-sough error was a missing assignment operator filled-in in a wrong manner by the compiler for VectorContent.

Note that:

  • gsl_vector is still used at many places
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * VectorContentUnittest.cpp
10 *
11 * Created on: Jan 8, 2010
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20using namespace std;
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25
26#include "VectorContentUnittest.hpp"
27
28#ifdef HAVE_TESTRUNNER
29#include "UnitTestMain.hpp"
30#endif /*HAVE_TESTRUNNER*/
31
32/********************************************** Test classes **************************************/
33
34// Registers the fixture into the 'registry'
35CPPUNIT_TEST_SUITE_REGISTRATION( VectorContentTest );
36
37
38void VectorContentTest::setUp()
39{
40 v = new VectorContent(3);
41};
42
43void VectorContentTest::tearDown()
44{
45 delete(v);
46};
47
48/** Unit test for accessing elements in the vector.
49 *
50 */
51void VectorContentTest::AccessTest()
52{
53 // set
54 for (int i=0;i<3;i++)
55 v->at(i) = (double)i;
56
57 // and check
58 double *ptr = NULL;
59 for (int i=0;i<3;i++) {
60 CPPUNIT_ASSERT_EQUAL( (double)i, v->at(i) );
61 ptr = v->Pointer(i);
62 CPPUNIT_ASSERT_EQUAL( (double)i, *ptr );
63 }
64
65 // out of bounds
66 //CPPUNIT_ASSERT_EQUAL(0., v->at(3) );
67 //CPPUNIT_ASSERT_EQUAL(0., v->at(-1) );
68};
69
70
71/** Unit test for initializing the vector.
72 *
73 */
74void VectorContentTest::InitializaionTest()
75{
76 // set zero
77 v->setZero();
78 for (int i=0;i<3;i++)
79 CPPUNIT_ASSERT_EQUAL( 0., v->at(i) );
80
81 // set basis
82 for (int i=0;i<3;i++) {
83 v->setBasis(i);
84 for (int j=0;j<3;j++)
85 CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , v->at(j) );
86 }
87
88 // set all
89 v->setValue(1.5);
90 for (int i=0;i<3;i++)
91 CPPUNIT_ASSERT_EQUAL( 1.5, v->at(i) );
92};
93
94/** Unit test for copying vectors.
95 *
96 */
97void VectorContentTest::CopyTest()
98{
99 // set basis
100 VectorContent *dest = NULL;
101 for (int i=0;i<3;i++) {
102 v->setBasis(i);
103 dest = new VectorContent(v);
104 for (int j=0;j<3;j++)
105 CPPUNIT_ASSERT_EQUAL( v->at(j) , dest->at(j) );
106
107 delete(dest);
108 }
109};
110
111/** Unit test for exchanging elements of a vector.
112 *
113 */
114void VectorContentTest::ExchangeTest()
115{
116 // set basis
117 for (int i=0;i<3;i++) {
118 v->setBasis(i);
119 v->SwapElements((i)%3,(i+1)%3);
120 for (int j=0;j<3;j++)
121 CPPUNIT_ASSERT_EQUAL( (i+1)%3 == j ? 1. : 0. , v->at(j) );
122 }
123
124 // set to 1,2,3 and reverse
125 for (int i=0;i<3;i++)
126 v->at(i) = (double)(i+1);
127 v->Reverse();
128 for (int j=0;j<3;j++)
129 CPPUNIT_ASSERT_EQUAL( (double)(3-j), v->at(j) );
130};
131
132/** UnitTest for operators.
133 */
134void VectorContentTest::OperatorIsTest()
135{
136 VectorContent zero(3);
137 VectorContent unit(3);
138 zero.setZero();
139 unit.setZero();
140 unit[1] = 1.;
141 // summation and scaling
142 CPPUNIT_ASSERT_EQUAL( true, unit.IsOne() );
143 CPPUNIT_ASSERT_EQUAL( false, zero.IsOne() );
144 CPPUNIT_ASSERT_EQUAL( false, unit.IsZero() );
145 CPPUNIT_ASSERT_EQUAL( true, zero.IsZero() );
146};
147
148/** UnitTest for operators.
149 */
150void VectorContentTest::OperatorAlgebraTest()
151{
152 VectorContent zero(3);
153 VectorContent unit(3);
154 zero.setZero();
155 unit.setZero();
156 unit[1] = 1.;
157 // summation and scaling
158 CPPUNIT_ASSERT_EQUAL( true, (zero+unit).IsOne() );
159 CPPUNIT_ASSERT_EQUAL( true, (zero+unit).IsOne() );
160 CPPUNIT_ASSERT_EQUAL( true, (zero-unit).IsOne() );
161 CPPUNIT_ASSERT_EQUAL( false, (zero-unit).IsZero() );
162 CPPUNIT_ASSERT_EQUAL( true, (zero+zero).IsZero() );
163 CPPUNIT_ASSERT_EQUAL( false, (unit*0.98).IsOne() );
164 CPPUNIT_ASSERT_EQUAL( false, (0.98*unit).IsOne() );
165 CPPUNIT_ASSERT_EQUAL( true, (unit*1.).IsOne() );
166 CPPUNIT_ASSERT_EQUAL( true, (1.*unit).IsOne() );
167
168 CPPUNIT_ASSERT_EQUAL( unit, (zero+unit) );
169 CPPUNIT_ASSERT_EQUAL( zero, (zero+zero) );
170 CPPUNIT_ASSERT_EQUAL( unit, (unit+zero) );
171
172 unit += zero;
173 CPPUNIT_ASSERT_EQUAL( true, unit.IsOne() );
174 unit *= 1.;
175 CPPUNIT_ASSERT_EQUAL( true, unit.IsOne() );
176};
Note: See TracBrowser for help on using the repository browser.