source: src/Graph/unittests/BondGraphUnitTest.cpp@ 9b6663

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

Added operator==() to BondGraph.

  • Property mode set to 100644
File size: 5.2 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
[b70721]8/*
[f844ef]9 * BondGraphUnitTest.cpp
[b70721]10 *
11 * Created on: Oct 29, 2009
12 * Author: heber
13 */
14
[bf3817]15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
[b70721]20using namespace std;
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25
26#include <iostream>
27#include <stdio.h>
[49e1ae]28#include <cstring>
[b70721]29
[ad011c]30#include "CodePatterns/Assert.hpp"
[4eb4fe]31
[b70721]32#include "atom.hpp"
[129204]33#include "Bond/bond.hpp"
[ad011c]34#include "CodePatterns/Log.hpp"
[3bdb6d]35#include "Element/element.hpp"
[129204]36#include "Graph/BondGraph.hpp"
[b70721]37#include "molecule.hpp"
[3bdb6d]38#include "Element/periodentafel.hpp"
[e6fdbe]39#include "World.hpp"
[073a9e4]40#include "WorldTime.hpp"
[b70721]41
[f844ef]42#include "BondGraphUnitTest.hpp"
43
[9b6b2f]44#ifdef HAVE_TESTRUNNER
45#include "UnitTestMain.hpp"
46#endif /*HAVE_TESTRUNNER*/
[b70721]47
48/********************************************** Test classes **************************************/
49
50// Registers the fixture into the 'registry'
51CPPUNIT_TEST_SUITE_REGISTRATION( BondGraphTest );
52
53
54void BondGraphTest::setUp()
55{
56 atom *Walker = NULL;
57
58 // construct element
[4eb4fe]59 hydrogen = World::getInstance().getPeriode()->FindElement(1);
60 carbon = World::getInstance().getPeriode()->FindElement(6);
61 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
62 CPPUNIT_ASSERT(carbon != NULL && "could not find element carbon");
[b70721]63
64 // construct molecule (tetraeder of hydrogens)
[23b547]65 TestMolecule = World::getInstance().createMolecule();
[4eb4fe]66 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
[23b547]67 Walker = World::getInstance().createAtom();
[4eb4fe]68 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]69 Walker->setType(carbon);
70 Walker->setPosition(Vector(1., 0., 1. ));
[b70721]71 TestMolecule->AddAtom(Walker);
[8cbb97]72
[23b547]73 Walker = World::getInstance().createAtom();
[4eb4fe]74 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]75 Walker->setType(carbon);
76 Walker->setPosition(Vector(0., 1., 1. ));
[b70721]77 TestMolecule->AddAtom(Walker);
[8cbb97]78
[23b547]79 Walker = World::getInstance().createAtom();
[4eb4fe]80 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]81 Walker->setType(carbon);
82 Walker->setPosition(Vector(1., 1., 0. ));
[b70721]83 TestMolecule->AddAtom(Walker);
[8cbb97]84
[23b547]85 Walker = World::getInstance().createAtom();
[4eb4fe]86 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]87 Walker->setType(carbon);
88 Walker->setPosition(Vector(0., 0., 0. ));
[b70721]89 TestMolecule->AddAtom(Walker);
90
91 // check that TestMolecule was correctly constructed
[ea7176]92 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
[b70721]93
[4e855e]94 // create stream with table
[4eb4fe]95 test << ".\tH\tHe\tLi\tBe\tB\tC\n";
96 test << "H\t1.\t1.\t1.\t1.\t1.\t1.2\n";
97 test << "He\t1.\t1.\t1.\t1.\t1.\t1.\n";
98 test << "Li\t1.\t1.\t1.\t1.\t1.\t1.\n";
99 test << "Be\t1.\t1.\t1.\t1.\t1.\t1.\n";
100 test << "B\t1.\t1.\t1.\t1.\t1.\t1.\n";
101 test << "C\t1.2\t1.\t1.\t1.\t1.\t1.5\n";
[4e855e]102 // created bad stream (i.e. non-present file)
103 dummy.setstate(ios::eofbit);
104 CPPUNIT_ASSERT(dummy.eof());
[b70721]105 BG = new BondGraph(true);
[4eb4fe]106 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
[b70721]107};
108
109
110void BondGraphTest::tearDown()
111{
112 // remove the file
113 delete(BG);
114
115 // remove molecule
[23b547]116 World::getInstance().destroyMolecule(TestMolecule);
[a1510d]117 // note that all the atoms, molecules, the tafel and the elements
118 // are all cleaned when the world is destroyed
[23b547]119 World::purgeInstance();
[e6fdbe]120 logger::purgeInstance();
[b70721]121};
122
[9879f6]123/** Tests whether setup worked.
124 */
125void BondGraphTest::SetupTest()
126{
127 CPPUNIT_ASSERT_EQUAL (false, TestMolecule->empty());
128 CPPUNIT_ASSERT_EQUAL ((size_t)4, TestMolecule->size());
129};
130
[b70721]131/** UnitTest for BondGraphTest::LoadBondLengthTable().
132 */
133void BondGraphTest::LoadTableTest()
134{
[4e855e]135 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(test) );
[b70721]136 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
[4eb4fe]137 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) );
138 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(5,5) );
[b70721]139};
140
[3738f0]141/** UnitTest for BondGraphTest::CreateAdjacency().
[b70721]142 */
[e5ad5c]143void BondGraphTest::ConstructGraphFromTableTest()
[b70721]144{
[9879f6]145 molecule::iterator Walker = TestMolecule->begin();
146 molecule::iterator Runner = TestMolecule->begin();
147 Runner++;
[4e855e]148 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(test) );
[3738f0]149 molecule::atomVector Set = TestMolecule->getAtomSet();
150 BG->CreateAdjacency(Set);
151 CPPUNIT_ASSERT( TestMolecule->getBondCount() != 0);
[073a9e4]152 CPPUNIT_ASSERT_EQUAL( true , (*Walker)->IsBondedTo(WorldTime::getTime(), (*Runner)) );
[b70721]153};
154
[3738f0]155/** UnitTest for BondGraphTest::CreateAdjacency().
[e5ad5c]156 */
157void BondGraphTest::ConstructGraphFromCovalentRadiiTest()
158{
[a7b761b]159
[4e855e]160 CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(dummy) );
[3738f0]161 molecule::atomVector Set = TestMolecule->getAtomSet();
162 BG->CreateAdjacency(Set);
163 CPPUNIT_ASSERT( TestMolecule->getBondCount() != 0);
[a7b761b]164
165 // this cannot be assured using dynamic IDs
166 //CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
[e5ad5c]167};
168
[9b6663]169/** UnitTest for operator==()
170 */
171void BondGraphTest::EqualityTest()
172{
173 // compare to self
174 CPPUNIT_ASSERT( *BG == *BG );
175
176 // create other instance
177 BondGraph *BG2 = new BondGraph(true);
178 CPPUNIT_ASSERT( *BG == *BG2 );
179 BG2->IsAngstroem = false;
180 CPPUNIT_ASSERT( *BG != *BG2 );
181 delete BG2;
182};
183
Note: See TracBrowser for help on using the repository browser.