source: src/unittests/ActOnAllUnitTest.cpp@ 8c5327

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 8c5327 was 776b64, checked in by Frederik Heber <heber@…>, 15 years ago

Huge refactoring to make const what is const (ticket #38), continued.

  • too many changes because of too many cross-references to be able to list them up here.
  • NOTE that "make check" runs fine and did catch several error.
  • note that we had to use const_iterator several times when the map, ... was declared const.
  • at times we changed an allocated LinkedCell LCList(...) into

const LinkedCell *LCList;
LCList = new LinkedCell(...);

  • also mutable (see ticket #5) was used, e.g. for molecule::InternalPointer (PointCloud changes are allowed, because they are just accounting).

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * ActOnAllUnitTest.cpp
3 *
4 * Created on: 04.10.2009
5 * Author: FrederikHeber
6 */
7
8using namespace std;
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#include "ActOnAlltest.hpp"
15#include "ActOnAllUnitTest.hpp"
16#include "memoryallocator.hpp"
17
18/********************************************** Test classes **************************************/
19
20// Registers the fixture into the 'registry'
21CPPUNIT_TEST_SUITE_REGISTRATION( ActOnAllTest );
22
23
24void ActOnAllTest::setUp()
25{
26 Vector *temp = NULL;
27 // fill list with vectors
28 temp = new Vector(1,0,0);
29 VL.AddVector(temp);
30 temp = new Vector(0,1,0);
31 VL.AddVector(temp);
32 temp = new Vector(0,0,1);
33 VL.AddVector(temp);
34 Ref = VL;
35};
36
37
38void ActOnAllTest::tearDown()
39{
40 VL.EmptyList();
41};
42
43/** UnitTest for VectorList::ActOnAll() and Vector::AddVector(), Vector::SubtractVector(),
44 */
45void ActOnAllTest::AddSubtractTest()
46{
47 const Vector test(1.,0.,0.);
48
49 // adding, subtracting
50 VL.ActOnAll( &Vector::AddVector, &test );
51 CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
52 VL.ActOnAll( &Vector::SubtractVector, &test );
53 CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
54};
55
56/** UnitTest for VectorList::ActOnAll()
57 */
58void ActOnAllTest::ScaleTest()
59{
60 double factor=2.;
61 double inverse=1./2.;
62
63 // scaling by value
64 VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, 2. );
65 CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
66
67 VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, 0.5 );
68 CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
69
70 // scaling by ref
71 VL.ActOnAll( (void (Vector::*)(const double * const)) &Vector::Scale, (const double * const)&factor );
72 CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
73
74 VL.ActOnAll( (void (Vector::*)(const double * const)) &Vector::Scale, (const double * const)&inverse );
75 CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
76
77 // scaling by three values
78 double *factors = Malloc<double>(NDIM, "ActOnAllTest::ScaleTest - factors");
79 double *inverses = Malloc<double>(NDIM, "ActOnAllTest::ScaleTest - inverses");
80 for (int i=0;i<NDIM;++i) {
81 factors[i] = 2.;
82 inverses[i] = 1./factors[i];
83 }
84 VL.ActOnAll( (void (Vector::*)(const double ** const)) &Vector::Scale, (const double ** const)&factors );
85 CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
86
87 VL.ActOnAll( (void (Vector::*)(const double ** const)) &Vector::Scale, (const double ** const)&inverses );
88 CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
89};
90
91/** UnitTest for VectorList::ActOnAll() and Vector::MakeNormalVector()
92 */
93void ActOnAllTest::NormalizeTest()
94{
95 const Vector xaxis(1.,0.,0.);
96 const Vector yaxis(0.,1.,0.);
97
98 // normalize with respect to x and y axis
99 bool (Vector::*f)(const Vector *, const Vector *) = &Vector::MakeNormalVector;
100 VL.ActOnAll( f, &xaxis, &yaxis );
101 CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
102
103 // check that x and y components are zero
104 for (ListOfVectors::iterator Runner = VL.Vectors.begin(); Runner != VL.Vectors.end(); Runner++) {
105 CPPUNIT_ASSERT_EQUAL( (*Runner)->x[0] , 0. );
106 CPPUNIT_ASSERT_EQUAL( (*Runner)->x[1] , 0. );
107 }
108};
109
110
111/********************************************** Main routine **************************************/
112
113int main(int argc, char **argv)
114{
115 // Get the top level suite from the registry
116 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
117
118 // Adds the test to the list of test to run
119 CppUnit::TextUi::TestRunner runner;
120 runner.addTest( suite );
121
122 // Change the default outputter to a compiler error format outputter
123 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
124 std::cerr ) );
125 // Run the tests.
126 bool wasSucessful = runner.run();
127
128 // Return error code 1 if the one of test failed.
129 return wasSucessful ? 0 : 1;
130};
Note: See TracBrowser for help on using the repository browser.