source: src/unittests/bondgraphunittest.cpp@ 46d958

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

Made the world solely responsible for creating and destroying atoms.

  • Property mode set to 100644
File size: 3.9 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
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
54 tafel = new periodentafel;
55 tafel->AddElement(hydrogen);
56 tafel->AddElement(carbon);
57
58 // construct molecule (tetraeder of hydrogens)
59 TestMolecule = new molecule(tafel);
60 Walker = World::get()->createAtom();
61 Walker->type = hydrogen;
62 Walker->node->Init(1., 0., 1. );
63 TestMolecule->AddAtom(Walker);
64 Walker = World::get()->createAtom();
65 Walker->type = hydrogen;
66 Walker->node->Init(0., 1., 1. );
67 TestMolecule->AddAtom(Walker);
68 Walker = World::get()->createAtom();
69 Walker->type = hydrogen;
70 Walker->node->Init(1., 1., 0. );
71 TestMolecule->AddAtom(Walker);
72 Walker = World::get()->createAtom();
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());
83 test << ".\tH\tC\n";
84 test << "H\t1.\t1.2\n";
85 test << "C\t1.2\t1.5\n";
86 test.close();
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
99 delete(TestMolecule);
100 // note that all the atoms are cleaned by TestMolecule
101 delete(tafel);
102 // note that element is cleaned by periodentafel
103};
104
105/** UnitTest for BondGraphTest::LoadBondLengthTable().
106 */
107void BondGraphTest::LoadTableTest()
108{
109 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
110 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
111 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
112 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
113};
114
115/** UnitTest for BondGraphTest::ConstructBondGraph().
116 */
117void BondGraphTest::ConstructGraphTest()
118{
119 atom *Walker = TestMolecule->start->next;
120 atom *Runner = TestMolecule->end->previous;
121 CPPUNIT_ASSERT( TestMolecule->end != Walker );
122 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
123 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
124 CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
125};
126
127
128/********************************************** Main routine **************************************/
129
130int main(int argc, char **argv)
131{
132 // Get the top level suite from the registry
133 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
134
135 // Adds the test to the list of test to run
136 CppUnit::TextUi::TestRunner runner;
137 runner.addTest( suite );
138
139 // Change the default outputter to a compiler error format outputter
140 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
141 std::cerr ) );
142 // Run the tests.
143 bool wasSucessful = runner.run();
144
145 // Return error code 1 if the one of test failed.
146 return wasSucessful ? 0 : 1;
147};
Note: See TracBrowser for help on using the repository browser.