source: src/unittests/bondgraphunittest.cpp@ a1510d

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 a1510d was a1510d, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'FreddiesRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Patterns/Observer.cpp
molecuilder/src/World.cpp
molecuilder/src/boundary.cpp
molecuilder/src/molecule_dynamics.cpp
molecuilder/src/unittests/AnalysisCorrelationToPointUnitTest.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/AnalysisPairCorrelationUnitTest.cpp
molecuilder/src/unittests/Makefile.am
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/unittests/listofbondsunittest.cpp

  • Property mode set to 100644
File size: 3.4 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 "molecule.hpp"
24#include "periodentafel.hpp"
25#include "bondgraphunittest.hpp"
26#include "World.hpp"
27
28#ifdef HAVE_TESTRUNNER
29#include "UnitTestMain.hpp"
30#endif /*HAVE_TESTRUNNER*/
31
32/********************************************** Test classes **************************************/
33
34// Registers the fixture into the 'registry'
35CPPUNIT_TEST_SUITE_REGISTRATION( BondGraphTest );
36
37
38void BondGraphTest::setUp()
39{
40 atom *Walker = NULL;
41
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 strcpy(hydrogen->name, "hydrogen");
51 strcpy(hydrogen->symbol, "H");
52 carbon = new element;
53 carbon->Z = 1;
54 strcpy(carbon->name, "carbon");
55 strcpy(carbon->symbol, "C");
56
57
58 // construct periodentafel
59 tafel = World::get()->getPeriode();
60 tafel->AddElement(hydrogen);
61 tafel->AddElement(carbon);
62
63 // construct molecule (tetraeder of hydrogens)
64 TestMolecule = World::get()->createMolecule();
65 Walker = World::get()->createAtom();
66 Walker->type = hydrogen;
67 Walker->node->Init(1., 0., 1. );
68 TestMolecule->AddAtom(Walker);
69 Walker = World::get()->createAtom();
70 Walker->type = hydrogen;
71 Walker->node->Init(0., 1., 1. );
72 TestMolecule->AddAtom(Walker);
73 Walker = World::get()->createAtom();
74 Walker->type = hydrogen;
75 Walker->node->Init(1., 1., 0. );
76 TestMolecule->AddAtom(Walker);
77 Walker = World::get()->createAtom();
78 Walker->type = hydrogen;
79 Walker->node->Init(0., 0., 0. );
80 TestMolecule->AddAtom(Walker);
81
82 // check that TestMolecule was correctly constructed
83 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
84
85 // create a small file with table
86 filename = new string("test.dat");
87 ofstream test(filename->c_str());
88 test << ".\tH\tC\n";
89 test << "H\t1.\t1.2\n";
90 test << "C\t1.2\t1.5\n";
91 test.close();
92 BG = new BondGraph(true);
93};
94
95
96void BondGraphTest::tearDown()
97{
98 // remove the file
99 remove(filename->c_str());
100 delete(filename);
101 delete(BG);
102
103 // remove molecule
104 World::get()->destroyMolecule(TestMolecule);
105 // note that all the atoms, molecules, the tafel and the elements
106 // are all cleaned when the world is destroyed
107 World::destroy();
108 MemoryUsageObserver::purgeInstance();
109 logger::purgeInstance();
110};
111
112/** UnitTest for BondGraphTest::LoadBondLengthTable().
113 */
114void BondGraphTest::LoadTableTest()
115{
116 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
117 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
118 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
119 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
120};
121
122/** UnitTest for BondGraphTest::ConstructBondGraph().
123 */
124void BondGraphTest::ConstructGraphTest()
125{
126 atom *Walker = TestMolecule->start->next;
127 atom *Runner = TestMolecule->end->previous;
128 CPPUNIT_ASSERT( TestMolecule->end != Walker );
129 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
130 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
131 CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
132};
Note: See TracBrowser for help on using the repository browser.