source: src/unittests/bondgraphunittest.cpp@ e5ad5c

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 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 e5ad5c was e5ad5c, checked in by Frederik Heber <heber@…>, 16 years ago

BUGFIX: BondGraphUnitTest was not working.

Changes:

  • atoms are now carbon, not hydrogen
  • added covalent and van-der-Waals radii to element creation
  • FIX: carbon now has Z = 2.
  • added test case for NULL BondTable (i.e. from covalent radii)

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 4.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
17#include "atom.hpp"
18#include "bond.hpp"
19#include "bondgraph.hpp"
20#include "element.hpp"
21#include "log.hpp"
22#include "molecule.hpp"
23#include "periodentafel.hpp"
24#include "bondgraphunittest.hpp"
25
26/********************************************** Test classes **************************************/
27
28// Registers the fixture into the 'registry'
29CPPUNIT_TEST_SUITE_REGISTRATION( BondGraphTest );
30
31
32void BondGraphTest::setUp()
33{
34 atom *Walker = NULL;
35
36 // init private all pointers to zero
37 TestMolecule = NULL;
38 hydrogen = NULL;
39 tafel = NULL;
40
41 // construct element
42 hydrogen = new element;
43 hydrogen->Z = 1;
44 hydrogen->CovalentRadius = 0.23;
45 hydrogen->VanDerWaalsRadius = 1.09;
46 strcpy(hydrogen->name, "hydrogen");
47 strcpy(hydrogen->symbol, "H");
48 carbon = new element;
49 carbon->Z = 2;
50 carbon->CovalentRadius = 0.68;
51 carbon->VanDerWaalsRadius = 1.7;
52 strcpy(carbon->name, "carbon");
53 strcpy(carbon->symbol, "C");
54
55
56 // construct periodentafel
57 tafel = new periodentafel;
58 tafel->AddElement(hydrogen);
59 tafel->AddElement(carbon);
60
61 // construct molecule (tetraeder of hydrogens)
62 TestMolecule = new molecule(tafel);
63 Walker = new atom();
64 Walker->type = carbon;
65 Walker->node->Init(1., 0., 1. );
66 TestMolecule->AddAtom(Walker);
67 Walker = new atom();
68 Walker->type = carbon;
69 Walker->node->Init(0., 1., 1. );
70 TestMolecule->AddAtom(Walker);
71 Walker = new atom();
72 Walker->type = carbon;
73 Walker->node->Init(1., 1., 0. );
74 TestMolecule->AddAtom(Walker);
75 Walker = new atom();
76 Walker->type = carbon;
77 Walker->node->Init(0., 0., 0. );
78 TestMolecule->AddAtom(Walker);
79
80 // check that TestMolecule was correctly constructed
81 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
82
83 // create a small file with table
84 dummyname = new string("dummy.dat");
85 filename = new string("test.dat");
86 ofstream test(filename->c_str());
87 test << ".\tH\tC\n";
88 test << "H\t1.\t1.2\n";
89 test << "C\t1.2\t1.5\n";
90 BG = new BondGraph(true);
91};
92
93
94void BondGraphTest::tearDown()
95{
96 // remove the file
97 remove(filename->c_str());
98 delete(filename);
99 delete(dummyname);
100 delete(BG);
101
102 // remove molecule
103 delete(TestMolecule);
104 // note that all the atoms are cleaned by TestMolecule
105 delete(tafel);
106 // note that element is cleaned by periodentafel
107};
108
109/** UnitTest for BondGraphTest::LoadBondLengthTable().
110 */
111void BondGraphTest::LoadTableTest()
112{
113 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
114 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
115 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
116 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
117};
118
119/** UnitTest for BondGraphTest::ConstructBondGraph().
120 */
121void BondGraphTest::ConstructGraphFromTableTest()
122{
123 atom *Walker = TestMolecule->start->next;
124 atom *Runner = TestMolecule->end->previous;
125 CPPUNIT_ASSERT( TestMolecule->end != Walker );
126 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
127 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
128 CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
129};
130
131/** UnitTest for BondGraphTest::ConstructBondGraph().
132 */
133void BondGraphTest::ConstructGraphFromCovalentRadiiTest()
134{
135 atom *Walker = TestMolecule->start->next;
136 atom *Runner = TestMolecule->end->previous;
137 CPPUNIT_ASSERT( TestMolecule->end != Walker );
138 CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(*dummyname) );
139 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
140 CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
141};
142
143
144/********************************************** Main routine **************************************/
145
146int main(int argc, char **argv)
147{
148 // Get the top level suite from the registry
149 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
150
151 // Adds the test to the list of test to run
152 CppUnit::TextUi::TestRunner runner;
153 runner.addTest( suite );
154
155 // Change the default outputter to a compiler error format outputter
156 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
157 std::cerr ) );
158 // Run the tests.
159 bool wasSucessful = runner.run();
160
161 // Return error code 1 if the one of test failed.
162 return wasSucessful ? 0 : 1;
163};
Note: See TracBrowser for help on using the repository browser.