source: src/unittests/bondgraphunittest.cpp@ 701ad6

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 701ad6 was bf3817, checked in by Frederik Heber <heber@…>, 15 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[b70721]1/*
2 * bondgraphunittest.cpp
3 *
4 * Created on: Oct 29, 2009
5 * Author: heber
6 */
7
[bf3817]8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
[b70721]13using namespace std;
14
15#include <cppunit/CompilerOutputter.h>
16#include <cppunit/extensions/TestFactoryRegistry.h>
17#include <cppunit/ui/text/TestRunner.h>
18
19#include <iostream>
20#include <stdio.h>
[49e1ae]21#include <cstring>
[b70721]22
[4eb4fe]23#include "Helpers/Assert.hpp"
24
[46d958]25#include "World.hpp"
[b70721]26#include "atom.hpp"
27#include "bond.hpp"
28#include "bondgraph.hpp"
29#include "element.hpp"
[952f38]30#include "Helpers/Log.hpp"
[b70721]31#include "molecule.hpp"
32#include "periodentafel.hpp"
33#include "bondgraphunittest.hpp"
[e6fdbe]34#include "World.hpp"
[b70721]35
[9b6b2f]36#ifdef HAVE_TESTRUNNER
37#include "UnitTestMain.hpp"
38#endif /*HAVE_TESTRUNNER*/
[b70721]39
40/********************************************** Test classes **************************************/
41
42// Registers the fixture into the 'registry'
43CPPUNIT_TEST_SUITE_REGISTRATION( BondGraphTest );
44
45
46void BondGraphTest::setUp()
47{
48 atom *Walker = NULL;
49
50 // construct element
[4eb4fe]51 hydrogen = World::getInstance().getPeriode()->FindElement(1);
52 carbon = World::getInstance().getPeriode()->FindElement(6);
53 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
54 CPPUNIT_ASSERT(carbon != NULL && "could not find element carbon");
[b70721]55
56 // construct molecule (tetraeder of hydrogens)
[23b547]57 TestMolecule = World::getInstance().createMolecule();
[4eb4fe]58 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
[23b547]59 Walker = World::getInstance().createAtom();
[4eb4fe]60 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]61 Walker->setType(carbon);
62 Walker->setPosition(Vector(1., 0., 1. ));
[b70721]63 TestMolecule->AddAtom(Walker);
[8cbb97]64
[23b547]65 Walker = World::getInstance().createAtom();
[4eb4fe]66 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]67 Walker->setType(carbon);
68 Walker->setPosition(Vector(0., 1., 1. ));
[b70721]69 TestMolecule->AddAtom(Walker);
[8cbb97]70
[23b547]71 Walker = World::getInstance().createAtom();
[4eb4fe]72 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]73 Walker->setType(carbon);
74 Walker->setPosition(Vector(1., 1., 0. ));
[b70721]75 TestMolecule->AddAtom(Walker);
[8cbb97]76
[23b547]77 Walker = World::getInstance().createAtom();
[4eb4fe]78 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]79 Walker->setType(carbon);
80 Walker->setPosition(Vector(0., 0., 0. ));
[b70721]81 TestMolecule->AddAtom(Walker);
82
83 // check that TestMolecule was correctly constructed
[ea7176]84 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
[b70721]85
86 // create a small file with table
[e5ad5c]87 dummyname = new string("dummy.dat");
[4eb4fe]88 CPPUNIT_ASSERT(dummyname != NULL && "could not create string");
[b70721]89 filename = new string("test.dat");
[4eb4fe]90 CPPUNIT_ASSERT(filename != NULL && "could not create string");
[b70721]91 ofstream test(filename->c_str());
[4eb4fe]92 test << ".\tH\tHe\tLi\tBe\tB\tC\n";
93 test << "H\t1.\t1.\t1.\t1.\t1.\t1.2\n";
94 test << "He\t1.\t1.\t1.\t1.\t1.\t1.\n";
95 test << "Li\t1.\t1.\t1.\t1.\t1.\t1.\n";
96 test << "Be\t1.\t1.\t1.\t1.\t1.\t1.\n";
97 test << "B\t1.\t1.\t1.\t1.\t1.\t1.\n";
98 test << "C\t1.2\t1.\t1.\t1.\t1.\t1.5\n";
[9a7186]99 test.close();
[b70721]100 BG = new BondGraph(true);
[4eb4fe]101 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
[b70721]102};
103
104
105void BondGraphTest::tearDown()
106{
107 // remove the file
108 remove(filename->c_str());
109 delete(filename);
[e5ad5c]110 delete(dummyname);
[b70721]111 delete(BG);
112
113 // remove molecule
[23b547]114 World::getInstance().destroyMolecule(TestMolecule);
[a1510d]115 // note that all the atoms, molecules, the tafel and the elements
116 // are all cleaned when the world is destroyed
[23b547]117 World::purgeInstance();
[e6fdbe]118 logger::purgeInstance();
[b70721]119};
120
[9879f6]121/** Tests whether setup worked.
122 */
123void BondGraphTest::SetupTest()
124{
125 CPPUNIT_ASSERT_EQUAL (false, TestMolecule->empty());
126 CPPUNIT_ASSERT_EQUAL ((size_t)4, TestMolecule->size());
127};
128
[b70721]129/** UnitTest for BondGraphTest::LoadBondLengthTable().
130 */
131void BondGraphTest::LoadTableTest()
132{
[e138de]133 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
[b70721]134 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
[4eb4fe]135 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) );
136 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(5,5) );
[b70721]137};
138
139/** UnitTest for BondGraphTest::ConstructBondGraph().
140 */
[e5ad5c]141void BondGraphTest::ConstructGraphFromTableTest()
[b70721]142{
[9879f6]143 molecule::iterator Walker = TestMolecule->begin();
144 molecule::iterator Runner = TestMolecule->begin();
145 Runner++;
[e138de]146 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
147 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
[9879f6]148 CPPUNIT_ASSERT_EQUAL( true , (*Walker)->IsBondedTo((*Runner)) );
[b70721]149};
150
[e5ad5c]151/** UnitTest for BondGraphTest::ConstructBondGraph().
152 */
153void BondGraphTest::ConstructGraphFromCovalentRadiiTest()
154{
[a7b761b]155
156 //atom *Walker = TestMolecule->start->next;
157 //atom *Runner = TestMolecule->end->previous;
158 //CPPUNIT_ASSERT( TestMolecule->end != Walker );
[e5ad5c]159 CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(*dummyname) );
160 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
[a7b761b]161
162 // this cannot be assured using dynamic IDs
163 //CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
[e5ad5c]164};
165
Note: See TracBrowser for help on using the repository browser.