source: src/Graph/unittests/CheckAgainstAdjacencyFileUnitTest.cpp@ cdaae6

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

Updated all source files's copyright note to current year 2012.

  • Property mode set to 100644
File size: 7.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * CheckAgainstAdjacencyFileUnitTest.cpp
10 *
11 * Created on: Oct 17, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CheckAgainstAdjacencyFileUnitTest.hpp"
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 <string>
28
29#include "CodePatterns/Assert.hpp"
30#include "CodePatterns/Log.hpp"
31
32#include "Atom/atom.hpp"
33#include "Descriptors/AtomDescriptor.hpp"
34#include "Element/element.hpp"
35#include "Element/periodentafel.hpp"
36#include "Graph/CheckAgainstAdjacencyFile.hpp"
37#include "molecule.hpp"
38#include "World.hpp"
39#include "WorldTime.hpp"
40
41#ifdef HAVE_TESTRUNNER
42#include "UnitTestMain.hpp"
43#endif /*HAVE_TESTRUNNER*/
44
45/********************************************** Test classes **************************************/
46// Registers the fixture into the 'registry'
47CPPUNIT_TEST_SUITE_REGISTRATION( CheckAgainstAdjacencyFileTest );
48
49static std::string adjacencyfile ="\
500 1\n\
511 0 2\n\
522 1 3\n\
533 2 4\n\
544 3 5\n\
555 4 6\n\
566 5 7\n\
577 6 8\n\
588 7 9\n\
599 8\n";
60
61static std::string wrongadjacencyfile1 ="\
620 1\n\
631 0 2\n\
643 2 4\n\
654 3 5\n\
665 4 6\n\
676 5 7\n\
687 6 8\n\
698 7 9\n\
709 8\n";
71
72static std::string wrongadjacencyfile2 ="\
730 1\n\
741 0 2\n\
752 1 3\n\
763 2 4\n\
774 3 5\n\
785 4 6\n\
796 5 7\n\
807 6 8\n\
818 7 9\n\
829 8 10\n\
8310 9";
84
85// set up and tear down
86void CheckAgainstAdjacencyFileTest::setUp()
87{
88 const element *hydrogen = World::getInstance().getPeriode()->FindElement(1);
89 CPPUNIT_ASSERT(hydrogen != NULL);
90
91 // failing asserts should be thrown
92 ASSERT_DO(Assert::Throw);
93
94 TestMolecule = World::getInstance().createMolecule();
95 CPPUNIT_ASSERT(TestMolecule != NULL);
96 for(int i=0;i<ATOM_COUNT;++i){
97 atoms[i]= World::getInstance().createAtom();
98 CPPUNIT_ASSERT(atoms[i] != NULL);
99 atoms[i]->setType(hydrogen);
100 TestMolecule->AddAtom(atoms[i]);
101 atomIds[i]= atoms[i]->getId();
102 }
103 // create linear chain
104 for(int i=0;i<ATOM_COUNT-1;++i){
105 atoms[i]->addBond(WorldTime::getTime(), atoms[i+1]);
106 }
107
108 // create map as it should be
109 for(int i=0;i<ATOM_COUNT;++i) {
110 if (i != 0) // first has only one bond
111 comparisonMap.insert( std::make_pair(atomIds[i], atomIds[i-1]) );
112 if (i != ATOM_COUNT-1) // last has only one bond
113 comparisonMap.insert( std::make_pair(atomIds[i], atomIds[i+1]) );
114 }
115}
116
117void CheckAgainstAdjacencyFileTest::tearDown()
118{
119 comparisonMap.clear();
120
121 // destroy molecule and contained atoms
122 TestMolecule->removeAtomsinMolecule();
123 World::getInstance().destroyMolecule(TestMolecule);
124 // destroy World
125 World::purgeInstance();
126// logger::purgeInstance();
127// errorLogger::purgeInstance();
128}
129
130/** Unit tests for CheckAgainstAdjacencyFile::CreateInternalMap().
131 *
132 */
133void CheckAgainstAdjacencyFileTest::CreateInternalMapTest()
134{
135 World::getInstance().selectAllAtoms(AllAtoms());
136 CheckAgainstAdjacencyFile fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
137
138 // check size (it's 8*2 + 2*1 = 18 keys)
139 CPPUNIT_ASSERT_EQUAL( (size_t)18, fileChecker.InternalAtomBondMap.size() );
140 CPPUNIT_ASSERT_EQUAL( (size_t)0, fileChecker.ExternalAtomBondMap.size() );
141
142 // check equality
143 CPPUNIT_ASSERT( comparisonMap.size() == fileChecker.InternalAtomBondMap.size() );
144// std::cout << "comparisonMap: " << comparisonMap << std::endl;
145// std::cout << "fileChecker.InternalAtomBondMap: " << fileChecker.InternalAtomBondMap << std::endl;
146 CPPUNIT_ASSERT( comparisonMap == fileChecker.InternalAtomBondMap );
147
148 // check non-equality: more
149 comparisonMap.insert( std::make_pair( (atomId_t)10, (atomId_t)8) );
150 CPPUNIT_ASSERT( comparisonMap != fileChecker.InternalAtomBondMap );
151 comparisonMap.erase((atomId_t)10);
152
153 // check non-equality: less
154 comparisonMap.erase((atomId_t)9);
155 CPPUNIT_ASSERT( comparisonMap != fileChecker.InternalAtomBondMap );
156}
157
158/** Unit tests for CheckAgainstAdjacencyFile::ParseInExternalMap().
159 *
160 */
161void CheckAgainstAdjacencyFileTest::ParseInExternalMapTest()
162{
163 std::stringstream input(adjacencyfile);
164 World::getInstance().selectAllAtoms(NoAtoms());
165 CheckAgainstAdjacencyFile fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
166 fileChecker.ParseInExternalMap(input);
167
168 // check size (it's 8*2 + 2*1 = 18 keys)
169 CPPUNIT_ASSERT_EQUAL( (size_t)0, fileChecker.InternalAtomBondMap.size() );
170 CPPUNIT_ASSERT_EQUAL( (size_t)18, fileChecker.ExternalAtomBondMap.size() );
171
172 // check equality
173 CPPUNIT_ASSERT( comparisonMap.size() == fileChecker.ExternalAtomBondMap.size() );
174 CPPUNIT_ASSERT( comparisonMap == fileChecker.ExternalAtomBondMap );
175
176 // check non-equality: more
177 comparisonMap.insert( std::make_pair( (atomId_t)10, (atomId_t)8) );
178 CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );
179 comparisonMap.erase((atomId_t)10);
180
181 // check non-equality: less
182 comparisonMap.erase((atomId_t)9);
183 CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );
184}
185
186/** Unit tests for CheckAgainstAdjacencyFile::CompareInternalExternalMap().
187 *
188 */
189void CheckAgainstAdjacencyFileTest::CompareInternalExternalMapTest()
190{
191 World::getInstance().selectAllAtoms(AllAtoms());
192 CheckAgainstAdjacencyFile fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
193
194 // assert non-equality before parsing
195 CPPUNIT_ASSERT( fileChecker.InternalAtomBondMap.size() != fileChecker.ExternalAtomBondMap.size() );
196 CPPUNIT_ASSERT( fileChecker.InternalAtomBondMap != fileChecker.ExternalAtomBondMap );
197 CPPUNIT_ASSERT( !fileChecker.CompareInternalExternalMap() );
198
199 // parse
200 std::stringstream input(adjacencyfile);
201 fileChecker.ParseInExternalMap(input);
202
203 // assert equality after parsing
204 CPPUNIT_ASSERT( fileChecker.InternalAtomBondMap.size() == fileChecker.ExternalAtomBondMap.size() );
205 CPPUNIT_ASSERT( fileChecker.InternalAtomBondMap == fileChecker.ExternalAtomBondMap );
206 CPPUNIT_ASSERT( fileChecker.CompareInternalExternalMap() );
207}
208
209/** Unit tests for CheckAgainstAdjacencyFile::operator()().
210 *
211 */
212void CheckAgainstAdjacencyFileTest::operatorTest()
213{
214 World::getInstance().selectAllAtoms(AllAtoms());
215 CheckAgainstAdjacencyFile fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
216 {
217 // parse right
218 std::stringstream input(adjacencyfile);
219 CPPUNIT_ASSERT( fileChecker(input) );
220 }
221 {
222 // parse wrong1
223 std::stringstream input(wrongadjacencyfile1);
224 CPPUNIT_ASSERT( !fileChecker(input) );
225 }
226 {
227 // parse wrong2 (there is no atom 10)
228 std::stringstream input(wrongadjacencyfile2);
229#ifndef NDEBUG
230 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
231 CPPUNIT_ASSERT_THROW( fileChecker(input), Assert::AssertionFailure );
232#else
233 CPPUNIT_ASSERT( !fileChecker(input) );
234#endif
235 }
236}
Note: See TracBrowser for help on using the repository browser.