source: src/unittests/gslvectorunittest.cpp@ 13e3c3

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 13e3c3 was bf3817, checked in by Frederik Heber <heber@…>, 14 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

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