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

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

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 7.7 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 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * CheckAgainstAdjacencyFileUnitTest.cpp
25 *
26 * Created on: Oct 17, 2011
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CheckAgainstAdjacencyFileUnitTest.hpp"
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41#include <iostream>
42#include <string>
43
44#include "CodePatterns/Assert.hpp"
45#include "CodePatterns/Log.hpp"
46
47#include "Atom/atom.hpp"
48#include "Descriptors/AtomDescriptor.hpp"
49#include "Element/element.hpp"
50#include "Element/periodentafel.hpp"
51#include "Graph/CheckAgainstAdjacencyFile.hpp"
52#include "molecule.hpp"
53#include "World.hpp"
54#include "WorldTime.hpp"
55
56#ifdef HAVE_TESTRUNNER
57#include "UnitTestMain.hpp"
58#endif /*HAVE_TESTRUNNER*/
59
60/********************************************** Test classes **************************************/
61// Registers the fixture into the 'registry'
62CPPUNIT_TEST_SUITE_REGISTRATION( CheckAgainstAdjacencyFileTest );
63
64static std::string adjacencyfile ="\
651 2\n\
662 1 3\n\
673 2 4\n\
684 3 5\n\
695 4 6\n\
706 5 7\n\
717 6 8\n\
728 7 9\n\
739 8 10\n\
7410 9\n";
75
76static std::string wrongadjacencyfile1 ="\
771 2\n\
782 1 3\n\
794 3 5\n\
805 4 6\n\
816 5 7\n\
827 6 8\n\
838 7 9\n\
849 8 10\n\
8510 9\n";
86
87static std::string wrongadjacencyfile2 ="\
881 2\n\
892 1 3\n\
903 2 4\n\
914 3 5\n\
925 4 6\n\
936 5 7\n\
947 6 8\n\
958 7 9\n\
969 8 10\n\
9710 9 11\n\
9811 10";
99
100// set up and tear down
101void CheckAgainstAdjacencyFileTest::setUp()
102{
103 const element *hydrogen = World::getInstance().getPeriode()->FindElement(1);
104 CPPUNIT_ASSERT(hydrogen != NULL);
105
106 // failing asserts should be thrown
107 ASSERT_DO(Assert::Throw);
108
109 TestMolecule = World::getInstance().createMolecule();
110 CPPUNIT_ASSERT(TestMolecule != NULL);
111 for(int i=0;i<ATOM_COUNT;++i){
112 atoms[i]= World::getInstance().createAtom();
113 CPPUNIT_ASSERT(atoms[i] != NULL);
114 atoms[i]->setType(hydrogen);
115 TestMolecule->AddAtom(atoms[i]);
116 atomIds[i]= atoms[i]->getId();
117 }
118 // create linear chain
119 for(int i=0;i<ATOM_COUNT-1;++i){
120 atoms[i]->addBond(WorldTime::getTime(), atoms[i+1]);
121 }
122
123 // create map as it should be
124 for(int i=0;i<ATOM_COUNT;++i) {
125 if (i != 0) // first has only one bond
126 comparisonMap.insert( std::make_pair(atomIds[i], atomIds[i-1]) );
127 if (i != ATOM_COUNT-1) // last has only one bond
128 comparisonMap.insert( std::make_pair(atomIds[i], atomIds[i+1]) );
129 }
130}
131
132void CheckAgainstAdjacencyFileTest::tearDown()
133{
134 comparisonMap.clear();
135
136 // destroy molecule and contained atoms
137 TestMolecule->removeAtomsinMolecule();
138 World::getInstance().destroyMolecule(TestMolecule);
139 // destroy World
140 World::purgeInstance();
141// logger::purgeInstance();
142// errorLogger::purgeInstance();
143}
144
145/** Unit tests for CheckAgainstAdjacencyFile::CreateInternalMap().
146 *
147 */
148void CheckAgainstAdjacencyFileTest::CreateInternalMapTest()
149{
150 World::getInstance().selectAllAtoms(AllAtoms());
151 CheckAgainstAdjacencyFile fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
152
153 // check size (it's 8*2 + 2*1 = 18 keys)
154 CPPUNIT_ASSERT_EQUAL( (size_t)18, fileChecker.InternalAtomBondMap.size() );
155 CPPUNIT_ASSERT_EQUAL( (size_t)0, fileChecker.ExternalAtomBondMap.size() );
156
157 // check equality
158 CPPUNIT_ASSERT( comparisonMap.size() == fileChecker.InternalAtomBondMap.size() );
159// std::cout << "comparisonMap: " << comparisonMap << std::endl;
160// std::cout << "fileChecker.InternalAtomBondMap: " << fileChecker.InternalAtomBondMap << std::endl;
161 CPPUNIT_ASSERT( comparisonMap == fileChecker.InternalAtomBondMap );
162
163 // check non-equality: more
164 comparisonMap.insert( std::make_pair( (atomId_t)10, (atomId_t)8) );
165 CPPUNIT_ASSERT( comparisonMap != fileChecker.InternalAtomBondMap );
166 comparisonMap.erase((atomId_t)10);
167
168 // check non-equality: less
169 comparisonMap.erase((atomId_t)9);
170 CPPUNIT_ASSERT( comparisonMap != fileChecker.InternalAtomBondMap );
171}
172
173/** Unit tests for CheckAgainstAdjacencyFile::ParseInExternalMap().
174 *
175 */
176void CheckAgainstAdjacencyFileTest::ParseInExternalMapTest()
177{
178 std::stringstream input(adjacencyfile);
179 World::getInstance().selectAllAtoms(NoAtoms());
180 CheckAgainstAdjacencyFile fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
181 fileChecker.ParseInExternalMap(input);
182
183 // check size (it's 8*2 + 2*1 = 18 keys)
184 CPPUNIT_ASSERT_EQUAL( (size_t)0, fileChecker.InternalAtomBondMap.size() );
185 CPPUNIT_ASSERT_EQUAL( (size_t)18, fileChecker.ExternalAtomBondMap.size() );
186
187 // check equality
188 CPPUNIT_ASSERT( comparisonMap.size() == fileChecker.ExternalAtomBondMap.size() );
189 CPPUNIT_ASSERT( comparisonMap == fileChecker.ExternalAtomBondMap );
190
191 // check non-equality: more
192 comparisonMap.insert( std::make_pair( (atomId_t)10, (atomId_t)8) );
193 CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );
194 comparisonMap.erase((atomId_t)10);
195
196 // check non-equality: less
197 comparisonMap.erase((atomId_t)9);
198 CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );
199}
200
201/** Unit tests for CheckAgainstAdjacencyFile::CompareInternalExternalMap().
202 *
203 */
204void CheckAgainstAdjacencyFileTest::CompareInternalExternalMapTest()
205{
206 World::getInstance().selectAllAtoms(AllAtoms());
207 CheckAgainstAdjacencyFile fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
208
209 // assert non-equality before parsing
210 CPPUNIT_ASSERT( fileChecker.InternalAtomBondMap.size() != fileChecker.ExternalAtomBondMap.size() );
211 CPPUNIT_ASSERT( fileChecker.InternalAtomBondMap != fileChecker.ExternalAtomBondMap );
212 CPPUNIT_ASSERT( !fileChecker.CompareInternalExternalMap() );
213
214 // parse
215 std::stringstream input(adjacencyfile);
216 fileChecker.ParseInExternalMap(input);
217
218 // assert equality after parsing
219 CPPUNIT_ASSERT_EQUAL( fileChecker.InternalAtomBondMap.size(), fileChecker.ExternalAtomBondMap.size() );
220 CPPUNIT_ASSERT_EQUAL( fileChecker.InternalAtomBondMap, fileChecker.ExternalAtomBondMap );
221 CPPUNIT_ASSERT( fileChecker.CompareInternalExternalMap() );
222}
223
224/** Unit tests for CheckAgainstAdjacencyFile::operator()().
225 *
226 */
227void CheckAgainstAdjacencyFileTest::operatorTest()
228{
229 World::getInstance().selectAllAtoms(AllAtoms());
230 CheckAgainstAdjacencyFile fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
231 {
232 // parse right
233 std::stringstream input(adjacencyfile);
234 CPPUNIT_ASSERT( fileChecker(input) );
235 }
236 {
237 // parse wrong1
238 std::stringstream input(wrongadjacencyfile1);
239 CPPUNIT_ASSERT( !fileChecker(input) );
240 }
241 {
242 // parse wrong2 (there is no atom 10)
243 std::stringstream input(wrongadjacencyfile2);
244#ifndef NDEBUG
245 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
246 CPPUNIT_ASSERT_THROW( fileChecker(input), Assert::AssertionFailure );
247#else
248 CPPUNIT_ASSERT( !fileChecker(input) );
249#endif
250 }
251}
Note: See TracBrowser for help on using the repository browser.