Changeset 257c77 for src/unittests


Ignore:
Timestamp:
Jun 17, 2010, 2:55:56 PM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Branches:
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, Candidate_v1.7.0, Candidate_v1.7.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
Children:
b47bfc
Parents:
992fd7 (diff), 5f5a7b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'stable' into QT4Refactoring

Conflicts:

molecuilder/src/Actions/TesselationAction/ConvexEnvelopeAction.hpp
molecuilder/src/Helpers/MemDebug.hpp
molecuilder/src/Makefile.am
molecuilder/src/UIElements/Dialog.cpp
molecuilder/src/UIElements/MainWindow.cpp
molecuilder/src/UIElements/TextUI/TextUIFactory.cpp
molecuilder/src/builder.cpp

Location:
src/unittests
Files:
6 added
30 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/ActOnAllUnitTest.cpp

    r992fd7 r257c77  
    4646  // Ref was copy constructed, hence has to be cleaned, too!
    4747  Ref.EmptyList();
    48   MemoryUsageObserver::purgeInstance();
    4948};
    5049
     
    7776
    7877  // scaling by three values
    79   double *factors = Malloc<double>(NDIM, "ActOnAllTest::ScaleTest - factors");
    80   double *inverses = Malloc<double>(NDIM, "ActOnAllTest::ScaleTest - inverses");
     78  double *factors = new double[NDIM];
     79  double *inverses = new double[NDIM];
    8180  for (int i=0;i<NDIM;++i) {
    8281    factors[i] = 2.;
     
    8887  VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, inverses );
    8988  CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
    90   Free(factors);
    91   Free(inverses);
     89  delete[](factors);
     90  delete[](inverses);
    9291};
    9392
  • src/unittests/AnalysisCorrelationToPointUnitTest.cpp

    r992fd7 r257c77  
    1717#include "AnalysisCorrelationToPointUnitTest.hpp"
    1818
    19 #include "World.hpp"
    2019#include "atom.hpp"
    21 #include "boundary.hpp"
    2220#include "element.hpp"
    2321#include "molecule.hpp"
    2422#include "linkedcell.hpp"
    2523#include "periodentafel.hpp"
    26 #include "tesselation.hpp"
    2724#include "World.hpp"
    2825
     
    4340  TestList = NULL;
    4441  TestMolecule = NULL;
    45   hydrogen = NULL;
    46   tafel = NULL;
    4742  pointmap = NULL;
    4843  binmap = NULL;
    4944  point = NULL;
    5045
    51   // construct element
    52   hydrogen = new element;
    53   hydrogen->Z = 1;
    54   strcpy(hydrogen->name, "hydrogen");
    55   strcpy(hydrogen->symbol, "H");
    56 
    57 
    58   // construct periodentafel
    59   tafel = World::getInstance().getPeriode();
    60   tafel->AddElement(hydrogen);
    61 
     46  // construct element list
     47  std::vector<element *> elements;
     48  hydrogen = World::getInstance().getPeriode()->FindElement(1);
     49  CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
     50  elements.push_back(hydrogen);
    6251  // construct molecule (tetraeder of hydrogens)
    6352  TestMolecule = World::getInstance().createMolecule();
     
    8069
    8170  // check that TestMolecule was correctly constructed
    82   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
     71  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
    8372
    8473  TestList = World::getInstance().getMolecules();
     
    9079
    9180  // init maps
    92   pointmap = CorrelationToPoint( (MoleculeListClass * const)TestList, (const element * const)hydrogen, (const Vector *)point );
     81  pointmap = CorrelationToPoint( (MoleculeListClass * const)TestList, elements, (const Vector *)point );
    9382  binmap = NULL;
    9483
     
    10594  delete(point);
    10695  World::purgeInstance();
    107   MemoryUsageObserver::purgeInstance();
    10896  logger::purgeInstance();
    10997};
  • src/unittests/AnalysisCorrelationToPointUnitTest.hpp

    r992fd7 r257c77  
    1212
    1313class element;
    14 class LinkedCell;
    1514class molecule;
    1615class MoleculeListClass;
    17 class periodentafel;
    18 class Tesselation;
    1916class Vector;
    2017
     
    4138      molecule *TestMolecule;
    4239      element *hydrogen;
    43       periodentafel *tafel;
    4440
    4541      CorrelationToPointMap *pointmap;
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    r992fd7 r257c77  
    1717#include "AnalysisCorrelationToSurfaceUnitTest.hpp"
    1818
    19 #include "World.hpp"
    2019#include "atom.hpp"
    2120#include "boundary.hpp"
     
    2625#include "tesselation.hpp"
    2726#include "World.hpp"
     27#include "Helpers/Assert.hpp"
    2828
    2929#include "Helpers/Assert.hpp"
     
    4040void AnalysisCorrelationToSurfaceUnitTest::setUp()
    4141{
    42   //ASSERT_DO(Assert::Throw);
     42  ASSERT_DO(Assert::Throw);
    4343
    4444  atom *Walker = NULL;
     
    4747  TestList = NULL;
    4848  TestSurfaceMolecule = NULL;
    49   hydrogen = NULL;
    50   tafel = NULL;
    5149  surfacemap = NULL;
    5250  binmap = NULL;
     
    5452  LC = NULL;
    5553
    56   // construct element
    57   hydrogen = new element;
    58   hydrogen->Z = 1;
    59   strcpy(hydrogen->name, "hydrogen");
    60   strcpy(hydrogen->symbol, "H");
    61   carbon = new element;
    62   carbon->Z = 6;
    63   strcpy(carbon->name, "carbon");
    64   strcpy(carbon->symbol, "C");
    65 
    66   // construct periodentafel
    67   tafel = World::getInstance().getPeriode();
    68   tafel->AddElement(hydrogen);
    69   tafel->AddElement(carbon);
     54  // prepare element list
     55  hydrogen = World::getInstance().getPeriode()->FindElement(1);
     56  CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
     57  elements.clear();
    7058
    7159  // construct molecule (tetraeder of hydrogens) base
    7260  TestSurfaceMolecule = World::getInstance().createMolecule();
     61
    7362  Walker = World::getInstance().createAtom();
    7463  Walker->type = hydrogen;
    7564  *Walker->node = Vector(1., 0., 1. );
    76 
    77   TestSurfaceMolecule->AddAtom(Walker);
     65  TestSurfaceMolecule->AddAtom(Walker);
     66
    7867  Walker = World::getInstance().createAtom();
    7968  Walker->type = hydrogen;
    8069  *Walker->node = Vector(0., 1., 1. );
    8170  TestSurfaceMolecule->AddAtom(Walker);
     71
    8272  Walker = World::getInstance().createAtom();
    8373  Walker->type = hydrogen;
    8474  *Walker->node = Vector(1., 1., 0. );
    8575  TestSurfaceMolecule->AddAtom(Walker);
     76
    8677  Walker = World::getInstance().createAtom();
    8778  Walker->type = hydrogen;
     
    9081
    9182  // check that TestMolecule was correctly constructed
    92   CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->AtomCount, 4 );
     83  CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->getAtomCount(), 4 );
    9384
    9485  TestList = World::getInstance().getMolecules();
     
    10293
    10394  // add outer atoms
     95  carbon = World::getInstance().getPeriode()->FindElement(6);
    10496  TestSurfaceMolecule = World::getInstance().createMolecule();
    10597  Walker = World::getInstance().createAtom();
     
    10799  *Walker->node = Vector(4., 0., 4. );
    108100  TestSurfaceMolecule->AddAtom(Walker);
     101
    109102  Walker = World::getInstance().createAtom();
    110103  Walker->type = carbon;
    111104  *Walker->node = Vector(0., 4., 4. );
    112105  TestSurfaceMolecule->AddAtom(Walker);
     106
    113107  Walker = World::getInstance().createAtom();
    114108  Walker->type = carbon;
    115109  *Walker->node = Vector(4., 4., 0. );
    116110  TestSurfaceMolecule->AddAtom(Walker);
     111
    117112  // add inner atoms
    118113  Walker = World::getInstance().createAtom();
     
    120115  *Walker->node = Vector(0.5, 0.5, 0.5 );
    121116  TestSurfaceMolecule->AddAtom(Walker);
     117
    122118  TestSurfaceMolecule->ActiveFlag = true;
    123119  TestList->insert(TestSurfaceMolecule);
     
    141137  delete(LC);
    142138  World::purgeInstance();
    143   MemoryUsageObserver::purgeInstance();
    144139  logger::purgeInstance();
    145140};
     
    150145void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest()
    151146{
    152   CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->AtomCount );
     147  CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->getAtomCount() );
    153148  CPPUNIT_ASSERT_EQUAL( (size_t)2, TestList->ListOfMolecules.size() );
    154149  CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
     
    160155{
    161156  // do the pair correlation
    162   surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
     157  elements.push_back(hydrogen);
     158  surfacemap = CorrelationToSurface( TestList, elements, Surface, LC );
    163159//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    164160  CPPUNIT_ASSERT( surfacemap != NULL );
     
    169165{
    170166  BinPairMap::iterator tester;
    171   surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
     167  elements.push_back(hydrogen);
     168  surfacemap = CorrelationToSurface( TestList, elements, Surface, LC );
    172169  // put pair correlation into bins and check with no range
    173170//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
     
    184181{
    185182  BinPairMap::iterator tester;
    186   surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
     183  elements.push_back(hydrogen);
     184  surfacemap = CorrelationToSurface( TestList, elements, Surface, LC );
    187185//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    188186  // ... and check with [0., 2.] range
     
    202200{
    203201  BinPairMap::iterator tester;
    204   surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
     202  elements.push_back(carbon);
     203  surfacemap = CorrelationToSurface( TestList, elements, Surface, LC );
    205204//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    206205  // put pair correlation into bins and check with no range
     
    221220{
    222221  BinPairMap::iterator tester;
    223   surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
     222  elements.push_back(carbon);
     223  surfacemap = CorrelationToSurface( TestList, elements, Surface, LC );
    224224//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    225225  // ... and check with [0., 2.] range
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.hpp

    r992fd7 r257c77  
    4747      element *hydrogen;
    4848      element *carbon;
    49       periodentafel *tafel;
     49      std::vector<element *> elements;
    5050
    5151      CorrelationToSurfaceMap *surfacemap;
  • src/unittests/AnalysisPairCorrelationUnitTest.cpp

    r992fd7 r257c77  
    4444  TestList = NULL;
    4545  TestMolecule = NULL;
    46   hydrogen = NULL;
    47   tafel = NULL;
    4846  correlationmap = NULL;
    4947  binmap = NULL;
    5048
    51   // construct element
    52   hydrogen = new element;
    53   hydrogen->Z = 1;
    54   strcpy(hydrogen->name, "hydrogen");
    55   strcpy(hydrogen->symbol, "H");
    56 
    57   // construct periodentafel
    58   tafel = World::getInstance().getPeriode();
    59   tafel->AddElement(hydrogen);
     49  // construct element list
     50  std::vector<element *> elements;
     51  hydrogen = World::getInstance().getPeriode()->FindElement(1);
     52  CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
     53  elements.push_back(hydrogen);
     54  elements.push_back(hydrogen);
    6055
    6156  // construct molecule (tetraeder of hydrogens)
     
    7974
    8075  // check that TestMolecule was correctly constructed
    81   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
     76  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
    8277
    8378  TestList = World::getInstance().getMolecules();
     
    8681
    8782  // init maps
    88   correlationmap = PairCorrelation( TestList, hydrogen, hydrogen );
     83  correlationmap = PairCorrelation( TestList, elements);
    8984  binmap = NULL;
    9085
     
    10196  // note that all the atoms are cleaned by TestMolecule
    10297  World::purgeInstance();
    103   MemoryUsageObserver::purgeInstance();
    10498  logger::purgeInstance();
    10599  errorLogger::purgeInstance();
  • src/unittests/AnalysisPairCorrelationUnitTest.hpp

    r992fd7 r257c77  
    1212
    1313class element;
    14 class LinkedCell;
    1514class molecule;
    1615class MoleculeListClass;
    17 class periodentafel;
    18 class Tesselation;
    1916class Vector;
    2017
     
    4138      molecule *TestMolecule;
    4239      element *hydrogen;
    43       periodentafel *tafel;
    4440
    4541      PairCorrelationMap *correlationmap;
  • src/unittests/CacheableTest.cpp

    r992fd7 r257c77  
    5555
    5656  threeNumbers(int _x,int _y, int _z) :
     57    Observable("threeNumbers"),
    5758    x(_x),y(_y),z(_z),
    58     sum(this,boost::bind(&threeNumbers::calcSum,this)),
     59    sum(this,boost::bind(&threeNumbers::calcSum,this),"sum"),
    5960    hasRecalced(false)
    6061  {}
     
    8182  CPPUNIT_ASSERT_EQUAL( 9, *(numbers->sum));
    8283  CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced);
     84  numbers->hasRecalced=false;
     85  CPPUNIT_ASSERT_EQUAL( 9, *(numbers->sum));
     86#ifndef NO_CACHING
     87  CPPUNIT_ASSERT_EQUAL( false, numbers->hasRecalced);
     88#else
     89  CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced);
     90#endif
    8391}
  • src/unittests/CountBondsUnitTest.cpp

    r992fd7 r257c77  
    1616#include <stdio.h>
    1717#include <cstring>
     18
     19#include "Helpers/Assert.hpp"
    1820
    1921#include "analysis_bonds.hpp"
     
    4042{
    4143  atom *Walker = NULL;
    42   BG = NULL;
    43   filename = NULL;
    44 
    45   // init private all pointers to zero
    46   molecules = NULL;
    47   TestMolecule1 = NULL;
    48   TestMolecule2 = NULL;
    49   hydrogen = NULL;
    50   oxygen = NULL;
    51   tafel = NULL;
    5244
    5345  // construct element
    54   hydrogen = new element;
    55   hydrogen->Z = 1;
    56   hydrogen->CovalentRadius = 0.23;
    57   strcpy(hydrogen->name, "hydrogen");
    58   strcpy(hydrogen->symbol, "H");
    59   oxygen = new element;
    60   oxygen->Z = 8;
    61   oxygen->CovalentRadius = 0.68;
    62   strcpy(oxygen->name, "oxygen");
    63   strcpy(oxygen->symbol, "O");
    64 
    65   // construct periodentafel
    66   tafel = World::getInstance().getPeriode();
    67   tafel->AddElement(hydrogen);
    68   tafel->AddElement(oxygen);
     46  hydrogen = World::getInstance().getPeriode()->FindElement(1);
     47  oxygen = World::getInstance().getPeriode()->FindElement(8);
     48  CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
     49  CPPUNIT_ASSERT(oxygen != NULL && "could not find element oxygen");
    6950
    7051  // construct molecule (water molecule)
    7152  TestMolecule1 = World::getInstance().createMolecule();
    72   Walker = World::getInstance().createAtom();
     53  CPPUNIT_ASSERT(TestMolecule1 != NULL && "could not create first molecule");
     54  Walker = World::getInstance().createAtom();
     55  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    7356  Walker->type = hydrogen;
    7457  *Walker->node = Vector(-0.2418, 0.9350, 0. );
    7558  TestMolecule1->AddAtom(Walker);
    7659  Walker = World::getInstance().createAtom();
     60  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    7761  Walker->type = hydrogen;
    7862  *Walker->node = Vector(0.9658, 0., 0. );
    7963  TestMolecule1->AddAtom(Walker);
    8064  Walker = World::getInstance().createAtom();
     65  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    8166  Walker->type = oxygen;
    8267  *Walker->node = Vector(0., 0., 0. );
     
    8469
    8570  TestMolecule2 = World::getInstance().createMolecule();
    86   Walker = World::getInstance().createAtom();
     71  CPPUNIT_ASSERT(TestMolecule2 != NULL && "could not create second molecule");
     72  Walker = World::getInstance().createAtom();
     73  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    8774  Walker->type = hydrogen;
    8875  *Walker->node = Vector(-0.2418, 0.9350, 0. );
    8976  TestMolecule2->AddAtom(Walker);
    9077  Walker = World::getInstance().createAtom();
     78  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    9179  Walker->type = hydrogen;
    9280  *Walker->node = Vector(0.9658, 0., 0. );
    9381  TestMolecule2->AddAtom(Walker);
    9482  Walker = World::getInstance().createAtom();
     83  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    9584  Walker->type = oxygen;
    9685  *Walker->node = Vector(0., 0., 0. );
     
    9887
    9988  molecules = World::getInstance().getMolecules();
     89  CPPUNIT_ASSERT(molecules != NULL && "could not obtain list of molecules");
    10090  molecules->insert(TestMolecule1);
    10191  molecules->insert(TestMolecule2);
    10292
    10393  // check that TestMolecule was correctly constructed
    104   CPPUNIT_ASSERT_EQUAL( TestMolecule1->AtomCount, 3 );
    105   Walker = TestMolecule1->start->next;
    106   CPPUNIT_ASSERT( TestMolecule1->end != Walker );
    107   CPPUNIT_ASSERT_EQUAL( TestMolecule2->AtomCount, 3 );
    108   Walker = TestMolecule2->start->next;
    109   CPPUNIT_ASSERT( TestMolecule2->end != Walker );
     94  CPPUNIT_ASSERT_EQUAL( TestMolecule1->getAtomCount(), 3 );
     95  CPPUNIT_ASSERT_EQUAL( TestMolecule2->getAtomCount(), 3 );
    11096
    11197  // create a small file with table
    11298  BG = new BondGraph(true);
     99  CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
    113100
    114101  // construct bond graphs
     
    126113
    127114  World::purgeInstance();
    128   MemoryUsageObserver::purgeInstance();
    129115};
    130116
     
    158144{
    159145  double *mirror = new double[3];
     146  CPPUNIT_ASSERT(mirror != NULL && "could not create array of doubles");
    160147  for (int i=0;i<3;i++)
    161148    mirror[i] = -1.;
  • src/unittests/CountBondsUnitTest.hpp

    r992fd7 r257c77  
    3939      molecule *TestMolecule1;
    4040      molecule *TestMolecule2;
    41       element *hydrogen;
    42       element *oxygen;
    43       periodentafel *tafel;
     41      const element *hydrogen;
     42      const element *oxygen;
    4443
    4544      BondGraph *BG;
  • src/unittests/LinkedCellUnitTest.cpp

    r992fd7 r257c77  
    3838  atom *Walker = NULL;
    3939
    40   // init private all pointers to zero
    41   TestMolecule = NULL;
    42   hydrogen = NULL;
    43   tafel = NULL;
    44 
    4540  // construct element
    46   hydrogen = new element;
    47   hydrogen->Z = 1;
    48   hydrogen->CovalentRadius = 0.23;
    49   strcpy(hydrogen->name, "hydrogen");
    50   strcpy(hydrogen->symbol, "H");
    51 
    52   // construct periodentafel
    53   tafel = World::getInstance().getPeriode();
    54   tafel->AddElement(hydrogen);
     41  hydrogen = World::getInstance().getPeriode()->FindElement(1);
     42  CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
    5543
    5644  // construct molecule (water molecule)
    5745  TestMolecule = World::getInstance().createMolecule();
     46  CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
    5847  for (double x=0.5;x<3;x+=1.)
    5948    for (double y=0.5;y<3;y+=1.)
    6049      for (double z=0.5;z<3;z+=1.) {
    6150        Walker = World::getInstance().createAtom();
     51        CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    6252        Walker->type = hydrogen;
    6353        *Walker->node = Vector(x, y, z );
     
    6757  // construct linked cell
    6858  LC = new LinkedCell (TestMolecule, 1.);
     59  CPPUNIT_ASSERT(LC != NULL && "could not create LinkedCell");
    6960
    7061  // check that TestMolecule was correctly constructed
    71   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 3*3*3 );
    72   Walker = TestMolecule->start->next;
    73   CPPUNIT_ASSERT( TestMolecule->end != Walker );
     62  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 3*3*3 );
    7463};
    7564
     
    7968  delete(LC);
    8069  World::purgeInstance();
    81   MemoryUsageObserver::purgeInstance();
    8270};
    8371
     
    197185{
    198186  // check all atoms
    199   atom *Walker = TestMolecule->start;
    200   while (Walker->next != TestMolecule->end) {
    201     Walker = Walker->next;
    202     CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToNode(Walker) );
     187  for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end();++iter){
     188    CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToNode(*iter) );
    203189  }
    204190
    205191  // check internal vectors, returns false, because this atom is not in LC-list!
    206   Walker = World::getInstance().createAtom();
    207   Walker->setName("test");
    208   Walker->x= Vector(1,1,1);
    209   CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
    210   World::getInstance().destroyAtom(Walker);
     192  atom *newAtom = World::getInstance().createAtom();
     193  newAtom->setName("test");
     194  newAtom->x= Vector(1,1,1);
     195  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(newAtom) );
     196  World::getInstance().destroyAtom(newAtom);
    211197
    212198  // check out of bounds vectors
    213   Walker = World::getInstance().createAtom();
    214   Walker->setName("test");
    215   Walker->x = Vector(0,-1,0);
    216   CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
    217   World::getInstance().destroyAtom(Walker);
     199  newAtom = World::getInstance().createAtom();
     200  newAtom->setName("test");
     201  newAtom->x = Vector(0,-1,0);
     202  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(newAtom) );
     203  World::getInstance().destroyAtom(newAtom);
    218204};
    219205
     
    287273  size = ListOfPoints->size();
    288274  CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
    289   Walker = TestMolecule->start;
    290   Walker = TestMolecule->start;
    291   while (Walker->next != TestMolecule->end) {
    292     Walker = Walker->next;
    293     ListOfPoints->remove(Walker);
     275
     276  for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end(); ++iter){
     277    ListOfPoints->remove((*iter));
    294278    size--;
    295279    CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
     
    306290  size=ListOfPoints->size();
    307291  CPPUNIT_ASSERT_EQUAL( (size_t)8, size );
    308   Walker = TestMolecule->start;
    309   while (Walker->next != TestMolecule->end) {
    310     Walker = Walker->next;
    311     if ((Walker->x[0] <2) && (Walker->x[1] <2) && (Walker->x[2] <2)) {
    312       ListOfPoints->remove(Walker);
     292  for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end(); ++iter){
     293    if (((*iter)->x[0] <2) && ((*iter)->x[1] <2) && ((*iter)->x[2] <2)) {
     294      ListOfPoints->remove(*iter);
    313295      size--;
    314296      CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
     
    326308  size=ListOfPoints->size();
    327309  CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
    328   Walker = TestMolecule->start;
    329   while (Walker->next != TestMolecule->end) {
    330     Walker = Walker->next;
    331     ListOfPoints->remove(Walker);
     310  for(molecule::iterator iter = TestMolecule->begin(); iter!=TestMolecule->end();++iter){
     311    ListOfPoints->remove(*iter);
    332312    size--;
    333313    CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
     
    355335  size = ListOfPoints->size();
    356336  CPPUNIT_ASSERT_EQUAL( (size_t)7, size );
    357   Walker = TestMolecule->start;
    358   while (Walker->next != TestMolecule->end) {
    359     Walker = Walker->next;
    360     if ((Walker->x.DistanceSquared(tester) - 1.) < MYEPSILON ) {
    361       ListOfPoints->remove(Walker);
     337  for(molecule::iterator iter = TestMolecule->begin(); iter!=TestMolecule->end();++iter){
     338    if (((*iter)->x.DistanceSquared(tester) - 1.) < MYEPSILON ) {
     339      ListOfPoints->remove(*iter);
    362340      size--;
    363341      CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
  • src/unittests/LinkedCellUnitTest.hpp

    r992fd7 r257c77  
    4848
    4949      molecule *TestMolecule;
    50       element *hydrogen;
    51       periodentafel *tafel;
     50      const element *hydrogen;
    5251      LinkedCell *LC;
    5352};
  • src/unittests/Makefile.am

    r992fd7 r257c77  
     1# PLEASE adhere to the alphabetical ordering in this Makefile!
     2# Also indentation by a single tab
     3
    14INCLUDES = -I$(top_srcdir)/src
    25
     
    3134  MemoryAllocatorUnitTest \
    3235  MoleculeDescriptorTest \
     36  ObserverTest \
     37  ParserUnitTest \
     38  periodentafelTest \
    3339  PlaneUnittest \
    34   ObserverTest \
    3540  SingletonTest \
    3641  StackClassUnitTest \
     
    7378  memoryusageobserverunittest.cpp \
    7479  MoleculeDescriptorTest.cpp \
     80  ObserverTest.cpp \
     81  ParserUnitTest.cpp \
     82  periodentafelTest.cpp \
    7583  PlaneUnittest.cpp \
    76   ObserverTest.cpp \
    7784  SingletonTest.cpp \
    7885  stackclassunittest.cpp \
     
    107114  memoryusageobserverunittest.hpp \
    108115  MoleculeDescriptorTest.hpp \
     116  periodentafelTest.hpp \
    109117  PlaneUnittest.hpp \
    110118  ObserverTest.hpp \
     
    117125 
    118126
     127ActionSequenceTest_SOURCES = UnitTestMain.cpp ../../../TestRunnerClient.hpp ActionSequenceTest.cpp ActionSequenceTest.hpp
     128ActionSequenceTest_LDADD = ${ALLLIBS}
     129
    119130ActOnAllUnitTest_SOURCES = UnitTestMain.cpp ../test/ActOnAllTest.hpp ActOnAllUnitTest.cpp ActOnAllUnitTest.hpp
    120131ActOnAllUnitTest_LDADD = ${ALLLIBS}
     
    135146atomsCalculationTest_LDADD = ${ALLLIBS}
    136147
     148AtomDescriptorTest_SOURCES = UnitTestMain.cpp AtomDescriptorTest.cpp AtomDescriptorTest.hpp
     149AtomDescriptorTest_LDADD = ${ALLLIBS}
     150
    137151BondGraphUnitTest_SOURCES = UnitTestMain.cpp bondgraphunittest.cpp bondgraphunittest.hpp
    138152BondGraphUnitTest_LDADD = ${ALLLIBS}
    139153
     154CacheableTest_SOURCES = UnitTestMain.cpp CacheableTest.cpp CacheableTest.hpp
     155CacheableTest_LDADD = ${ALLLIBS}
     156
    140157CountBondsUnitTest_SOURCES = UnitTestMain.cpp CountBondsUnitTest.cpp CountBondsUnitTest.hpp
    141158CountBondsUnitTest_LDADD = ${ALLLIBS}
     
    168185LogUnitTest_LDADD = ${ALLLIBS}
    169186
    170 MemoryAllocatorUnitTest_SOURCES = UnitTestMain.cpp memoryallocatorunittest.cpp memoryallocatorunittest.hpp
     187manipulateAtomsTest_SOURCES = UnitTestMain.cpp manipulateAtomsTest.cpp manipulateAtomsTest.hpp
     188manipulateAtomsTest_LDADD = ${ALLLIBS}
     189
     190MemoryAllocatorUnitTest_SOURCES = UnitTestMain.cpp ../memoryallocator.hpp ../memoryallocator.cpp ../memoryusageobserver.cpp ../memoryusageobserver.hpp memoryallocatorunittest.cpp memoryallocatorunittest.hpp
    171191MemoryAllocatorUnitTest_LDADD = ${ALLLIBS}
    172192
    173 MemoryUsageObserverUnitTest_SOURCES = UnitTestMain.cpp memoryusageobserverunittest.cpp memoryusageobserverunittest.hpp
     193MemoryUsageObserverUnitTest_SOURCES = UnitTestMain.cpp ../memoryallocator.hpp ../memoryusageobserver.cpp ../memoryusageobserver.hpp memoryusageobserverunittest.cpp memoryusageobserverunittest.hpp
    174194MemoryUsageObserverUnitTest_LDADD = ${ALLLIBS}
    175195
     
    177197MoleculeDescriptorTest_LDADD = ${ALLLIBS}
    178198
     199ObserverTest_SOURCES = UnitTestMain.cpp ObserverTest.cpp ObserverTest.hpp
     200ObserverTest_LDADD = ${ALLLIBS}
     201
     202ParserUnitTest_SOURCES = UnitTestMain.cpp ParserUnitTest.cpp ParserUnitTest.hpp
     203ParserUnitTest_LDADD = ${ALLLIBS}
     204
     205periodentafelTest_SOURCES = UnitTestMain.cpp periodentafelTest.cpp periodentafelTest.hpp
     206periodentafelTest_LDADD = ${ALLLIBS}
     207
    179208PlaneUnittest_SOURCES = UnitTestMain.cpp PlaneUnittest.cpp PlaneUnittest.hpp
    180209PlaneUnittest_LDADD = ${ALLLIBS}
     
    195224Tesselation_InOutsideUnitTest_LDADD = ${ALLLIBS}
    196225
     226TestRunner_SOURCES = TestRunnerMain.cpp ../memoryallocator.hpp ../memoryallocator.cpp ../memoryusageobserver.cpp ../memoryusageobserver.hpp $(TESTSOURCES) $(TESTHEADERS)
     227TestRunner_LDADD = ${ALLLIBS}
     228
    197229VectorUnitTest_SOURCES = UnitTestMain.cpp vectorunittest.cpp vectorunittest.hpp
    198230VectorUnitTest_LDADD = ${ALLLIBS}
    199231
    200 ActionSequenceTest_SOURCES = UnitTestMain.cpp ../../../TestRunnerClient.hpp ActionSequenceTest.cpp ActionSequenceTest.hpp
    201 ActionSequenceTest_LDADD = ${ALLLIBS}
    202 
    203 ObserverTest_SOURCES = UnitTestMain.cpp ObserverTest.cpp ObserverTest.hpp
    204 ObserverTest_LDADD = ${ALLLIBS}
    205 
    206 CacheableTest_SOURCES = UnitTestMain.cpp CacheableTest.cpp CacheableTest.hpp
    207 CacheableTest_LDADD = ${ALLLIBS}
    208 
    209 AtomDescriptorTest_SOURCES = UnitTestMain.cpp AtomDescriptorTest.cpp AtomDescriptorTest.hpp
    210 AtomDescriptorTest_LDADD = ${ALLLIBS}
    211 
    212 manipulateAtomsTest_SOURCES = UnitTestMain.cpp manipulateAtomsTest.cpp manipulateAtomsTest.hpp
    213 manipulateAtomsTest_LDADD = ${ALLLIBS}
    214 
    215 TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS)
    216 TestRunner_LDADD = ${ALLLIBS}
    217 
    218232#AUTOMAKE_OPTIONS = parallel-tests
    219 
  • src/unittests/ObserverTest.cpp

    r992fd7 r257c77  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
     13#include <set>
    1314
    1415#include "Patterns/Observer.hpp"
     16#include "Patterns/ObservedIterator.hpp"
    1517#include "Helpers/Assert.hpp"
    1618
     
    3133public:
    3234  UpdateCountObserver() :
     35    Observer("UpdateCountObserver"),
    3336    updates(0)
    3437  {};
     
    4346class SimpleObservable : public Observable {
    4447public:
     48  SimpleObservable() :
     49    Observable("SimpleObservable")
     50  {}
     51
    4552  void changeMethod() {
    4653    OBSERVE;
     
    5259class CallObservable : public Observable {
    5360public:
     61  CallObservable() :
     62    Observable("CallObservable")
     63  {}
     64
    5465  void changeMethod1() {
    5566    OBSERVE;
     
    6879class BlockObservable : public Observable {
    6980public:
     81  BlockObservable() :
     82    Observable("BlockObservable")
     83  {}
     84
    7085  void changeMethod1(){
    7186    OBSERVE;
     
    102117class SuperObservable : public Observable {
    103118public:
    104   SuperObservable(){
     119  SuperObservable():
     120    Observable("SuperObservable")
     121  {
    105122    subObservable = new SimpleObservable();
    106123    subObservable->signOn(this);
     
    121138public:
    122139  NotificationObservable() :
    123       notification1(new Notification(this)),
    124       notification2(new Notification(this))
     140    Observable("NotificationObservable"),
     141    notification1(new Notification(this)),
     142    notification2(new Notification(this))
    125143  {}
    126144
     
    147165public:
    148166  NotificationObserver(Notification_ptr notification) :
     167    Observer("NotificationObserver"),
    149168    requestedNotification(notification),
    150169    wasNotified(false)
     
    162181  bool wasNotified;
    163182};
     183
     184class ObservableCollection : public Observable {
     185public:
     186  typedef std::set<SimpleObservable*> set;
     187  typedef ObservedIterator<set> iterator;
     188  typedef set::const_iterator const_iterator;
     189
     190  ObservableCollection(int _num) :
     191    Observable("ObservableCollection"),
     192    num(_num)
     193  {
     194    for(int i=0; i<num; ++i){
     195      SimpleObservable *content = new SimpleObservable();
     196      content->signOn(this);
     197      theSet.insert(content);
     198    }
     199  }
     200
     201  ~ObservableCollection(){
     202    set::iterator iter;
     203    for(iter=theSet.begin(); iter!=theSet.end(); ++iter ){
     204      delete (*iter);
     205    }
     206  }
     207
     208  iterator begin(){
     209    return iterator(theSet.begin(),this);
     210  }
     211
     212  iterator end(){
     213    return iterator(theSet.end(),this);
     214  }
     215
     216  const int num;
     217
     218private:
     219  set theSet;
     220};
     221
    164222
    165223/******************* actuall tests ***************/
     
    173231  blockObservable = new BlockObservable();
    174232  notificationObservable = new NotificationObservable();
     233  collection = new ObservableCollection(5);
    175234
    176235  observer1 = new UpdateCountObserver();
     
    181240  notificationObserver1 = new NotificationObserver(notificationObservable->notification1);
    182241  notificationObserver2 = new NotificationObserver(notificationObservable->notification2);
    183 
    184242}
    185243
     
    191249  delete blockObservable;
    192250  delete notificationObservable;
     251  delete collection;
    193252
    194253  delete observer1;
     
    277336  blockObservable->changeMethod2();
    278337  blockObservable->noChangeMethod();
     338}
     339
     340void ObserverTest::iteratorTest(){
     341  int i = 0;
     342  // test the general iterator methods
     343  for(ObservableCollection::iterator iter=collection->begin(); iter!=collection->end();++iter){
     344    CPPUNIT_ASSERT(i< collection->num);
     345    i++;
     346  }
     347
     348  i=0;
     349  for(ObservableCollection::const_iterator iter=collection->begin(); iter!=collection->end();++iter){
     350    CPPUNIT_ASSERT(i<collection->num);
     351    i++;
     352  }
     353
     354  collection->signOn(observer1);
     355  {
     356    // we construct this out of the loop, so the iterator dies at the end of
     357    // the scope and not the end of the loop (allows more testing)
     358    ObservableCollection::iterator iter;
     359    for(iter=collection->begin(); iter!=collection->end(); ++iter){
     360      (*iter)->changeMethod();
     361    }
     362    // At this point no change should have been propagated
     363    CPPUNIT_ASSERT_EQUAL( 0, observer1->updates);
     364  }
     365  // After the Iterator has died the propagation should take place
     366  CPPUNIT_ASSERT_EQUAL( 1, observer1->updates);
     367
     368  // when using a const_iterator no changes should be propagated
     369  for(ObservableCollection::const_iterator iter = collection->begin(); iter!=collection->end();++iter);
     370  CPPUNIT_ASSERT_EQUAL( 1, observer1->updates);
     371  collection->signOff(observer1);
    279372}
    280373
  • src/unittests/ObserverTest.hpp

    r992fd7 r257c77  
    1717class CallObservable;
    1818class SuperObservable;
     19class ObservableCollection;
    1920class BlockObservable;
    2021class NotificationObservable;
    21 
    2222
    2323class ObserverTest :  public CppUnit::TestFixture
     
    2929  CPPUNIT_TEST ( doesNotifyTest );
    3030  CPPUNIT_TEST ( doesReportTest );
     31  CPPUNIT_TEST ( iteratorTest );
    3132  CPPUNIT_TEST ( CircleDetectionTest );
    3233  CPPUNIT_TEST_SUITE_END();
     
    4142  void doesNotifyTest();
    4243  void doesReportTest();
     44  void iteratorTest();
    4345  void CircleDetectionTest();
    4446
     
    5860  SuperObservable *superObservable;
    5961  NotificationObservable *notificationObservable;
     62  ObservableCollection *collection;
     63
    6064};
    6165
  • src/unittests/SingletonTest.cpp

    r992fd7 r257c77  
    5252    count1++;
    5353  }
    54   // explicit copy constructor to catch if thsi is ever called
     54  // explicit copy constructor to catch if this is ever called
    5555  SingletonStub2(const SingletonStub2&){
    5656    CPPUNIT_FAIL    ( "Copy constructor of Singleton called" );
  • src/unittests/TestRunnerMain.cpp

    r992fd7 r257c77  
    66 */
    77
     8// include config.h
     9#ifdef HAVE_CONFIG_H
     10#include <config.h>
     11#endif
     12
     13#ifdef HAVE_ECUT
    814// give the main function its correct name
    915#define CPPUNIT_MAIN main
    10 
    1116// include the TestRunnerClient file containing the main class
    1217#include "../../../TestRunnerClient.h"
    1318#include "../../../TestRunnerClient.cpp"
     19#else
     20#include "UnitTestMain.cpp"
     21#endif
     22
  • src/unittests/analysisbondsunittest.cpp

    r992fd7 r257c77  
    2525#include "molecule.hpp"
    2626#include "periodentafel.hpp"
     27#include "World.hpp"
    2728
    2829#ifdef HAVE_TESTRUNNER
     
    4041  atom *Walker = NULL;
    4142
    42   // init private all pointers to zero
    43   TestMolecule = NULL;
    44   hydrogen = NULL;
    45   tafel = NULL;
    46 
    47   // construct element
    48   hydrogen = new element;
    49   hydrogen->Z = 1;
    50   hydrogen->Valence = 1;
    51   hydrogen->NoValenceOrbitals = 1;
    52   strcpy(hydrogen->name, "hydrogen");
    53   strcpy(hydrogen->symbol, "H");
    54   carbon = new element;
    55   carbon->Z = 2;
    56   carbon->Valence = 4;
    57   carbon->NoValenceOrbitals = 4;
    58   strcpy(carbon->name, "carbon");
    59   strcpy(carbon->symbol, "C");
    60 
    61 
    62   // construct periodentafel
    63   tafel = World::getInstance().getPeriode();
    64   tafel->AddElement(hydrogen);
    65   tafel->AddElement(carbon);
     43  // get elements
     44  hydrogen = World::getInstance().getPeriode()->FindElement(1);
     45  carbon = World::getInstance().getPeriode()->FindElement(6);
     46  CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
     47  CPPUNIT_ASSERT(carbon != NULL && "could not find element carbon");
    6648
    6749  // construct molecule (tetraeder of hydrogens)
    6850  TestMolecule = World::getInstance().createMolecule();
     51  CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
    6952  Walker = World::getInstance().createAtom();
     53  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    7054  Walker->type = hydrogen;
    7155  *Walker->node = Vector(1.5, 0., 1.5 );
    7256  TestMolecule->AddAtom(Walker);
    7357  Walker = World::getInstance().createAtom();
     58  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    7459  Walker->type = hydrogen;
    7560  *Walker->node = Vector(0., 1.5, 1.5 );
    7661  TestMolecule->AddAtom(Walker);
    7762  Walker = World::getInstance().createAtom();
     63  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    7864  Walker->type = hydrogen;
    7965  *Walker->node = Vector(1.5, 1.5, 0. );
    8066  TestMolecule->AddAtom(Walker);
    8167  Walker = World::getInstance().createAtom();
     68  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    8269  Walker->type = hydrogen;
    8370  *Walker->node = Vector(0., 0., 0. );
    8471  TestMolecule->AddAtom(Walker);
    8572  Walker = World::getInstance().createAtom();
     73  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    8674  Walker->type = carbon;
    8775  *Walker->node = Vector(0.5, 0.5, 0.5 );
     
    8977
    9078  // check that TestMolecule was correctly constructed
    91   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 5 );
     79  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 5 );
    9280
    9381  // create a small file with table
    9482  filename = new string("test.dat");
     83  CPPUNIT_ASSERT(filename != NULL && "could not create string");
    9584  ofstream test(filename->c_str());
    96   test << ".\tH\tC\n";
    97   test << "H\t1.\t1.2\n";
    98   test << "C\t1.2\t1.5\n";
     85  test << ".\tH\tHe\tLi\tBe\tB\tC\n";
     86  test << "H\t1.\t1.\t1.\t1.\t1.\t1.2\n";
     87  test << "He\t1.\t1.\t1.\t1.\t1.\t1.\n";
     88  test << "Li\t1.\t1.\t1.\t1.\t1.\t1.\n";
     89  test << "Be\t1.\t1.\t1.\t1.\t1.\t1.\n";
     90  test << "B\t1.\t1.\t1.\t1.\t1.\t1.\n";
     91  test << "C\t1.2\t1.\t1.\t1.\t1.\t1.5\n";
    9992  test.close();
    10093  BG = new BondGraph(true);
     94  CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
    10195
    10296  CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
    10397  CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
    104   CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
    105   CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
     98  CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) );
     99  CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(5,5) );
    106100
    107101  BG->ConstructBondGraph(TestMolecule);
  • src/unittests/analysisbondsunittest.hpp

    r992fd7 r257c77  
    3434
    3535      molecule *TestMolecule;
    36       element *hydrogen;
    37       element *carbon;
    38       periodentafel *tafel;
     36      const element *hydrogen;
     37      const element *carbon;
    3938
    4039      BondGraph *BG;
  • src/unittests/bondgraphunittest.cpp

    r992fd7 r257c77  
    1515#include <stdio.h>
    1616#include <cstring>
     17
     18#include "Helpers/Assert.hpp"
    1719
    1820#include "World.hpp"
     
    4143  atom *Walker = NULL;
    4244
    43   // init private all pointers to zero
    44   TestMolecule = NULL;
    45   hydrogen = NULL;
    46   tafel = NULL;
    47 
    4845  // construct element
    49   hydrogen = new element;
    50   hydrogen->Z = 1;
    51   hydrogen->CovalentRadius = 0.23;
    52   hydrogen->VanDerWaalsRadius = 1.09;
    53   strcpy(hydrogen->name, "hydrogen");
    54   strcpy(hydrogen->symbol, "H");
    55   carbon = new element;
    56   carbon->Z = 2;
    57   carbon->CovalentRadius = 0.68;
    58   carbon->VanDerWaalsRadius = 1.7;
    59   strcpy(carbon->name, "carbon");
    60   strcpy(carbon->symbol, "C");
    61 
    62 
    63   // construct periodentafel
    64   tafel = World::getInstance().getPeriode();
    65   tafel->AddElement(hydrogen);
    66   tafel->AddElement(carbon);
     46  hydrogen = World::getInstance().getPeriode()->FindElement(1);
     47  carbon = World::getInstance().getPeriode()->FindElement(6);
     48  CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
     49  CPPUNIT_ASSERT(carbon != NULL && "could not find element carbon");
    6750
    6851  // construct molecule (tetraeder of hydrogens)
    6952  TestMolecule = World::getInstance().createMolecule();
     53  CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
    7054  Walker = World::getInstance().createAtom();
     55  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    7156  Walker->type = carbon;
    7257  *Walker->node = Vector(1., 0., 1. );
     
    7459
    7560  Walker = World::getInstance().createAtom();
     61  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    7662  Walker->type = carbon;
    7763  *Walker->node = Vector(0., 1., 1. );
     
    7965
    8066  Walker = World::getInstance().createAtom();
     67  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    8168  Walker->type = carbon;
    8269  *Walker->node = Vector(1., 1., 0. );
     
    8471
    8572  Walker = World::getInstance().createAtom();
     73  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    8674  Walker->type = carbon;
    8775  *Walker->node = Vector(0., 0., 0. );
     
    8977
    9078  // check that TestMolecule was correctly constructed
    91   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
     79  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
    9280
    9381  // create a small file with table
    9482  dummyname = new string("dummy.dat");
     83  CPPUNIT_ASSERT(dummyname != NULL && "could not create string");
    9584  filename = new string("test.dat");
     85  CPPUNIT_ASSERT(filename != NULL && "could not create string");
    9686  ofstream test(filename->c_str());
    97   test << ".\tH\tC\n";
    98   test << "H\t1.\t1.2\n";
    99   test << "C\t1.2\t1.5\n";
     87  test << ".\tH\tHe\tLi\tBe\tB\tC\n";
     88  test << "H\t1.\t1.\t1.\t1.\t1.\t1.2\n";
     89  test << "He\t1.\t1.\t1.\t1.\t1.\t1.\n";
     90  test << "Li\t1.\t1.\t1.\t1.\t1.\t1.\n";
     91  test << "Be\t1.\t1.\t1.\t1.\t1.\t1.\n";
     92  test << "B\t1.\t1.\t1.\t1.\t1.\t1.\n";
     93  test << "C\t1.2\t1.\t1.\t1.\t1.\t1.5\n";
    10094  test.close();
    10195  BG = new BondGraph(true);
     96  CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
    10297};
    10398
     
    116111  // are all cleaned when the world is destroyed
    117112  World::purgeInstance();
    118   MemoryUsageObserver::purgeInstance();
    119113  logger::purgeInstance();
     114};
     115
     116/** Tests whether setup worked.
     117 */
     118void BondGraphTest::SetupTest()
     119{
     120  CPPUNIT_ASSERT_EQUAL (false, TestMolecule->empty());
     121  CPPUNIT_ASSERT_EQUAL ((size_t)4, TestMolecule->size());
    120122};
    121123
     
    126128  CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
    127129  CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
    128   CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
    129   CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
     130  CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) );
     131  CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(5,5) );
    130132};
    131133
     
    134136void BondGraphTest::ConstructGraphFromTableTest()
    135137{
    136   atom *Walker = TestMolecule->start->next;
    137   atom *Runner = TestMolecule->end->previous;
    138   CPPUNIT_ASSERT( TestMolecule->end != Walker );
     138  molecule::iterator Walker = TestMolecule->begin();
     139  molecule::iterator Runner = TestMolecule->begin();
     140  Runner++;
    139141  CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
    140142  CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
    141   CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
     143  CPPUNIT_ASSERT_EQUAL( true , (*Walker)->IsBondedTo((*Runner)) );
    142144};
    143145
     
    146148void BondGraphTest::ConstructGraphFromCovalentRadiiTest()
    147149{
    148   atom *Walker = TestMolecule->start->next;
    149   atom *Runner = TestMolecule->end->previous;
    150   CPPUNIT_ASSERT( TestMolecule->end != Walker );
     150
     151  //atom *Walker = TestMolecule->start->next;
     152  //atom *Runner = TestMolecule->end->previous;
     153  //CPPUNIT_ASSERT( TestMolecule->end != Walker );
    151154  CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(*dummyname) );
    152155  CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
    153   CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
     156
     157  // this cannot be assured using dynamic IDs
     158  //CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
    154159};
    155160
  • src/unittests/bondgraphunittest.hpp

    r992fd7 r257c77  
    2222{
    2323    CPPUNIT_TEST_SUITE( BondGraphTest) ;
     24    CPPUNIT_TEST ( SetupTest );
    2425    CPPUNIT_TEST ( LoadTableTest );
    2526    CPPUNIT_TEST ( ConstructGraphFromTableTest );
     
    3031      void setUp();
    3132      void tearDown();
     33      void SetupTest();
    3234      void LoadTableTest();
    3335      void ConstructGraphFromTableTest();
     
    3739
    3840      molecule *TestMolecule;
    39       element *hydrogen;
    40       element *carbon;
    41       periodentafel *tafel;
     41      const element *hydrogen;
     42      const element *carbon;
    4243
    4344      BondGraph *BG;
  • src/unittests/listofbondsunittest.cpp

    r992fd7 r257c77  
    3838  atom *Walker = NULL;
    3939
    40   // init private all pointers to zero
    41   TestMolecule = NULL;
    42   hydrogen = NULL;
    43   tafel = NULL;
    44 
    4540  // construct element
    46   hydrogen = new element;
    47   hydrogen->Z = 1;
    48   strcpy(hydrogen->name, "hydrogen");
    49   strcpy(hydrogen->symbol, "H");
    50 
    51 
    52   // construct periodentafel
    53   tafel = World::getInstance().getPeriode();
    54   tafel->AddElement(hydrogen);
     41  hydrogen = World::getInstance().getPeriode()->FindElement(1);
     42  CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
    5543
    5644  // construct molecule (tetraeder of hydrogens)
    5745  TestMolecule = World::getInstance().createMolecule();
    58   Walker = World::getInstance().createAtom();
     46  CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
     47  Walker = World::getInstance().createAtom();
     48  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    5949  Walker->type = hydrogen;
    6050  *Walker->node = Vector(1., 0., 1. );
    6151  TestMolecule->AddAtom(Walker);
    6252  Walker = World::getInstance().createAtom();
     53  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    6354  Walker->type = hydrogen;
    6455  *Walker->node = Vector(0., 1., 1. );
    6556  TestMolecule->AddAtom(Walker);
    6657  Walker = World::getInstance().createAtom();
     58  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    6759  Walker->type = hydrogen;
    6860  *Walker->node = Vector(1., 1., 0. );
    6961  TestMolecule->AddAtom(Walker);
    7062  Walker = World::getInstance().createAtom();
     63  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    7164  Walker->type = hydrogen;
    7265  *Walker->node = Vector(0., 0., 0. );
     
    7467
    7568  // check that TestMolecule was correctly constructed
    76   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    77 
     69  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
    7870};
    7971
     
    8678  // are all cleaned when the world is destroyed
    8779  World::purgeInstance();
    88   MemoryUsageObserver::purgeInstance();
    8980  logger::purgeInstance();
    9081};
    9182
     83/** Tests whether setup worked correctly.
     84 *
     85 */
     86void ListOfBondsTest::SetupTest()
     87{
     88  CPPUNIT_ASSERT_EQUAL( false, TestMolecule->empty() );
     89  CPPUNIT_ASSERT_EQUAL( (size_t)4, TestMolecule->size() );
     90};
     91
    9292/** Unit Test of molecule::AddBond()
    9393 *
     
    9696{
    9797  bond *Binder = NULL;
    98   atom *atom1 = TestMolecule->start->next;
    99   atom *atom2 = atom1->next;
    100   CPPUNIT_ASSERT( atom1 != NULL );
    101   CPPUNIT_ASSERT( atom2 != NULL );
    102 
    103   // add bond
    104   Binder = TestMolecule->AddBond(atom1, atom2, 1);
    105   CPPUNIT_ASSERT( Binder != NULL );
    106   bond *TestBond = TestMolecule->first->next;
    107   CPPUNIT_ASSERT_EQUAL ( TestBond, Binder );
     98  molecule::iterator iter = TestMolecule->begin();
     99  atom *atom1 = *iter;
     100  iter++;
     101  atom *atom2 = *iter;
     102  CPPUNIT_ASSERT( atom1 != NULL );
     103  CPPUNIT_ASSERT( atom2 != NULL );
     104
     105  // add bond
     106  Binder = TestMolecule->AddBond(atom1, atom2, 1);
     107  CPPUNIT_ASSERT( Binder != NULL );
     108  CPPUNIT_ASSERT_EQUAL ( true, TestMolecule->hasBondStructure() );
    108109
    109110  // check that bond contains the two atoms
     
    124125{
    125126  bond *Binder = NULL;
    126   atom *atom1 = TestMolecule->start->next;
    127   atom *atom2 = atom1->next;
     127  molecule::iterator iter = TestMolecule->begin();
     128  atom *atom1 = *iter;
     129  iter++;
     130  atom *atom2 = *iter;
    128131  CPPUNIT_ASSERT( atom1 != NULL );
    129132  CPPUNIT_ASSERT( atom2 != NULL );
     
    141144
    142145  // check if removed from molecule
    143   CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
     146  CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
    144147};
    145148
     
    150153{
    151154  bond *Binder = NULL;
    152   atom *atom1 = TestMolecule->start->next;
    153   atom *atom2 = atom1->next;
    154   atom *atom3 = atom2->next;
     155  molecule::iterator iter = TestMolecule->begin();
     156  atom *atom1 = *iter;
     157  iter++;
     158  atom *atom2 = *iter;
     159  iter++;
     160  atom *atom3 = *iter;
    155161  CPPUNIT_ASSERT( atom1 != NULL );
    156162  CPPUNIT_ASSERT( atom2 != NULL );
     
    179185
    180186  // check if removed from molecule
    181   CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, Binder );
    182   CPPUNIT_ASSERT_EQUAL( Binder->next, TestMolecule->last );
     187  CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
     188  CPPUNIT_ASSERT_EQUAL( (unsigned int)1, TestMolecule->CountBonds() );
    183189};
    184190
     
    189195{
    190196  bond *Binder = NULL;
    191   atom *atom1 = TestMolecule->start->next;
    192   atom *atom2 = atom1->next;
     197  molecule::iterator iter = TestMolecule->begin();
     198  atom *atom1 = *iter;
     199  iter++;
     200  atom *atom2 = *iter;
    193201  CPPUNIT_ASSERT( atom1 != NULL );
    194202  CPPUNIT_ASSERT( atom2 != NULL );
     
    206214
    207215  // check if removed from molecule
    208   CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
     216  CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
    209217};
    210218
     
    215223{
    216224  bond *Binder = NULL;
    217   atom *atom1 = TestMolecule->start->next;
    218   atom *atom2 = atom1->next;
     225  molecule::iterator iter = TestMolecule->begin();
     226  atom *atom1 = *iter;
     227  iter++;
     228  atom *atom2 = *iter;
    219229  CPPUNIT_ASSERT( atom1 != NULL );
    220230  CPPUNIT_ASSERT( atom2 != NULL );
     
    231241
    232242  // check if removed from molecule
    233   CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
     243  CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
    234244};
    235245
     
    239249void ListOfBondsTest::DeleteAtomTest()
    240250{
    241   bond *Binder = NULL;
    242   atom *atom1 = TestMolecule->start->next;
    243   atom *atom2 = atom1->next;
    244   CPPUNIT_ASSERT( atom1 != NULL );
    245   CPPUNIT_ASSERT( atom2 != NULL );
    246 
    247   // add bond
    248   Binder = TestMolecule->AddBond(atom1, atom2, 1);
    249   CPPUNIT_ASSERT( Binder != NULL );
     251  atom *atom1 = NULL;
     252  atom *atom2 = NULL;
     253  bond *Binder = NULL;
     254  {
     255    molecule::iterator iter = TestMolecule->begin();
     256    atom1 = *iter;
     257    iter++;
     258    atom2 = *iter;
     259  }
     260  CPPUNIT_ASSERT( atom1 != NULL );
     261  CPPUNIT_ASSERT( atom2 != NULL );
     262
     263  // add bond
     264  Binder = TestMolecule->AddBond(atom1, atom2, 1);
     265  CPPUNIT_ASSERT( Binder != NULL );
     266
     267  CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom1->ListOfBonds.size() );
     268  CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->ListOfBonds.size() );
     269
     270  CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
    250271
    251272  // remove atom2
     
    256277
    257278  // check if removed from molecule
    258   CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
    259 };
     279  CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
     280};
  • src/unittests/listofbondsunittest.hpp

    r992fd7 r257c77  
    2020{
    2121    CPPUNIT_TEST_SUITE( ListOfBondsTest) ;
     22    CPPUNIT_TEST ( SetupTest );
    2223    CPPUNIT_TEST ( AddingBondTest );
    2324    CPPUNIT_TEST ( RemovingBondTest );
     
    3132      void setUp();
    3233      void tearDown();
     34      void SetupTest();
    3335      void AddingBondTest();
    3436      void RemovingBondTest();
     
    4143
    4244      molecule *TestMolecule;
    43       element *hydrogen;
    44       periodentafel *tafel;
     45      const element *hydrogen;
    4546};
    4647
  • src/unittests/manipulateAtomsTest.cpp

    r992fd7 r257c77  
    5555public:
    5656  countObserver() :
     57    Observer("countObserver"),
    5758    count(0)
    5859    {}
  • src/unittests/memoryallocatorunittest.cpp

    r992fd7 r257c77  
    1212#include "memoryallocator.hpp"
    1313#include "memoryallocatorunittest.hpp"
     14#include "memoryusageobserver.hpp"
    1415#include "helpers.hpp"
    1516#include "log.hpp"
  • src/unittests/stackclassunittest.cpp

    r992fd7 r257c77  
    3737  Stack->ClearStack();
    3838  delete(Stack);
    39   MemoryUsageObserver::purgeInstance();
    4039  logger::purgeInstance();
    4140};
  • src/unittests/tesselation_boundarytriangleunittest.cpp

    r992fd7 r257c77  
    7070    delete tesselpoints[i];
    7171  }
    72   MemoryUsageObserver::purgeInstance();
    7372  logger::purgeInstance();
    7473  errorLogger::purgeInstance();
  • src/unittests/tesselation_insideoutsideunittest.cpp

    r992fd7 r257c77  
    134134  }
    135135  Corners.clear();
    136   MemoryUsageObserver::purgeInstance();
    137136  logger::purgeInstance();
    138137  errorLogger::purgeInstance();
  • src/unittests/tesselationunittest.cpp

    r992fd7 r257c77  
    106106  }
    107107  Corners.clear();
    108   MemoryUsageObserver::purgeInstance();
    109108  logger::purgeInstance();
    110109  errorLogger::purgeInstance();
  • src/unittests/vectorunittest.cpp

    r992fd7 r257c77  
    4949void VectorTest::tearDown()
    5050{
    51   MemoryUsageObserver::purgeInstance();
    5251  logger::purgeInstance();
    5352  errorLogger::purgeInstance();
Note: See TracChangeset for help on using the changeset viewer.