source: src/Descriptors/unittests/MoleculeDescriptorUnitTest.cpp@ a636f8

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

FIX: MoleculeOrderDescriptor was not working correctly.

  • Property mode set to 100644
File size: 7.3 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 * MoleculeDescriptorTest.cpp
10 *
11 * Created on: Mar 4, 2010
12 * Author: crueger
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include <cppunit/CompilerOutputter.h>
21#include <cppunit/extensions/TestFactoryRegistry.h>
22#include <cppunit/ui/text/TestRunner.h>
23#include <iostream>
24
25#include <Descriptors/MoleculeDescriptor.hpp>
26#include <Descriptors/MoleculeIdDescriptor.hpp>
27#include <Descriptors/MoleculeNameDescriptor.hpp>
28#include <Descriptors/MoleculeOrderDescriptor.hpp>
29
30#include "World.hpp"
31#include "molecule.hpp"
32
33#include "MoleculeDescriptorUnitTest.hpp"
34
35#ifdef HAVE_TESTRUNNER
36#include "UnitTestMain.hpp"
37#endif /*HAVE_TESTRUNNER*/
38
39/********************************************** Test classes **************************************/
40// Registers the fixture into the 'registry'
41CPPUNIT_TEST_SUITE_REGISTRATION( MoleculeDescriptorTest );
42
43// set up and tear down
44void MoleculeDescriptorTest::setUp(){
45 World::getInstance();
46 for(int i=0;i<MOLECULE_COUNT;++i){
47 molecules[i]= World::getInstance().createMolecule();
48 moleculeIds[i]= molecules[i]->getId();
49 }
50}
51
52void MoleculeDescriptorTest::tearDown(){
53 World::purgeInstance();
54}
55
56// some helper functions
57static bool hasAllMolecules(std::vector<molecule*> molecules,moleculeId_t ids[MOLECULE_COUNT], std::set<moleculeId_t> excluded = std::set<moleculeId_t>()){
58 for(int i=0;i<MOLECULE_COUNT;++i){
59 moleculeId_t id = ids[i];
60 if(!excluded.count(id)){
61 std::vector<molecule*>::iterator iter;
62 bool res=false;
63 for(iter=molecules.begin();iter!=molecules.end();++iter){
64 res |= (*iter)->getId() == id;
65 }
66 if(!res) {
67 cout << "Molecule " << id << " missing in returned list" << endl;
68 return false;
69 }
70 }
71 }
72 return true;
73}
74
75static bool hasNoDuplicateMolecules(std::vector<molecule*> molecules){
76 std::set<moleculeId_t> found;
77 std::vector<molecule*>::iterator iter;
78 for(iter=molecules.begin();iter!=molecules.end();++iter){
79 int id = (*iter)->getId();
80 if(found.count(id))
81 return false;
82 found.insert(id);
83 }
84 return true;
85}
86
87
88void MoleculeDescriptorTest::MoleculeBaseSetsTest(){
89 std::vector<molecule*> allMolecules = World::getInstance().getAllMolecules(AllMolecules());
90 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(allMolecules,moleculeIds));
91 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(allMolecules));
92
93 std::vector<molecule*> noMolecules = World::getInstance().getAllMolecules(NoMolecules());
94 CPPUNIT_ASSERT_EQUAL( true , noMolecules.empty());
95}
96void MoleculeDescriptorTest::MoleculeIdTest(){
97 // test Molecules from boundaries and middle of the set
98 molecule* testMolecule;
99 testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[0]));
100 CPPUNIT_ASSERT(testMolecule);
101 CPPUNIT_ASSERT_EQUAL( moleculeIds[0], testMolecule->getId());
102 testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT/2]));
103 CPPUNIT_ASSERT(testMolecule);
104 CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT/2], testMolecule->getId());
105 testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT-1]));
106 CPPUNIT_ASSERT(testMolecule);
107 CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT-1], testMolecule->getId());
108
109 // find some ID that has not been created
110 moleculeId_t outsideId=0;
111 bool res = false;
112 for(outsideId=0;!res;++outsideId) {
113 res = true;
114 for(int i = 0; i < MOLECULE_COUNT; ++i){
115 res &= moleculeIds[i]!=outsideId;
116 }
117 }
118 // test from outside of set
119 testMolecule = World::getInstance().getMolecule(MoleculeById(outsideId));
120 CPPUNIT_ASSERT(!testMolecule);
121}
122void MoleculeDescriptorTest::MoleculeCalcTest(){
123 // test some elementary set operations
124 {
125 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()||NoMolecules());
126 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
127 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
128 }
129
130 {
131 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()||AllMolecules());
132 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
133 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
134 }
135
136 {
137 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()&&AllMolecules());
138 CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
139 }
140
141 {
142 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()&&NoMolecules());
143 CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
144 }
145
146 {
147 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!AllMolecules());
148 CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
149 }
150
151 {
152 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!NoMolecules());
153 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
154 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
155 }
156
157 // exclude and include some molecules
158 {
159 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()&&(!MoleculeById(moleculeIds[MOLECULE_COUNT/2])));
160 std::set<moleculeId_t> excluded;
161 excluded.insert(moleculeIds[MOLECULE_COUNT/2]);
162 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds,excluded));
163 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
164 CPPUNIT_ASSERT_EQUAL( (size_t)(MOLECULE_COUNT-1), testMolecules.size());
165 }
166
167 {
168 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()||(MoleculeById(moleculeIds[MOLECULE_COUNT/2])));
169 CPPUNIT_ASSERT_EQUAL( (size_t)1, testMolecules.size());
170 CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT/2], testMolecules[0]->getId());
171 }
172}
173
174void MoleculeDescriptorTest::MoleculeNameTest()
175{
176 molecule* testMolecule;
177
178 // name each molecule
179 for(int i=1;i<=MOLECULE_COUNT;++i)
180 molecules[i-1]->setName(toString(i));
181
182 // retrieve each
183 for(int i=1;i<=MOLECULE_COUNT;++i) {
184 testMolecule = World::getInstance().getMolecule(MoleculeByName(toString(i)));
185 CPPUNIT_ASSERT_EQUAL( moleculeIds[i-1], testMolecule->getId());
186 }
187
188 // check for non-present name
189 testMolecule = World::getInstance().getMolecule(MoleculeByName("not present"));
190 CPPUNIT_ASSERT(!testMolecule);
191}
192
193
194void MoleculeDescriptorTest::MoleculeOrderTest()
195{
196 molecule* testMolecule;
197
198 // test in normal order: 1, 2, ...
199 for(int i=1;i<=MOLECULE_COUNT;++i){
200 testMolecule = World::getInstance().getMolecule(MoleculeByOrder(i));
201 CPPUNIT_ASSERT_EQUAL( moleculeIds[i-1], testMolecule->getId());
202 }
203
204 // test in reverse order: -1, -2, ...
205 for(int i=1; i<= MOLECULE_COUNT;++i){
206 testMolecule = World::getInstance().getMolecule(MoleculeByOrder(-i));
207 CPPUNIT_ASSERT_EQUAL( moleculeIds[(int)MOLECULE_COUNT-i], testMolecule->getId());
208 }
209
210 // test from outside of set
211 testMolecule = World::getInstance().getMolecule(MoleculeByOrder(MOLECULE_COUNT+1));
212 CPPUNIT_ASSERT(!testMolecule);
213 testMolecule = World::getInstance().getMolecule(MoleculeByOrder(-MOLECULE_COUNT-1));
214 CPPUNIT_ASSERT(!testMolecule);
215}
Note: See TracBrowser for help on using the repository browser.