source: src/unittests/bondgraphunittest.cpp@ 8cbb97

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 8cbb97 was 8cbb97, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'VectorRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Legacy/oldmenu.cpp
molecuilder/src/Makefile.am
molecuilder/src/analysis_correlation.cpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/ellipsoid.cpp
molecuilder/src/linkedcell.cpp
molecuilder/src/molecule.cpp
molecuilder/src/molecule_fragmentation.cpp
molecuilder/src/molecule_geometry.cpp
molecuilder/src/molecule_graph.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/tesselation.cpp
molecuilder/src/tesselationhelpers.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/vector.cpp
molecuilder/src/vector.hpp

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * bondgraphunittest.cpp
3 *
4 * Created on: Oct 29, 2009
5 * Author: heber
6 */
7
8using namespace std;
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#include <iostream>
15#include <stdio.h>
16#include <cstring>
17
18#include "World.hpp"
19#include "atom.hpp"
20#include "bond.hpp"
21#include "bondgraph.hpp"
22#include "element.hpp"
23#include "log.hpp"
24#include "molecule.hpp"
25#include "periodentafel.hpp"
26#include "bondgraphunittest.hpp"
27#include "World.hpp"
28
29#ifdef HAVE_TESTRUNNER
30#include "UnitTestMain.hpp"
31#endif /*HAVE_TESTRUNNER*/
32
33/********************************************** Test classes **************************************/
34
35// Registers the fixture into the 'registry'
36CPPUNIT_TEST_SUITE_REGISTRATION( BondGraphTest );
37
38
39void BondGraphTest::setUp()
40{
41 atom *Walker = NULL;
42
43 // init private all pointers to zero
44 TestMolecule = NULL;
45 hydrogen = NULL;
46 tafel = NULL;
47
48 // 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);
67
68 // construct molecule (tetraeder of hydrogens)
69 TestMolecule = World::getInstance().createMolecule();
70 Walker = World::getInstance().createAtom();
71 Walker->type = carbon;
72 *Walker->node = Vector(1., 0., 1. );
73 TestMolecule->AddAtom(Walker);
74
75 Walker = World::getInstance().createAtom();
76 Walker->type = carbon;
77 *Walker->node = Vector(0., 1., 1. );
78 TestMolecule->AddAtom(Walker);
79
80 Walker = World::getInstance().createAtom();
81 Walker->type = carbon;
82 *Walker->node = Vector(1., 1., 0. );
83 TestMolecule->AddAtom(Walker);
84
85 Walker = World::getInstance().createAtom();
86 Walker->type = carbon;
87 *Walker->node = Vector(0., 0., 0. );
88 TestMolecule->AddAtom(Walker);
89
90 // check that TestMolecule was correctly constructed
91 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
92
93 // create a small file with table
94 dummyname = new string("dummy.dat");
95 filename = new string("test.dat");
96 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";
100 test.close();
101 BG = new BondGraph(true);
102};
103
104
105void BondGraphTest::tearDown()
106{
107 // remove the file
108 remove(filename->c_str());
109 delete(filename);
110 delete(dummyname);
111 delete(BG);
112
113 // remove molecule
114 World::getInstance().destroyMolecule(TestMolecule);
115 // note that all the atoms, molecules, the tafel and the elements
116 // are all cleaned when the world is destroyed
117 World::purgeInstance();
118 MemoryUsageObserver::purgeInstance();
119 logger::purgeInstance();
120};
121
122/** UnitTest for BondGraphTest::LoadBondLengthTable().
123 */
124void BondGraphTest::LoadTableTest()
125{
126 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
127 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};
131
132/** UnitTest for BondGraphTest::ConstructBondGraph().
133 */
134void BondGraphTest::ConstructGraphFromTableTest()
135{
136 atom *Walker = TestMolecule->start->next;
137 atom *Runner = TestMolecule->end->previous;
138 CPPUNIT_ASSERT( TestMolecule->end != Walker );
139 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
140 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
141 CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
142};
143
144/** UnitTest for BondGraphTest::ConstructBondGraph().
145 */
146void BondGraphTest::ConstructGraphFromCovalentRadiiTest()
147{
148 atom *Walker = TestMolecule->start->next;
149 atom *Runner = TestMolecule->end->previous;
150 CPPUNIT_ASSERT( TestMolecule->end != Walker );
151 CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(*dummyname) );
152 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
153 CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
154};
155
Note: See TracBrowser for help on using the repository browser.