source: src/unittests/bondgraphunittest.cpp@ 2a92ff

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 2a92ff was 4eb4fe, checked in by Frederik Heber <heber@…>, 15 years ago

"-e <db path>" not necessary anymore.

Removed necessity of specifying path to databases (this was one check of molecuilder/test/testsuite.at which cannot be fulfilled anymore with boost::program_options)
For this to work a great number of small changes have been necessary:

class periodentafel:

  • all .db files merged into const char * arrays in elements_db.cpp
  • periodentafel rewritten:
  • FindElement(), AskElement() and EnterElement return element * const instead of const element * (i.e. the contents of the pointer is const (the element) not the pointer itself which is very vexatious (i.e. FindElement() yields const element * which can subsequently not be used for RemoveElement(), ...)
  • parsedElems is not needed anymore. Instead we operate on map elements directly
  • new unittest periodentafelTest which is made friend of periodentafel to be able to access private loading functions directly

A number of unit tests had to be changed (all that create elements during setUp() which is now unnecessary)

Some of the analysis_bonds function's signatures were changed in the process:

Finally, the respective tests are removed from molecuilder/tests/testsuite.at.

  • Property mode set to 100644
File size: 4.5 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 "Helpers/Assert.hpp"
19
20#include "World.hpp"
21#include "atom.hpp"
22#include "bond.hpp"
23#include "bondgraph.hpp"
24#include "element.hpp"
25#include "log.hpp"
26#include "molecule.hpp"
27#include "periodentafel.hpp"
28#include "bondgraphunittest.hpp"
29#include "World.hpp"
30
31#ifdef HAVE_TESTRUNNER
32#include "UnitTestMain.hpp"
33#endif /*HAVE_TESTRUNNER*/
34
35/********************************************** Test classes **************************************/
36
37// Registers the fixture into the 'registry'
38CPPUNIT_TEST_SUITE_REGISTRATION( BondGraphTest );
39
40
41void BondGraphTest::setUp()
42{
43 atom *Walker = NULL;
44
45 // construct element
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");
50
51 // construct molecule (tetraeder of hydrogens)
52 TestMolecule = World::getInstance().createMolecule();
53 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
54 Walker = World::getInstance().createAtom();
55 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
56 Walker->type = carbon;
57 *Walker->node = Vector(1., 0., 1. );
58 TestMolecule->AddAtom(Walker);
59
60 Walker = World::getInstance().createAtom();
61 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
62 Walker->type = carbon;
63 *Walker->node = Vector(0., 1., 1. );
64 TestMolecule->AddAtom(Walker);
65
66 Walker = World::getInstance().createAtom();
67 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
68 Walker->type = carbon;
69 *Walker->node = Vector(1., 1., 0. );
70 TestMolecule->AddAtom(Walker);
71
72 Walker = World::getInstance().createAtom();
73 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
74 Walker->type = carbon;
75 *Walker->node = Vector(0., 0., 0. );
76 TestMolecule->AddAtom(Walker);
77
78 // check that TestMolecule was correctly constructed
79 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
80
81 // create a small file with table
82 dummyname = new string("dummy.dat");
83 CPPUNIT_ASSERT(dummyname != NULL && "could not create string");
84 filename = new string("test.dat");
85 CPPUNIT_ASSERT(filename != NULL && "could not create string");
86 ofstream test(filename->c_str());
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";
94 test.close();
95 BG = new BondGraph(true);
96 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
97};
98
99
100void BondGraphTest::tearDown()
101{
102 // remove the file
103 remove(filename->c_str());
104 delete(filename);
105 delete(dummyname);
106 delete(BG);
107
108 // remove molecule
109 World::getInstance().destroyMolecule(TestMolecule);
110 // note that all the atoms, molecules, the tafel and the elements
111 // are all cleaned when the world is destroyed
112 World::purgeInstance();
113 MemoryUsageObserver::purgeInstance();
114 logger::purgeInstance();
115};
116
117/** UnitTest for BondGraphTest::LoadBondLengthTable().
118 */
119void BondGraphTest::LoadTableTest()
120{
121 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
122 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
123 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) );
124 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(5,5) );
125};
126
127/** UnitTest for BondGraphTest::ConstructBondGraph().
128 */
129void BondGraphTest::ConstructGraphFromTableTest()
130{
131 atom *Walker = TestMolecule->start->next;
132 atom *Runner = TestMolecule->end->previous;
133 CPPUNIT_ASSERT( TestMolecule->end != Walker );
134 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
135 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
136 CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
137};
138
139/** UnitTest for BondGraphTest::ConstructBondGraph().
140 */
141void BondGraphTest::ConstructGraphFromCovalentRadiiTest()
142{
143 atom *Walker = TestMolecule->start->next;
144 atom *Runner = TestMolecule->end->previous;
145 CPPUNIT_ASSERT( TestMolecule->end != Walker );
146 CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(*dummyname) );
147 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
148 CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
149};
150
Note: See TracBrowser for help on using the repository browser.