source: src/unittests/MoleculeDescriptorTest.cpp@ 13e3c3

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

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 * MoleculeDescriptorTest.cpp
3 *
4 * Created on: Mar 4, 2010
5 * Author: crueger
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include "MoleculeDescriptorTest.hpp"
14
15#include <cppunit/CompilerOutputter.h>
16#include <cppunit/extensions/TestFactoryRegistry.h>
17#include <cppunit/ui/text/TestRunner.h>
18#include <iostream>
19
20#include <Descriptors/MoleculeDescriptor.hpp>
21#include <Descriptors/MoleculeIdDescriptor.hpp>
22
23#include "World.hpp"
24#include "molecule.hpp"
25
26#ifdef HAVE_TESTRUNNER
27#include "UnitTestMain.hpp"
28#endif /*HAVE_TESTRUNNER*/
29
30/********************************************** Test classes **************************************/
31// Registers the fixture into the 'registry'
32CPPUNIT_TEST_SUITE_REGISTRATION( MoleculeDescriptorTest );
33
34// set up and tear down
35void MoleculeDescriptorTest::setUp(){
36 World::getInstance();
37 for(int i=0;i<MOLECULE_COUNT;++i){
38 molecules[i]= World::getInstance().createMolecule();
39 moleculeIds[i]= molecules[i]->getId();
40 }
41}
42
43void MoleculeDescriptorTest::tearDown(){
44 World::purgeInstance();
45}
46
47// some helper functions
48static bool hasAllMolecules(std::vector<molecule*> molecules,moleculeId_t ids[MOLECULE_COUNT], std::set<moleculeId_t> excluded = std::set<moleculeId_t>()){
49 for(int i=0;i<MOLECULE_COUNT;++i){
50 moleculeId_t id = ids[i];
51 if(!excluded.count(id)){
52 std::vector<molecule*>::iterator iter;
53 bool res=false;
54 for(iter=molecules.begin();iter!=molecules.end();++iter){
55 res |= (*iter)->getId() == id;
56 }
57 if(!res) {
58 cout << "Molecule " << id << " missing in returned list" << endl;
59 return false;
60 }
61 }
62 }
63 return true;
64}
65
66static bool hasNoDuplicateMolecules(std::vector<molecule*> molecules){
67 std::set<moleculeId_t> found;
68 std::vector<molecule*>::iterator iter;
69 for(iter=molecules.begin();iter!=molecules.end();++iter){
70 int id = (*iter)->getId();
71 if(found.count(id))
72 return false;
73 found.insert(id);
74 }
75 return true;
76}
77
78
79void MoleculeDescriptorTest::MoleculeBaseSetsTest(){
80 std::vector<molecule*> allMolecules = World::getInstance().getAllMolecules(AllMolecules());
81 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(allMolecules,moleculeIds));
82 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(allMolecules));
83
84 std::vector<molecule*> noMolecules = World::getInstance().getAllMolecules(NoMolecules());
85 CPPUNIT_ASSERT_EQUAL( true , noMolecules.empty());
86}
87void MoleculeDescriptorTest::MoleculeIdTest(){
88 // test Molecules from boundaries and middle of the set
89 molecule* testMolecule;
90 testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[0]));
91 CPPUNIT_ASSERT(testMolecule);
92 CPPUNIT_ASSERT_EQUAL( moleculeIds[0], testMolecule->getId());
93 testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT/2]));
94 CPPUNIT_ASSERT(testMolecule);
95 CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT/2], testMolecule->getId());
96 testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT-1]));
97 CPPUNIT_ASSERT(testMolecule);
98 CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT-1], testMolecule->getId());
99
100 // find some ID that has not been created
101 moleculeId_t outsideId=0;
102 bool res = false;
103 for(outsideId=0;!res;++outsideId) {
104 res = true;
105 for(int i = 0; i < MOLECULE_COUNT; ++i){
106 res &= moleculeIds[i]!=outsideId;
107 }
108 }
109 // test from outside of set
110 testMolecule = World::getInstance().getMolecule(MoleculeById(outsideId));
111 CPPUNIT_ASSERT(!testMolecule);
112}
113void MoleculeDescriptorTest::MoleculeCalcTest(){
114 // test some elementary set operations
115 {
116 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()||NoMolecules());
117 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
118 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
119 }
120
121 {
122 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()||AllMolecules());
123 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
124 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
125 }
126
127 {
128 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()&&AllMolecules());
129 CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
130 }
131
132 {
133 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()&&NoMolecules());
134 CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
135 }
136
137 {
138 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!AllMolecules());
139 CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
140 }
141
142 {
143 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!NoMolecules());
144 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
145 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
146 }
147
148 // exclude and include some molecules
149 {
150 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()&&(!MoleculeById(moleculeIds[MOLECULE_COUNT/2])));
151 std::set<moleculeId_t> excluded;
152 excluded.insert(moleculeIds[MOLECULE_COUNT/2]);
153 CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds,excluded));
154 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
155 CPPUNIT_ASSERT_EQUAL( (size_t)(MOLECULE_COUNT-1), testMolecules.size());
156 }
157
158 {
159 std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()||(MoleculeById(moleculeIds[MOLECULE_COUNT/2])));
160 CPPUNIT_ASSERT_EQUAL( (size_t)1, testMolecules.size());
161 CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT/2], testMolecules[0]->getId());
162 }
163}
Note: See TracBrowser for help on using the repository browser.