source: src/unittests/ActOnAllUnitTest.cpp@ 9cd807

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 9cd807 was bf3817, checked in by Frederik Heber <heber@…>, 15 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.5 KB
RevLine 
[aba92d]1/*
2 * ActOnAllUnitTest.cpp
3 *
4 * Created on: 04.10.2009
5 * Author: FrederikHeber
6 */
7
[bf3817]8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
[aba92d]13using namespace std;
14
15#include <cppunit/CompilerOutputter.h>
16#include <cppunit/extensions/TestFactoryRegistry.h>
17#include <cppunit/ui/text/TestRunner.h>
18
[46ea3b]19#include "../test/ActOnAlltest.hpp"
[aba92d]20#include "ActOnAllUnitTest.hpp"
[57f243]21#include "LinearAlgebra/Vector.hpp"
[aba92d]22
[9b6b2f]23#ifdef HAVE_TESTRUNNER
24#include "UnitTestMain.hpp"
25#endif /*HAVE_TESTRUNNER*/
26
[aba92d]27/********************************************** Test classes **************************************/
28
29// Registers the fixture into the 'registry'
30CPPUNIT_TEST_SUITE_REGISTRATION( ActOnAllTest );
31
32
33void ActOnAllTest::setUp()
34{
35 Vector *temp = NULL;
36 // fill list with vectors
37 temp = new Vector(1,0,0);
38 VL.AddVector(temp);
39 temp = new Vector(0,1,0);
40 VL.AddVector(temp);
41 temp = new Vector(0,0,1);
42 VL.AddVector(temp);
[33f9f7]43 Ref = VL;
[aba92d]44};
45
46
47void ActOnAllTest::tearDown()
48{
49 VL.EmptyList();
[f72703]50 // Ref was copy constructed, hence has to be cleaned, too!
51 Ref.EmptyList();
[aba92d]52};
53
[eaee7f]54/** UnitTest for VectorList::ActOnAll() and Vector::AddVector(), Vector::SubtractVector(),
[33f9f7]55 */
56void ActOnAllTest::AddSubtractTest()
57{
58 const Vector test(1.,0.,0.);
59
60 // adding, subtracting
[273382]61 VL.ActOnAll( &Vector::AddVector, test );
[33f9f7]62 CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
[273382]63 VL.ActOnAll( &Vector::SubtractVector, test );
[33f9f7]64 CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
65};
66
[eaee7f]67/** UnitTest for VectorList::ActOnAll()
[aba92d]68 */
[33f9f7]69void ActOnAllTest::ScaleTest()
70{
71 double factor=2.;
72 double inverse=1./2.;
73
74 // scaling by value
[1bd79e]75 VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, factor );
[33f9f7]76 CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
77
[1bd79e]78 VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, inverse );
[33f9f7]79 CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
80
81 // scaling by three values
[920c70]82 double *factors = new double[NDIM];
83 double *inverses = new double[NDIM];
[33f9f7]84 for (int i=0;i<NDIM;++i) {
85 factors[i] = 2.;
86 inverses[i] = 1./factors[i];
87 }
[1bd79e]88 VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, factors );
[33f9f7]89 CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
90
[1bd79e]91 VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, inverses );
[33f9f7]92 CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
[920c70]93 delete[](factors);
94 delete[](inverses);
[33f9f7]95};
96
[0a4f7f]97#if 0
98
99// Unitttest deactivated for now...
100// Reasons:
101// Vector::MakeNormalVector has been removed and is now part of Plane class
102// VectorList::ActOnAll is in the test directory and seems to be used only for unittests
103// MakeNormal never depended on the input Vector except in the case of linear dependence (i.e. failure)
104//
105// TODO: Rethink what exactely is being tested at this point and introduce a new unittest for the
106// tested behaviour. Most likely this should result in a thourough unittest of the plane class
107
[eaee7f]108/** UnitTest for VectorList::ActOnAll() and Vector::MakeNormalVector()
[33f9f7]109 */
110void ActOnAllTest::NormalizeTest()
[aba92d]111{
[33f9f7]112 const Vector xaxis(1.,0.,0.);
113 const Vector yaxis(0.,1.,0.);
114
115 // normalize with respect to x and y axis
116 bool (Vector::*f)(const Vector *, const Vector *) = &Vector::MakeNormalVector;
[eaee7f]117 VL.ActOnAll( f, &xaxis, &yaxis );
[33f9f7]118 CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
119
120 // check that x and y components are zero
121 for (ListOfVectors::iterator Runner = VL.Vectors.begin(); Runner != VL.Vectors.end(); Runner++) {
[0a4f7f]122 CPPUNIT_ASSERT_EQUAL( (*Runner)->at(0) , 0. );
123 CPPUNIT_ASSERT_EQUAL( (*Runner)->at(1) , 0. );
[33f9f7]124 }
[aba92d]125};
[0a4f7f]126
127#endif
Note: See TracBrowser for help on using the repository browser.