Changeset 257c77 for src/unittests
- Timestamp:
- Jun 17, 2010, 2:55:56 PM (16 years ago)
- 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. - Location:
- src/unittests
- Files:
-
- 6 added
- 30 edited
-
ActOnAllUnitTest.cpp (modified) (3 diffs)
-
AnalysisCorrelationToPointUnitTest.cpp (modified) (5 diffs)
-
AnalysisCorrelationToPointUnitTest.hpp (modified) (2 diffs)
-
AnalysisCorrelationToSurfaceUnitTest.cpp (modified) (16 diffs)
-
AnalysisCorrelationToSurfaceUnitTest.hpp (modified) (1 diff)
-
AnalysisPairCorrelationUnitTest.cpp (modified) (4 diffs)
-
AnalysisPairCorrelationUnitTest.hpp (modified) (2 diffs)
-
CacheableTest.cpp (modified) (2 diffs)
-
CountBondsUnitTest.cpp (modified) (6 diffs)
-
CountBondsUnitTest.hpp (modified) (1 diff)
-
LinkedCellUnitTest.cpp (modified) (8 diffs)
-
LinkedCellUnitTest.hpp (modified) (1 diff)
-
Makefile.am (modified) (9 diffs)
-
MapofActionsTest.cpp (added)
-
MapofActionsTest.hpp (added)
-
ObserverTest.cpp (modified) (13 diffs)
-
ObserverTest.hpp (modified) (4 diffs)
-
ParserUnitTest.cpp (added)
-
ParserUnitTest.hpp (added)
-
SingletonTest.cpp (modified) (1 diff)
-
TestRunnerMain.cpp (modified) (1 diff)
-
analysisbondsunittest.cpp (modified) (3 diffs)
-
analysisbondsunittest.hpp (modified) (1 diff)
-
bondgraphunittest.cpp (modified) (10 diffs)
-
bondgraphunittest.hpp (modified) (3 diffs)
-
listofbondsunittest.cpp (modified) (14 diffs)
-
listofbondsunittest.hpp (modified) (3 diffs)
-
manipulateAtomsTest.cpp (modified) (1 diff)
-
memoryallocatorunittest.cpp (modified) (1 diff)
-
periodentafelTest.cpp (added)
-
periodentafelTest.hpp (added)
-
stackclassunittest.cpp (modified) (1 diff)
-
tesselation_boundarytriangleunittest.cpp (modified) (1 diff)
-
tesselation_insideoutsideunittest.cpp (modified) (1 diff)
-
tesselationunittest.cpp (modified) (1 diff)
-
vectorunittest.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/ActOnAllUnitTest.cpp
r992fd7 r257c77 46 46 // Ref was copy constructed, hence has to be cleaned, too! 47 47 Ref.EmptyList(); 48 MemoryUsageObserver::purgeInstance();49 48 }; 50 49 … … 77 76 78 77 // 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]; 81 80 for (int i=0;i<NDIM;++i) { 82 81 factors[i] = 2.; … … 88 87 VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, inverses ); 89 88 CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); 90 Free(factors);91 Free(inverses);89 delete[](factors); 90 delete[](inverses); 92 91 }; 93 92 -
src/unittests/AnalysisCorrelationToPointUnitTest.cpp
r992fd7 r257c77 17 17 #include "AnalysisCorrelationToPointUnitTest.hpp" 18 18 19 #include "World.hpp"20 19 #include "atom.hpp" 21 #include "boundary.hpp"22 20 #include "element.hpp" 23 21 #include "molecule.hpp" 24 22 #include "linkedcell.hpp" 25 23 #include "periodentafel.hpp" 26 #include "tesselation.hpp"27 24 #include "World.hpp" 28 25 … … 43 40 TestList = NULL; 44 41 TestMolecule = NULL; 45 hydrogen = NULL;46 tafel = NULL;47 42 pointmap = NULL; 48 43 binmap = NULL; 49 44 point = NULL; 50 45 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); 62 51 // construct molecule (tetraeder of hydrogens) 63 52 TestMolecule = World::getInstance().createMolecule(); … … 80 69 81 70 // check that TestMolecule was correctly constructed 82 CPPUNIT_ASSERT_EQUAL( TestMolecule-> AtomCount, 4 );71 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 ); 83 72 84 73 TestList = World::getInstance().getMolecules(); … … 90 79 91 80 // 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 ); 93 82 binmap = NULL; 94 83 … … 105 94 delete(point); 106 95 World::purgeInstance(); 107 MemoryUsageObserver::purgeInstance();108 96 logger::purgeInstance(); 109 97 }; -
src/unittests/AnalysisCorrelationToPointUnitTest.hpp
r992fd7 r257c77 12 12 13 13 class element; 14 class LinkedCell;15 14 class molecule; 16 15 class MoleculeListClass; 17 class periodentafel;18 class Tesselation;19 16 class Vector; 20 17 … … 41 38 molecule *TestMolecule; 42 39 element *hydrogen; 43 periodentafel *tafel;44 40 45 41 CorrelationToPointMap *pointmap; -
src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
r992fd7 r257c77 17 17 #include "AnalysisCorrelationToSurfaceUnitTest.hpp" 18 18 19 #include "World.hpp"20 19 #include "atom.hpp" 21 20 #include "boundary.hpp" … … 26 25 #include "tesselation.hpp" 27 26 #include "World.hpp" 27 #include "Helpers/Assert.hpp" 28 28 29 29 #include "Helpers/Assert.hpp" … … 40 40 void AnalysisCorrelationToSurfaceUnitTest::setUp() 41 41 { 42 //ASSERT_DO(Assert::Throw);42 ASSERT_DO(Assert::Throw); 43 43 44 44 atom *Walker = NULL; … … 47 47 TestList = NULL; 48 48 TestSurfaceMolecule = NULL; 49 hydrogen = NULL;50 tafel = NULL;51 49 surfacemap = NULL; 52 50 binmap = NULL; … … 54 52 LC = NULL; 55 53 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(); 70 58 71 59 // construct molecule (tetraeder of hydrogens) base 72 60 TestSurfaceMolecule = World::getInstance().createMolecule(); 61 73 62 Walker = World::getInstance().createAtom(); 74 63 Walker->type = hydrogen; 75 64 *Walker->node = Vector(1., 0., 1. ); 76 77 TestSurfaceMolecule->AddAtom(Walker); 65 TestSurfaceMolecule->AddAtom(Walker); 66 78 67 Walker = World::getInstance().createAtom(); 79 68 Walker->type = hydrogen; 80 69 *Walker->node = Vector(0., 1., 1. ); 81 70 TestSurfaceMolecule->AddAtom(Walker); 71 82 72 Walker = World::getInstance().createAtom(); 83 73 Walker->type = hydrogen; 84 74 *Walker->node = Vector(1., 1., 0. ); 85 75 TestSurfaceMolecule->AddAtom(Walker); 76 86 77 Walker = World::getInstance().createAtom(); 87 78 Walker->type = hydrogen; … … 90 81 91 82 // check that TestMolecule was correctly constructed 92 CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule-> AtomCount, 4 );83 CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->getAtomCount(), 4 ); 93 84 94 85 TestList = World::getInstance().getMolecules(); … … 102 93 103 94 // add outer atoms 95 carbon = World::getInstance().getPeriode()->FindElement(6); 104 96 TestSurfaceMolecule = World::getInstance().createMolecule(); 105 97 Walker = World::getInstance().createAtom(); … … 107 99 *Walker->node = Vector(4., 0., 4. ); 108 100 TestSurfaceMolecule->AddAtom(Walker); 101 109 102 Walker = World::getInstance().createAtom(); 110 103 Walker->type = carbon; 111 104 *Walker->node = Vector(0., 4., 4. ); 112 105 TestSurfaceMolecule->AddAtom(Walker); 106 113 107 Walker = World::getInstance().createAtom(); 114 108 Walker->type = carbon; 115 109 *Walker->node = Vector(4., 4., 0. ); 116 110 TestSurfaceMolecule->AddAtom(Walker); 111 117 112 // add inner atoms 118 113 Walker = World::getInstance().createAtom(); … … 120 115 *Walker->node = Vector(0.5, 0.5, 0.5 ); 121 116 TestSurfaceMolecule->AddAtom(Walker); 117 122 118 TestSurfaceMolecule->ActiveFlag = true; 123 119 TestList->insert(TestSurfaceMolecule); … … 141 137 delete(LC); 142 138 World::purgeInstance(); 143 MemoryUsageObserver::purgeInstance();144 139 logger::purgeInstance(); 145 140 }; … … 150 145 void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest() 151 146 { 152 CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule-> AtomCount);147 CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->getAtomCount() ); 153 148 CPPUNIT_ASSERT_EQUAL( (size_t)2, TestList->ListOfMolecules.size() ); 154 149 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() ); … … 160 155 { 161 156 // do the pair correlation 162 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC ); 157 elements.push_back(hydrogen); 158 surfacemap = CorrelationToSurface( TestList, elements, Surface, LC ); 163 159 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); 164 160 CPPUNIT_ASSERT( surfacemap != NULL ); … … 169 165 { 170 166 BinPairMap::iterator tester; 171 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC ); 167 elements.push_back(hydrogen); 168 surfacemap = CorrelationToSurface( TestList, elements, Surface, LC ); 172 169 // put pair correlation into bins and check with no range 173 170 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); … … 184 181 { 185 182 BinPairMap::iterator tester; 186 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC ); 183 elements.push_back(hydrogen); 184 surfacemap = CorrelationToSurface( TestList, elements, Surface, LC ); 187 185 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); 188 186 // ... and check with [0., 2.] range … … 202 200 { 203 201 BinPairMap::iterator tester; 204 surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC ); 202 elements.push_back(carbon); 203 surfacemap = CorrelationToSurface( TestList, elements, Surface, LC ); 205 204 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); 206 205 // put pair correlation into bins and check with no range … … 221 220 { 222 221 BinPairMap::iterator tester; 223 surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC ); 222 elements.push_back(carbon); 223 surfacemap = CorrelationToSurface( TestList, elements, Surface, LC ); 224 224 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); 225 225 // ... and check with [0., 2.] range -
src/unittests/AnalysisCorrelationToSurfaceUnitTest.hpp
r992fd7 r257c77 47 47 element *hydrogen; 48 48 element *carbon; 49 periodentafel *tafel;49 std::vector<element *> elements; 50 50 51 51 CorrelationToSurfaceMap *surfacemap; -
src/unittests/AnalysisPairCorrelationUnitTest.cpp
r992fd7 r257c77 44 44 TestList = NULL; 45 45 TestMolecule = NULL; 46 hydrogen = NULL;47 tafel = NULL;48 46 correlationmap = NULL; 49 47 binmap = NULL; 50 48 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); 60 55 61 56 // construct molecule (tetraeder of hydrogens) … … 79 74 80 75 // check that TestMolecule was correctly constructed 81 CPPUNIT_ASSERT_EQUAL( TestMolecule-> AtomCount, 4 );76 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 ); 82 77 83 78 TestList = World::getInstance().getMolecules(); … … 86 81 87 82 // init maps 88 correlationmap = PairCorrelation( TestList, hydrogen, hydrogen);83 correlationmap = PairCorrelation( TestList, elements); 89 84 binmap = NULL; 90 85 … … 101 96 // note that all the atoms are cleaned by TestMolecule 102 97 World::purgeInstance(); 103 MemoryUsageObserver::purgeInstance();104 98 logger::purgeInstance(); 105 99 errorLogger::purgeInstance(); -
src/unittests/AnalysisPairCorrelationUnitTest.hpp
r992fd7 r257c77 12 12 13 13 class element; 14 class LinkedCell;15 14 class molecule; 16 15 class MoleculeListClass; 17 class periodentafel;18 class Tesselation;19 16 class Vector; 20 17 … … 41 38 molecule *TestMolecule; 42 39 element *hydrogen; 43 periodentafel *tafel;44 40 45 41 PairCorrelationMap *correlationmap; -
src/unittests/CacheableTest.cpp
r992fd7 r257c77 55 55 56 56 threeNumbers(int _x,int _y, int _z) : 57 Observable("threeNumbers"), 57 58 x(_x),y(_y),z(_z), 58 sum(this,boost::bind(&threeNumbers::calcSum,this) ),59 sum(this,boost::bind(&threeNumbers::calcSum,this),"sum"), 59 60 hasRecalced(false) 60 61 {} … … 81 82 CPPUNIT_ASSERT_EQUAL( 9, *(numbers->sum)); 82 83 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 83 91 } -
src/unittests/CountBondsUnitTest.cpp
r992fd7 r257c77 16 16 #include <stdio.h> 17 17 #include <cstring> 18 19 #include "Helpers/Assert.hpp" 18 20 19 21 #include "analysis_bonds.hpp" … … 40 42 { 41 43 atom *Walker = NULL; 42 BG = NULL;43 filename = NULL;44 45 // init private all pointers to zero46 molecules = NULL;47 TestMolecule1 = NULL;48 TestMolecule2 = NULL;49 hydrogen = NULL;50 oxygen = NULL;51 tafel = NULL;52 44 53 45 // 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"); 69 50 70 51 // construct molecule (water molecule) 71 52 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"); 73 56 Walker->type = hydrogen; 74 57 *Walker->node = Vector(-0.2418, 0.9350, 0. ); 75 58 TestMolecule1->AddAtom(Walker); 76 59 Walker = World::getInstance().createAtom(); 60 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 77 61 Walker->type = hydrogen; 78 62 *Walker->node = Vector(0.9658, 0., 0. ); 79 63 TestMolecule1->AddAtom(Walker); 80 64 Walker = World::getInstance().createAtom(); 65 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 81 66 Walker->type = oxygen; 82 67 *Walker->node = Vector(0., 0., 0. ); … … 84 69 85 70 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"); 87 74 Walker->type = hydrogen; 88 75 *Walker->node = Vector(-0.2418, 0.9350, 0. ); 89 76 TestMolecule2->AddAtom(Walker); 90 77 Walker = World::getInstance().createAtom(); 78 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 91 79 Walker->type = hydrogen; 92 80 *Walker->node = Vector(0.9658, 0., 0. ); 93 81 TestMolecule2->AddAtom(Walker); 94 82 Walker = World::getInstance().createAtom(); 83 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 95 84 Walker->type = oxygen; 96 85 *Walker->node = Vector(0., 0., 0. ); … … 98 87 99 88 molecules = World::getInstance().getMolecules(); 89 CPPUNIT_ASSERT(molecules != NULL && "could not obtain list of molecules"); 100 90 molecules->insert(TestMolecule1); 101 91 molecules->insert(TestMolecule2); 102 92 103 93 // 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 ); 110 96 111 97 // create a small file with table 112 98 BG = new BondGraph(true); 99 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph"); 113 100 114 101 // construct bond graphs … … 126 113 127 114 World::purgeInstance(); 128 MemoryUsageObserver::purgeInstance();129 115 }; 130 116 … … 158 144 { 159 145 double *mirror = new double[3]; 146 CPPUNIT_ASSERT(mirror != NULL && "could not create array of doubles"); 160 147 for (int i=0;i<3;i++) 161 148 mirror[i] = -1.; -
src/unittests/CountBondsUnitTest.hpp
r992fd7 r257c77 39 39 molecule *TestMolecule1; 40 40 molecule *TestMolecule2; 41 element *hydrogen; 42 element *oxygen; 43 periodentafel *tafel; 41 const element *hydrogen; 42 const element *oxygen; 44 43 45 44 BondGraph *BG; -
src/unittests/LinkedCellUnitTest.cpp
r992fd7 r257c77 38 38 atom *Walker = NULL; 39 39 40 // init private all pointers to zero41 TestMolecule = NULL;42 hydrogen = NULL;43 tafel = NULL;44 45 40 // 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"); 55 43 56 44 // construct molecule (water molecule) 57 45 TestMolecule = World::getInstance().createMolecule(); 46 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule"); 58 47 for (double x=0.5;x<3;x+=1.) 59 48 for (double y=0.5;y<3;y+=1.) 60 49 for (double z=0.5;z<3;z+=1.) { 61 50 Walker = World::getInstance().createAtom(); 51 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 62 52 Walker->type = hydrogen; 63 53 *Walker->node = Vector(x, y, z ); … … 67 57 // construct linked cell 68 58 LC = new LinkedCell (TestMolecule, 1.); 59 CPPUNIT_ASSERT(LC != NULL && "could not create LinkedCell"); 69 60 70 61 // 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 ); 74 63 }; 75 64 … … 79 68 delete(LC); 80 69 World::purgeInstance(); 81 MemoryUsageObserver::purgeInstance();82 70 }; 83 71 … … 197 185 { 198 186 // 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) ); 203 189 } 204 190 205 191 // 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); 211 197 212 198 // 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); 218 204 }; 219 205 … … 287 273 size = ListOfPoints->size(); 288 274 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)); 294 278 size--; 295 279 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); … … 306 290 size=ListOfPoints->size(); 307 291 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); 313 295 size--; 314 296 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); … … 326 308 size=ListOfPoints->size(); 327 309 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); 332 312 size--; 333 313 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); … … 355 335 size = ListOfPoints->size(); 356 336 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); 362 340 size--; 363 341 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); -
src/unittests/LinkedCellUnitTest.hpp
r992fd7 r257c77 48 48 49 49 molecule *TestMolecule; 50 element *hydrogen; 51 periodentafel *tafel; 50 const element *hydrogen; 52 51 LinkedCell *LC; 53 52 }; -
src/unittests/Makefile.am
r992fd7 r257c77 1 # PLEASE adhere to the alphabetical ordering in this Makefile! 2 # Also indentation by a single tab 3 1 4 INCLUDES = -I$(top_srcdir)/src 2 5 … … 31 34 MemoryAllocatorUnitTest \ 32 35 MoleculeDescriptorTest \ 36 ObserverTest \ 37 ParserUnitTest \ 38 periodentafelTest \ 33 39 PlaneUnittest \ 34 ObserverTest \35 40 SingletonTest \ 36 41 StackClassUnitTest \ … … 73 78 memoryusageobserverunittest.cpp \ 74 79 MoleculeDescriptorTest.cpp \ 80 ObserverTest.cpp \ 81 ParserUnitTest.cpp \ 82 periodentafelTest.cpp \ 75 83 PlaneUnittest.cpp \ 76 ObserverTest.cpp \77 84 SingletonTest.cpp \ 78 85 stackclassunittest.cpp \ … … 107 114 memoryusageobserverunittest.hpp \ 108 115 MoleculeDescriptorTest.hpp \ 116 periodentafelTest.hpp \ 109 117 PlaneUnittest.hpp \ 110 118 ObserverTest.hpp \ … … 117 125 118 126 127 ActionSequenceTest_SOURCES = UnitTestMain.cpp ../../../TestRunnerClient.hpp ActionSequenceTest.cpp ActionSequenceTest.hpp 128 ActionSequenceTest_LDADD = ${ALLLIBS} 129 119 130 ActOnAllUnitTest_SOURCES = UnitTestMain.cpp ../test/ActOnAllTest.hpp ActOnAllUnitTest.cpp ActOnAllUnitTest.hpp 120 131 ActOnAllUnitTest_LDADD = ${ALLLIBS} … … 135 146 atomsCalculationTest_LDADD = ${ALLLIBS} 136 147 148 AtomDescriptorTest_SOURCES = UnitTestMain.cpp AtomDescriptorTest.cpp AtomDescriptorTest.hpp 149 AtomDescriptorTest_LDADD = ${ALLLIBS} 150 137 151 BondGraphUnitTest_SOURCES = UnitTestMain.cpp bondgraphunittest.cpp bondgraphunittest.hpp 138 152 BondGraphUnitTest_LDADD = ${ALLLIBS} 139 153 154 CacheableTest_SOURCES = UnitTestMain.cpp CacheableTest.cpp CacheableTest.hpp 155 CacheableTest_LDADD = ${ALLLIBS} 156 140 157 CountBondsUnitTest_SOURCES = UnitTestMain.cpp CountBondsUnitTest.cpp CountBondsUnitTest.hpp 141 158 CountBondsUnitTest_LDADD = ${ALLLIBS} … … 168 185 LogUnitTest_LDADD = ${ALLLIBS} 169 186 170 MemoryAllocatorUnitTest_SOURCES = UnitTestMain.cpp memoryallocatorunittest.cpp memoryallocatorunittest.hpp 187 manipulateAtomsTest_SOURCES = UnitTestMain.cpp manipulateAtomsTest.cpp manipulateAtomsTest.hpp 188 manipulateAtomsTest_LDADD = ${ALLLIBS} 189 190 MemoryAllocatorUnitTest_SOURCES = UnitTestMain.cpp ../memoryallocator.hpp ../memoryallocator.cpp ../memoryusageobserver.cpp ../memoryusageobserver.hpp memoryallocatorunittest.cpp memoryallocatorunittest.hpp 171 191 MemoryAllocatorUnitTest_LDADD = ${ALLLIBS} 172 192 173 MemoryUsageObserverUnitTest_SOURCES = UnitTestMain.cpp memoryusageobserverunittest.cpp memoryusageobserverunittest.hpp193 MemoryUsageObserverUnitTest_SOURCES = UnitTestMain.cpp ../memoryallocator.hpp ../memoryusageobserver.cpp ../memoryusageobserver.hpp memoryusageobserverunittest.cpp memoryusageobserverunittest.hpp 174 194 MemoryUsageObserverUnitTest_LDADD = ${ALLLIBS} 175 195 … … 177 197 MoleculeDescriptorTest_LDADD = ${ALLLIBS} 178 198 199 ObserverTest_SOURCES = UnitTestMain.cpp ObserverTest.cpp ObserverTest.hpp 200 ObserverTest_LDADD = ${ALLLIBS} 201 202 ParserUnitTest_SOURCES = UnitTestMain.cpp ParserUnitTest.cpp ParserUnitTest.hpp 203 ParserUnitTest_LDADD = ${ALLLIBS} 204 205 periodentafelTest_SOURCES = UnitTestMain.cpp periodentafelTest.cpp periodentafelTest.hpp 206 periodentafelTest_LDADD = ${ALLLIBS} 207 179 208 PlaneUnittest_SOURCES = UnitTestMain.cpp PlaneUnittest.cpp PlaneUnittest.hpp 180 209 PlaneUnittest_LDADD = ${ALLLIBS} … … 195 224 Tesselation_InOutsideUnitTest_LDADD = ${ALLLIBS} 196 225 226 TestRunner_SOURCES = TestRunnerMain.cpp ../memoryallocator.hpp ../memoryallocator.cpp ../memoryusageobserver.cpp ../memoryusageobserver.hpp $(TESTSOURCES) $(TESTHEADERS) 227 TestRunner_LDADD = ${ALLLIBS} 228 197 229 VectorUnitTest_SOURCES = UnitTestMain.cpp vectorunittest.cpp vectorunittest.hpp 198 230 VectorUnitTest_LDADD = ${ALLLIBS} 199 231 200 ActionSequenceTest_SOURCES = UnitTestMain.cpp ../../../TestRunnerClient.hpp ActionSequenceTest.cpp ActionSequenceTest.hpp201 ActionSequenceTest_LDADD = ${ALLLIBS}202 203 ObserverTest_SOURCES = UnitTestMain.cpp ObserverTest.cpp ObserverTest.hpp204 ObserverTest_LDADD = ${ALLLIBS}205 206 CacheableTest_SOURCES = UnitTestMain.cpp CacheableTest.cpp CacheableTest.hpp207 CacheableTest_LDADD = ${ALLLIBS}208 209 AtomDescriptorTest_SOURCES = UnitTestMain.cpp AtomDescriptorTest.cpp AtomDescriptorTest.hpp210 AtomDescriptorTest_LDADD = ${ALLLIBS}211 212 manipulateAtomsTest_SOURCES = UnitTestMain.cpp manipulateAtomsTest.cpp manipulateAtomsTest.hpp213 manipulateAtomsTest_LDADD = ${ALLLIBS}214 215 TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS)216 TestRunner_LDADD = ${ALLLIBS}217 218 232 #AUTOMAKE_OPTIONS = parallel-tests 219 -
src/unittests/ObserverTest.cpp
r992fd7 r257c77 11 11 #include <cppunit/extensions/TestFactoryRegistry.h> 12 12 #include <cppunit/ui/text/TestRunner.h> 13 #include <set> 13 14 14 15 #include "Patterns/Observer.hpp" 16 #include "Patterns/ObservedIterator.hpp" 15 17 #include "Helpers/Assert.hpp" 16 18 … … 31 33 public: 32 34 UpdateCountObserver() : 35 Observer("UpdateCountObserver"), 33 36 updates(0) 34 37 {}; … … 43 46 class SimpleObservable : public Observable { 44 47 public: 48 SimpleObservable() : 49 Observable("SimpleObservable") 50 {} 51 45 52 void changeMethod() { 46 53 OBSERVE; … … 52 59 class CallObservable : public Observable { 53 60 public: 61 CallObservable() : 62 Observable("CallObservable") 63 {} 64 54 65 void changeMethod1() { 55 66 OBSERVE; … … 68 79 class BlockObservable : public Observable { 69 80 public: 81 BlockObservable() : 82 Observable("BlockObservable") 83 {} 84 70 85 void changeMethod1(){ 71 86 OBSERVE; … … 102 117 class SuperObservable : public Observable { 103 118 public: 104 SuperObservable(){ 119 SuperObservable(): 120 Observable("SuperObservable") 121 { 105 122 subObservable = new SimpleObservable(); 106 123 subObservable->signOn(this); … … 121 138 public: 122 139 NotificationObservable() : 123 notification1(new Notification(this)), 124 notification2(new Notification(this)) 140 Observable("NotificationObservable"), 141 notification1(new Notification(this)), 142 notification2(new Notification(this)) 125 143 {} 126 144 … … 147 165 public: 148 166 NotificationObserver(Notification_ptr notification) : 167 Observer("NotificationObserver"), 149 168 requestedNotification(notification), 150 169 wasNotified(false) … … 162 181 bool wasNotified; 163 182 }; 183 184 class ObservableCollection : public Observable { 185 public: 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 218 private: 219 set theSet; 220 }; 221 164 222 165 223 /******************* actuall tests ***************/ … … 173 231 blockObservable = new BlockObservable(); 174 232 notificationObservable = new NotificationObservable(); 233 collection = new ObservableCollection(5); 175 234 176 235 observer1 = new UpdateCountObserver(); … … 181 240 notificationObserver1 = new NotificationObserver(notificationObservable->notification1); 182 241 notificationObserver2 = new NotificationObserver(notificationObservable->notification2); 183 184 242 } 185 243 … … 191 249 delete blockObservable; 192 250 delete notificationObservable; 251 delete collection; 193 252 194 253 delete observer1; … … 277 336 blockObservable->changeMethod2(); 278 337 blockObservable->noChangeMethod(); 338 } 339 340 void 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); 279 372 } 280 373 -
src/unittests/ObserverTest.hpp
r992fd7 r257c77 17 17 class CallObservable; 18 18 class SuperObservable; 19 class ObservableCollection; 19 20 class BlockObservable; 20 21 class NotificationObservable; 21 22 22 23 23 class ObserverTest : public CppUnit::TestFixture … … 29 29 CPPUNIT_TEST ( doesNotifyTest ); 30 30 CPPUNIT_TEST ( doesReportTest ); 31 CPPUNIT_TEST ( iteratorTest ); 31 32 CPPUNIT_TEST ( CircleDetectionTest ); 32 33 CPPUNIT_TEST_SUITE_END(); … … 41 42 void doesNotifyTest(); 42 43 void doesReportTest(); 44 void iteratorTest(); 43 45 void CircleDetectionTest(); 44 46 … … 58 60 SuperObservable *superObservable; 59 61 NotificationObservable *notificationObservable; 62 ObservableCollection *collection; 63 60 64 }; 61 65 -
src/unittests/SingletonTest.cpp
r992fd7 r257c77 52 52 count1++; 53 53 } 54 // explicit copy constructor to catch if th siis ever called54 // explicit copy constructor to catch if this is ever called 55 55 SingletonStub2(const SingletonStub2&){ 56 56 CPPUNIT_FAIL ( "Copy constructor of Singleton called" ); -
src/unittests/TestRunnerMain.cpp
r992fd7 r257c77 6 6 */ 7 7 8 // include config.h 9 #ifdef HAVE_CONFIG_H 10 #include <config.h> 11 #endif 12 13 #ifdef HAVE_ECUT 8 14 // give the main function its correct name 9 15 #define CPPUNIT_MAIN main 10 11 16 // include the TestRunnerClient file containing the main class 12 17 #include "../../../TestRunnerClient.h" 13 18 #include "../../../TestRunnerClient.cpp" 19 #else 20 #include "UnitTestMain.cpp" 21 #endif 22 -
src/unittests/analysisbondsunittest.cpp
r992fd7 r257c77 25 25 #include "molecule.hpp" 26 26 #include "periodentafel.hpp" 27 #include "World.hpp" 27 28 28 29 #ifdef HAVE_TESTRUNNER … … 40 41 atom *Walker = NULL; 41 42 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"); 66 48 67 49 // construct molecule (tetraeder of hydrogens) 68 50 TestMolecule = World::getInstance().createMolecule(); 51 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule"); 69 52 Walker = World::getInstance().createAtom(); 53 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 70 54 Walker->type = hydrogen; 71 55 *Walker->node = Vector(1.5, 0., 1.5 ); 72 56 TestMolecule->AddAtom(Walker); 73 57 Walker = World::getInstance().createAtom(); 58 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 74 59 Walker->type = hydrogen; 75 60 *Walker->node = Vector(0., 1.5, 1.5 ); 76 61 TestMolecule->AddAtom(Walker); 77 62 Walker = World::getInstance().createAtom(); 63 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 78 64 Walker->type = hydrogen; 79 65 *Walker->node = Vector(1.5, 1.5, 0. ); 80 66 TestMolecule->AddAtom(Walker); 81 67 Walker = World::getInstance().createAtom(); 68 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 82 69 Walker->type = hydrogen; 83 70 *Walker->node = Vector(0., 0., 0. ); 84 71 TestMolecule->AddAtom(Walker); 85 72 Walker = World::getInstance().createAtom(); 73 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 86 74 Walker->type = carbon; 87 75 *Walker->node = Vector(0.5, 0.5, 0.5 ); … … 89 77 90 78 // check that TestMolecule was correctly constructed 91 CPPUNIT_ASSERT_EQUAL( TestMolecule-> AtomCount, 5 );79 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 5 ); 92 80 93 81 // create a small file with table 94 82 filename = new string("test.dat"); 83 CPPUNIT_ASSERT(filename != NULL && "could not create string"); 95 84 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"; 99 92 test.close(); 100 93 BG = new BondGraph(true); 94 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph"); 101 95 102 96 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) ); 103 97 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) ); 106 100 107 101 BG->ConstructBondGraph(TestMolecule); -
src/unittests/analysisbondsunittest.hpp
r992fd7 r257c77 34 34 35 35 molecule *TestMolecule; 36 element *hydrogen; 37 element *carbon; 38 periodentafel *tafel; 36 const element *hydrogen; 37 const element *carbon; 39 38 40 39 BondGraph *BG; -
src/unittests/bondgraphunittest.cpp
r992fd7 r257c77 15 15 #include <stdio.h> 16 16 #include <cstring> 17 18 #include "Helpers/Assert.hpp" 17 19 18 20 #include "World.hpp" … … 41 43 atom *Walker = NULL; 42 44 43 // init private all pointers to zero44 TestMolecule = NULL;45 hydrogen = NULL;46 tafel = NULL;47 48 45 // 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"); 67 50 68 51 // construct molecule (tetraeder of hydrogens) 69 52 TestMolecule = World::getInstance().createMolecule(); 53 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule"); 70 54 Walker = World::getInstance().createAtom(); 55 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 71 56 Walker->type = carbon; 72 57 *Walker->node = Vector(1., 0., 1. ); … … 74 59 75 60 Walker = World::getInstance().createAtom(); 61 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 76 62 Walker->type = carbon; 77 63 *Walker->node = Vector(0., 1., 1. ); … … 79 65 80 66 Walker = World::getInstance().createAtom(); 67 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 81 68 Walker->type = carbon; 82 69 *Walker->node = Vector(1., 1., 0. ); … … 84 71 85 72 Walker = World::getInstance().createAtom(); 73 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 86 74 Walker->type = carbon; 87 75 *Walker->node = Vector(0., 0., 0. ); … … 89 77 90 78 // check that TestMolecule was correctly constructed 91 CPPUNIT_ASSERT_EQUAL( TestMolecule-> AtomCount, 4 );79 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 ); 92 80 93 81 // create a small file with table 94 82 dummyname = new string("dummy.dat"); 83 CPPUNIT_ASSERT(dummyname != NULL && "could not create string"); 95 84 filename = new string("test.dat"); 85 CPPUNIT_ASSERT(filename != NULL && "could not create string"); 96 86 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"; 100 94 test.close(); 101 95 BG = new BondGraph(true); 96 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph"); 102 97 }; 103 98 … … 116 111 // are all cleaned when the world is destroyed 117 112 World::purgeInstance(); 118 MemoryUsageObserver::purgeInstance();119 113 logger::purgeInstance(); 114 }; 115 116 /** Tests whether setup worked. 117 */ 118 void BondGraphTest::SetupTest() 119 { 120 CPPUNIT_ASSERT_EQUAL (false, TestMolecule->empty()); 121 CPPUNIT_ASSERT_EQUAL ((size_t)4, TestMolecule->size()); 120 122 }; 121 123 … … 126 128 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) ); 127 129 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) ); 130 132 }; 131 133 … … 134 136 void BondGraphTest::ConstructGraphFromTableTest() 135 137 { 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++; 139 141 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) ); 140 142 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) ); 141 CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );143 CPPUNIT_ASSERT_EQUAL( true , (*Walker)->IsBondedTo((*Runner)) ); 142 144 }; 143 145 … … 146 148 void BondGraphTest::ConstructGraphFromCovalentRadiiTest() 147 149 { 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 ); 151 154 CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(*dummyname) ); 152 155 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) ); 154 159 }; 155 160 -
src/unittests/bondgraphunittest.hpp
r992fd7 r257c77 22 22 { 23 23 CPPUNIT_TEST_SUITE( BondGraphTest) ; 24 CPPUNIT_TEST ( SetupTest ); 24 25 CPPUNIT_TEST ( LoadTableTest ); 25 26 CPPUNIT_TEST ( ConstructGraphFromTableTest ); … … 30 31 void setUp(); 31 32 void tearDown(); 33 void SetupTest(); 32 34 void LoadTableTest(); 33 35 void ConstructGraphFromTableTest(); … … 37 39 38 40 molecule *TestMolecule; 39 element *hydrogen; 40 element *carbon; 41 periodentafel *tafel; 41 const element *hydrogen; 42 const element *carbon; 42 43 43 44 BondGraph *BG; -
src/unittests/listofbondsunittest.cpp
r992fd7 r257c77 38 38 atom *Walker = NULL; 39 39 40 // init private all pointers to zero41 TestMolecule = NULL;42 hydrogen = NULL;43 tafel = NULL;44 45 40 // 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"); 55 43 56 44 // construct molecule (tetraeder of hydrogens) 57 45 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"); 59 49 Walker->type = hydrogen; 60 50 *Walker->node = Vector(1., 0., 1. ); 61 51 TestMolecule->AddAtom(Walker); 62 52 Walker = World::getInstance().createAtom(); 53 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 63 54 Walker->type = hydrogen; 64 55 *Walker->node = Vector(0., 1., 1. ); 65 56 TestMolecule->AddAtom(Walker); 66 57 Walker = World::getInstance().createAtom(); 58 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 67 59 Walker->type = hydrogen; 68 60 *Walker->node = Vector(1., 1., 0. ); 69 61 TestMolecule->AddAtom(Walker); 70 62 Walker = World::getInstance().createAtom(); 63 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 71 64 Walker->type = hydrogen; 72 65 *Walker->node = Vector(0., 0., 0. ); … … 74 67 75 68 // check that TestMolecule was correctly constructed 76 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 77 69 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 ); 78 70 }; 79 71 … … 86 78 // are all cleaned when the world is destroyed 87 79 World::purgeInstance(); 88 MemoryUsageObserver::purgeInstance();89 80 logger::purgeInstance(); 90 81 }; 91 82 83 /** Tests whether setup worked correctly. 84 * 85 */ 86 void ListOfBondsTest::SetupTest() 87 { 88 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->empty() ); 89 CPPUNIT_ASSERT_EQUAL( (size_t)4, TestMolecule->size() ); 90 }; 91 92 92 /** Unit Test of molecule::AddBond() 93 93 * … … 96 96 { 97 97 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() ); 108 109 109 110 // check that bond contains the two atoms … … 124 125 { 125 126 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; 128 131 CPPUNIT_ASSERT( atom1 != NULL ); 129 132 CPPUNIT_ASSERT( atom2 != NULL ); … … 141 144 142 145 // check if removed from molecule 143 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last);146 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() ); 144 147 }; 145 148 … … 150 153 { 151 154 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; 155 161 CPPUNIT_ASSERT( atom1 != NULL ); 156 162 CPPUNIT_ASSERT( atom2 != NULL ); … … 179 185 180 186 // 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() ); 183 189 }; 184 190 … … 189 195 { 190 196 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; 193 201 CPPUNIT_ASSERT( atom1 != NULL ); 194 202 CPPUNIT_ASSERT( atom2 != NULL ); … … 206 214 207 215 // check if removed from molecule 208 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last);216 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() ); 209 217 }; 210 218 … … 215 223 { 216 224 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; 219 229 CPPUNIT_ASSERT( atom1 != NULL ); 220 230 CPPUNIT_ASSERT( atom2 != NULL ); … … 231 241 232 242 // check if removed from molecule 233 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last);243 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() ); 234 244 }; 235 245 … … 239 249 void ListOfBondsTest::DeleteAtomTest() 240 250 { 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() ); 250 271 251 272 // remove atom2 … … 256 277 257 278 // 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 20 20 { 21 21 CPPUNIT_TEST_SUITE( ListOfBondsTest) ; 22 CPPUNIT_TEST ( SetupTest ); 22 23 CPPUNIT_TEST ( AddingBondTest ); 23 24 CPPUNIT_TEST ( RemovingBondTest ); … … 31 32 void setUp(); 32 33 void tearDown(); 34 void SetupTest(); 33 35 void AddingBondTest(); 34 36 void RemovingBondTest(); … … 41 43 42 44 molecule *TestMolecule; 43 element *hydrogen; 44 periodentafel *tafel; 45 const element *hydrogen; 45 46 }; 46 47 -
src/unittests/manipulateAtomsTest.cpp
r992fd7 r257c77 55 55 public: 56 56 countObserver() : 57 Observer("countObserver"), 57 58 count(0) 58 59 {} -
src/unittests/memoryallocatorunittest.cpp
r992fd7 r257c77 12 12 #include "memoryallocator.hpp" 13 13 #include "memoryallocatorunittest.hpp" 14 #include "memoryusageobserver.hpp" 14 15 #include "helpers.hpp" 15 16 #include "log.hpp" -
src/unittests/stackclassunittest.cpp
r992fd7 r257c77 37 37 Stack->ClearStack(); 38 38 delete(Stack); 39 MemoryUsageObserver::purgeInstance();40 39 logger::purgeInstance(); 41 40 }; -
src/unittests/tesselation_boundarytriangleunittest.cpp
r992fd7 r257c77 70 70 delete tesselpoints[i]; 71 71 } 72 MemoryUsageObserver::purgeInstance();73 72 logger::purgeInstance(); 74 73 errorLogger::purgeInstance(); -
src/unittests/tesselation_insideoutsideunittest.cpp
r992fd7 r257c77 134 134 } 135 135 Corners.clear(); 136 MemoryUsageObserver::purgeInstance();137 136 logger::purgeInstance(); 138 137 errorLogger::purgeInstance(); -
src/unittests/tesselationunittest.cpp
r992fd7 r257c77 106 106 } 107 107 Corners.clear(); 108 MemoryUsageObserver::purgeInstance();109 108 logger::purgeInstance(); 110 109 errorLogger::purgeInstance(); -
src/unittests/vectorunittest.cpp
r992fd7 r257c77 49 49 void VectorTest::tearDown() 50 50 { 51 MemoryUsageObserver::purgeInstance();52 51 logger::purgeInstance(); 53 52 errorLogger::purgeInstance();
Note:
See TracChangeset
for help on using the changeset viewer.
