source: src/unittests/ActOnAllUnitTest.cpp@ 94d131

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 94d131 was 920c70, checked in by Frederik Heber <heber@…>, 15 years ago

Removed all Malloc/Calloc/ReAlloc (&Free) and replaced by new and delete/delete[].

Due to the new MemDebug framework there is no need (or even unnecessary/unwanted competition between it and) for the MemoryAllocator and ..UsageObserver anymore.
They can however still be used with c codes such as pcp and alikes.

In Molecuilder lots of glibc corruptions arose and the C-like syntax make it generally harder to get allocation and deallocation straight.

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

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