source: src/unittests/bondgraphunittest.cpp@ 1f2217

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

Made the world solely responsible for creating and erasing molecules.

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